Sanjayraju30 commited on
Commit
70d0717
·
verified ·
1 Parent(s): 7bffc00

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -8,7 +8,7 @@ with gr.Blocks() as demo:
8
 
9
  # 🔄 Reset button at the top
10
  with gr.Row():
11
- reset_btn = gr.Button("🔄 Reset All Fields")
12
 
13
  # Input fields
14
  with gr.Row():
@@ -23,15 +23,17 @@ with gr.Blocks() as demo:
23
  result = gr.Textbox(label="Risk Prediction")
24
  alert = gr.Textbox(label="🚨 Alert Message")
25
  ist_time = gr.Textbox(label="Timestamp (IST)")
 
26
  summary = gr.Markdown()
27
  history_table = gr.Dataframe(headers=["Temperature", "Duration", "Risk", "Timestamp"], label="📈 Prediction History")
28
  plot = gr.Plot(label="📊 Risk Trend Chart")
29
 
30
  def classify(temp, duration):
31
  if temp <= 0 or duration <= 0:
32
- return "❌ Invalid", "Invalid", "Invalid", "", pd.DataFrame(), plt.figure()
33
 
34
  risk, timestamp = predict_risk(temp, duration)
 
35
 
36
  alert_msg = {
37
  "Low": "✅ SAFE - No action needed",
@@ -43,6 +45,7 @@ with gr.Blocks() as demo:
43
  ### 🔎 Summary
44
  - **Max Temp**: {temp} °C
45
  - **Duration**: {duration} min
 
46
  - **Risk**: {risk}
47
  - **Timestamp**: {timestamp}
48
  - **Alert**: {alert_msg}
@@ -65,24 +68,24 @@ with gr.Blocks() as demo:
65
 
66
  df_display = df[["Temperature", "Duration", "Risk", "Timestamp"]]
67
 
68
- return risk, alert_msg, timestamp, summary_md, df_display, fig
69
 
70
  # Function to reset all fields
71
  def reset_all():
72
  return (
73
- 100, 30, "", "", "", "", pd.DataFrame(columns=["Temperature", "Duration", "Risk", "Timestamp"]), plt.figure()
74
  )
75
 
76
  predict_btn.click(
77
  classify,
78
  inputs=[temp, duration],
79
- outputs=[result, alert, ist_time, summary, history_table, plot]
80
  )
81
 
82
  reset_btn.click(
83
  reset_all,
84
  inputs=[],
85
- outputs=[temp, duration, result, alert, ist_time, summary, history_table, plot]
86
  )
87
 
88
  demo.launch()
 
8
 
9
  # 🔄 Reset button at the top
10
  with gr.Row():
11
+ reset_btn = gr.Button("🔄 Reset")
12
 
13
  # Input fields
14
  with gr.Row():
 
23
  result = gr.Textbox(label="Risk Prediction")
24
  alert = gr.Textbox(label="🚨 Alert Message")
25
  ist_time = gr.Textbox(label="Timestamp (IST)")
26
+ risk_score = gr.Textbox(label="📊 Risk Score") # NEW FIELD
27
  summary = gr.Markdown()
28
  history_table = gr.Dataframe(headers=["Temperature", "Duration", "Risk", "Timestamp"], label="📈 Prediction History")
29
  plot = gr.Plot(label="📊 Risk Trend Chart")
30
 
31
  def classify(temp, duration):
32
  if temp <= 0 or duration <= 0:
33
+ return "❌ Invalid", "Invalid", "Invalid", "", "", pd.DataFrame(), plt.figure()
34
 
35
  risk, timestamp = predict_risk(temp, duration)
36
+ score = round((temp + duration) / 2, 2)
37
 
38
  alert_msg = {
39
  "Low": "✅ SAFE - No action needed",
 
45
  ### 🔎 Summary
46
  - **Max Temp**: {temp} °C
47
  - **Duration**: {duration} min
48
+ - **Risk Score**: {score}
49
  - **Risk**: {risk}
50
  - **Timestamp**: {timestamp}
51
  - **Alert**: {alert_msg}
 
68
 
69
  df_display = df[["Temperature", "Duration", "Risk", "Timestamp"]]
70
 
71
+ return risk, alert_msg, timestamp, score, summary_md, df_display, fig
72
 
73
  # Function to reset all fields
74
  def reset_all():
75
  return (
76
+ 100, 30, "", "", "", "", "", pd.DataFrame(columns=["Temperature", "Duration", "Risk", "Timestamp"]), plt.figure()
77
  )
78
 
79
  predict_btn.click(
80
  classify,
81
  inputs=[temp, duration],
82
+ outputs=[result, alert, ist_time, risk_score, summary, history_table, plot]
83
  )
84
 
85
  reset_btn.click(
86
  reset_all,
87
  inputs=[],
88
+ outputs=[temp, duration, result, alert, ist_time, risk_score, summary, history_table, plot]
89
  )
90
 
91
  demo.launch()