Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,30 @@
|
|
1 |
import gradio as gr
|
2 |
-
from risk_model import predict_risk,
|
3 |
import pandas as pd
|
4 |
import matplotlib.pyplot as plt
|
5 |
|
6 |
with gr.Blocks() as demo:
|
7 |
gr.Markdown("## 🔥 Heating Mantle Safety Risk Predictor")
|
8 |
|
|
|
|
|
|
|
|
|
|
|
9 |
with gr.Row():
|
10 |
temp = gr.Number(label="Max Temperature (°C)", value=100)
|
11 |
duration = gr.Number(label="Duration (min)", value=30)
|
12 |
|
|
|
13 |
with gr.Row():
|
14 |
predict_btn = gr.Button("🔍 Predict")
|
15 |
-
retrain_btn = gr.Button("🔁 Retrain Model")
|
16 |
|
|
|
17 |
result = gr.Textbox(label="Risk Prediction")
|
18 |
alert = gr.Textbox(label="🚨 Alert Message")
|
19 |
ist_time = gr.Textbox(label="Timestamp (IST)")
|
20 |
-
retrain_output = gr.Textbox(label="Retrain Status")
|
21 |
-
|
22 |
summary = gr.Markdown()
|
23 |
history_table = gr.Dataframe(headers=["Temperature", "Duration", "Risk", "Timestamp"], label="📈 Prediction History")
|
24 |
-
|
25 |
plot = gr.Plot(label="📊 Risk Trend Chart")
|
26 |
|
27 |
def classify(temp, duration):
|
@@ -30,12 +33,11 @@ with gr.Blocks() as demo:
|
|
30 |
|
31 |
risk, timestamp = predict_risk(temp, duration)
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
alert_msg = "🔥 SHUTDOWN - Immediate attention needed"
|
39 |
|
40 |
summary_md = f"""
|
41 |
### 🔎 Summary
|
@@ -47,8 +49,6 @@ with gr.Blocks() as demo:
|
|
47 |
"""
|
48 |
|
49 |
df = get_history_df()
|
50 |
-
|
51 |
-
# Convert Risk to numeric for plotting
|
52 |
risk_map = {'Low': 1, 'Moderate': 2, 'High': 3}
|
53 |
df["Risk_Num"] = df["Risk"].map(risk_map)
|
54 |
|
@@ -67,9 +67,22 @@ with gr.Blocks() as demo:
|
|
67 |
|
68 |
return risk, alert_msg, timestamp, summary_md, df_display, fig
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from risk_model import predict_risk, get_history_df
|
3 |
import pandas as pd
|
4 |
import matplotlib.pyplot as plt
|
5 |
|
6 |
with gr.Blocks() as demo:
|
7 |
gr.Markdown("## 🔥 Heating Mantle Safety Risk Predictor")
|
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():
|
15 |
temp = gr.Number(label="Max Temperature (°C)", value=100)
|
16 |
duration = gr.Number(label="Duration (min)", value=30)
|
17 |
|
18 |
+
# Predict button
|
19 |
with gr.Row():
|
20 |
predict_btn = gr.Button("🔍 Predict")
|
|
|
21 |
|
22 |
+
# Output fields
|
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):
|
|
|
33 |
|
34 |
risk, timestamp = predict_risk(temp, duration)
|
35 |
|
36 |
+
alert_msg = {
|
37 |
+
"Low": "✅ SAFE - No action needed",
|
38 |
+
"Moderate": "⚠️ SAFE - Monitor closely",
|
39 |
+
"High": "🔥 SHUTDOWN - Immediate attention needed"
|
40 |
+
}.get(risk, "Unknown")
|
|
|
41 |
|
42 |
summary_md = f"""
|
43 |
### 🔎 Summary
|
|
|
49 |
"""
|
50 |
|
51 |
df = get_history_df()
|
|
|
|
|
52 |
risk_map = {'Low': 1, 'Moderate': 2, 'High': 3}
|
53 |
df["Risk_Num"] = df["Risk"].map(risk_map)
|
54 |
|
|
|
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()
|