VectorV17 commited on
Commit
3e36c61
·
verified ·
1 Parent(s): b9b4bb1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -61
app.py CHANGED
@@ -405,7 +405,7 @@ def handle_csv_upload(file):
405
  return df_results, summary_text, pdf_path
406
 
407
  # ---------------------------------------------------------------------------
408
- # 6. SLEEK & GLOSSY GRADIO UI LAYOUT
409
  # ---------------------------------------------------------------------------
410
  custom_css = """
411
  body, .gradio-container {
@@ -423,13 +423,6 @@ body, .gradio-container {
423
  margin-bottom: 20px !important;
424
  }
425
 
426
- .sidebar-panel {
427
- background: rgba(15, 23, 42, 0.85) !important;
428
- border-right: 1px solid rgba(255, 255, 255, 0.1) !important;
429
- padding: 24px !important;
430
- border-radius: 16px !important;
431
- }
432
-
433
  .btn-primary {
434
  background: linear-gradient(90deg, #0284c7 0%, #0369a1 100%) !important;
435
  border: none !important;
@@ -448,69 +441,67 @@ with gr.Blocks(css=custom_css, title="Steel Industry Energy Predictor") as demo:
448
  """
449
  )
450
 
451
- with gr.Row():
452
- # SIDEBAR CONTROL PANEL
453
- with gr.Column(scale=1, elem_classes=["sidebar-panel"]):
454
- gr.Markdown("### ⚙️ Input Control Sidebar")
455
- gr.Markdown("Configure manual parameters or run batch processes directly.")
 
 
 
456
 
457
- with gr.Accordion("Single Inspection Parameters", open=True):
458
- lag_kvarh = gr.Number(label="Lagging Reactive Power (kVarh)", value=12.5)
459
- lead_kvarh = gr.Number(label="Leading Reactive Power (kVarh)", value=2.1)
460
- lag_pf = gr.Slider(minimum=0, maximum=100, label="Lagging Power Factor (%)", value=85.0)
461
- lead_pf = gr.Slider(minimum=0, maximum=100, label="Leading Power Factor (%)", value=95.0)
462
- nsm = gr.Number(label="Number of Seconds from Midnight (NSM)", value=36000)
463
- hour = gr.Slider(minimum=0, maximum=23, step=1, label="Hour of Day", value=10)
464
- month = gr.Slider(minimum=1, maximum=12, step=1, label="Month of Year", value=6)
465
- day_of_week = gr.Dropdown(
466
- choices=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
467
- value='Monday',
468
- label="Day of Week"
469
- )
470
- load_type = gr.Dropdown(
471
- choices=['Light_Load', 'Medium_Load', 'Maximum_Load'],
472
- value='Medium_Load',
473
- label="Load Type Category"
474
- )
475
 
476
- predict_btn = gr.Button("🚀 Predict Single Record", elem_classes=["btn-primary"])
477
-
478
- # MAIN WORKFLOW AREA
479
- with gr.Column(scale=3):
480
- with gr.Tabs():
481
- # TAB 1: CSV UPLOAD & AUDIT EXPORT
482
- with gr.TabItem("📂 Batch CSV Upload & PDF Export"):
483
- with gr.Group(elem_classes=["glass-panel"]):
484
- gr.Markdown("### Upload Steel Industry Data CSV")
485
- file_input = gr.File(label="Upload CSV File (`Steel_industry_data.csv`)", file_types=[".csv"])
486
- process_csv_btn = gr.Button("⚡ Analyze CSV Data & Generate Report", elem_classes=["btn-primary"])
487
-
488
- with gr.Row():
489
- with gr.Column(scale=2):
490
- output_dataframe = gr.Dataframe(label="Predictions & Anomaly Status Preview", interactive=False)
491
- with gr.Column(scale=1):
492
- summary_output = gr.Markdown(value="*Upload a CSV to view analysis summary.*")
493
- pdf_download = gr.File(label="📄 Download PDF Audit Report")
494
-
495
- # TAB 2: SINGLE PREDICTION RESULT
496
- with gr.TabItem("🎯 Single Record Result"):
497
- with gr.Group(elem_classes=["glass-panel"]):
498
- gr.Markdown("### Single Inspection Diagnostic Result")
499
- out_kwh = gr.Textbox(label="Predicted Energy Consumption (Usage_kWh)", interactive=False)
500
- out_co2 = gr.Textbox(label="Estimated Carbon Emissions (Tonnes CO2)", interactive=False)
501
- out_pf_status = gr.Textbox(label="⚡ Power Factor Diagnostic & Surcharge Alert", interactive=False)
 
 
 
502
 
503
  single_inputs = [lag_kvarh, lead_kvarh, lag_pf, lead_pf, nsm, hour, month, day_of_week, load_type]
504
  single_outputs = [out_kwh, out_co2, out_pf_status]
505
 
506
- # Button event
507
  predict_btn.click(
508
  fn=handle_single_prediction,
509
  inputs=single_inputs,
510
  outputs=single_outputs
511
  )
512
 
513
- # Real-time change event listeners
514
  for inp in single_inputs:
515
  inp.change(
516
  fn=handle_single_prediction,
@@ -518,14 +509,13 @@ with gr.Blocks(css=custom_css, title="Steel Industry Energy Predictor") as demo:
518
  outputs=single_outputs
519
  )
520
 
521
- # Initial load trigger (prevents blank textboxes on startup)
522
  demo.load(
523
  fn=handle_single_prediction,
524
  inputs=single_inputs,
525
  outputs=single_outputs
526
  )
527
 
528
- # Batch CSV process button
529
  process_csv_btn.click(
530
  fn=handle_csv_upload,
531
  inputs=[file_input],
 
405
  return df_results, summary_text, pdf_path
406
 
407
  # ---------------------------------------------------------------------------
408
+ # 6. SLEEK & GLOSSY GRADIO UI LAYOUT (REFACTORED FOR CLEAR SEPARATION)
409
  # ---------------------------------------------------------------------------
410
  custom_css = """
411
  body, .gradio-container {
 
423
  margin-bottom: 20px !important;
424
  }
425
 
 
 
 
 
 
 
 
426
  .btn-primary {
427
  background: linear-gradient(90deg, #0284c7 0%, #0369a1 100%) !important;
428
  border: none !important;
 
441
  """
442
  )
443
 
444
+ with gr.Tabs():
445
+ # TAB 1: CSV BATCH ANALYSIS & PDF EXPORT
446
+ with gr.TabItem("📂 Batch CSV Upload & PDF Audit"):
447
+ with gr.Group(elem_classes=["glass-panel"]):
448
+ gr.Markdown("### Upload Steel Industry Data CSV for Dataset Analysis")
449
+ gr.Markdown("Upload `Steel_industry_data.csv` to process thousands of historical plant records and export an audit PDF.")
450
+ file_input = gr.File(label="Upload CSV File (`Steel_industry_data.csv`)", file_types=[".csv"])
451
+ process_csv_btn = gr.Button("⚡ Analyze CSV Data & Generate PDF Report", elem_classes=["btn-primary"])
452
 
453
+ with gr.Row():
454
+ with gr.Column(scale=2):
455
+ output_dataframe = gr.Dataframe(label="Predictions & Anomaly Status Preview", interactive=False)
456
+ with gr.Column(scale=1):
457
+ summary_output = gr.Markdown(value="*Upload a CSV above to view dataset summary.*")
458
+ pdf_download = gr.File(label="📄 Download PDF Audit Report")
459
+
460
+ # TAB 2: SINGLE RECORD SIMULATOR & DIAGNOSTICS
461
+ with gr.TabItem("🎯 Single Record Simulator & Diagnostic"):
462
+ gr.Markdown("### Single Inspection Simulator")
463
+ gr.Markdown("Adjust sliders and parameters below to simulate power usage for a single specific timestamp/operational condition.")
 
 
 
 
 
 
 
464
 
465
+ with gr.Row():
466
+ # LEFT COLUMN: INPUT CONTROLS
467
+ with gr.Column(scale=1, elem_classes=["glass-panel"]):
468
+ gr.Markdown("#### ⚙️ Input Parameters")
469
+ lag_kvarh = gr.Number(label="Lagging Reactive Power (kVarh)", value=12.5)
470
+ lead_kvarh = gr.Number(label="Leading Reactive Power (kVarh)", value=2.1)
471
+ lag_pf = gr.Slider(minimum=0, maximum=100, label="Lagging Power Factor (%)", value=85.0)
472
+ lead_pf = gr.Slider(minimum=0, maximum=100, label="Leading Power Factor (%)", value=95.0)
473
+ nsm = gr.Number(label="Number of Seconds from Midnight (NSM)", value=36000)
474
+ hour = gr.Slider(minimum=0, maximum=23, step=1, label="Hour of Day", value=10)
475
+ month = gr.Slider(minimum=1, maximum=12, step=1, label="Month of Year", value=6)
476
+ day_of_week = gr.Dropdown(
477
+ choices=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
478
+ value='Monday',
479
+ label="Day of Week"
480
+ )
481
+ load_type = gr.Dropdown(
482
+ choices=['Light_Load', 'Medium_Load', 'Maximum_Load'],
483
+ value='Medium_Load',
484
+ label="Load Type Category"
485
+ )
486
+ predict_btn = gr.Button("🚀 Predict Single Record", elem_classes=["btn-primary"])
487
+
488
+ # RIGHT COLUMN: PREDICTION OUTPUTS
489
+ with gr.Column(scale=1, elem_classes=["glass-panel"]):
490
+ gr.Markdown("#### 📊 Diagnostic Results")
491
+ out_kwh = gr.Textbox(label="Predicted Energy Consumption (Usage_kWh)", interactive=False)
492
+ out_co2 = gr.Textbox(label="Estimated Carbon Emissions (Tonnes CO2)", interactive=False)
493
+ out_pf_status = gr.Textbox(label="⚡ Power Factor Diagnostic & Surcharge Alert", interactive=False)
494
 
495
  single_inputs = [lag_kvarh, lead_kvarh, lag_pf, lead_pf, nsm, hour, month, day_of_week, load_type]
496
  single_outputs = [out_kwh, out_co2, out_pf_status]
497
 
498
+ # Single Prediction Event Listeners
499
  predict_btn.click(
500
  fn=handle_single_prediction,
501
  inputs=single_inputs,
502
  outputs=single_outputs
503
  )
504
 
 
505
  for inp in single_inputs:
506
  inp.change(
507
  fn=handle_single_prediction,
 
509
  outputs=single_outputs
510
  )
511
 
 
512
  demo.load(
513
  fn=handle_single_prediction,
514
  inputs=single_inputs,
515
  outputs=single_outputs
516
  )
517
 
518
+ # Batch CSV Event Listener
519
  process_csv_btn.click(
520
  fn=handle_csv_upload,
521
  inputs=[file_input],