Sanjayraju30 commited on
Commit
53267d3
·
verified ·
1 Parent(s): 6f1fc6b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from fastapi import FastAPI
3
+ from risk_model import predict_risk, retrain_model, get_history_df
4
+
5
+ app = FastAPI()
6
+ gradio_app = gr.Blocks()
7
+
8
+ with gradio_app:
9
+ gr.Markdown("## 🔥 Heating Mantle Safety Risk Predictor")
10
+
11
+ with gr.Row():
12
+ temp = gr.Number(label="Max Temperature (°C)", value=100)
13
+ duration = gr.Number(label="Duration (min)", value=30)
14
+
15
+ with gr.Row():
16
+ predict_btn = gr.Button("🔍 Predict")
17
+ retrain_btn = gr.Button("🔁 Retrain Model")
18
+
19
+ result = gr.Textbox(label="Risk Prediction")
20
+ score = gr.Textbox(label="Confidence (%)")
21
+ retrain_output = gr.Textbox(label="Retrain Status")
22
+
23
+ history_table = gr.Dataframe(headers=["Temperature", "Duration", "Risk", "Confidence"], label="📈 Prediction History")
24
+
25
+ def classify(temp, duration):
26
+ if temp <= 0 or duration <= 0:
27
+ return "Invalid Input", "Use values > 0", get_history_df()
28
+ risk, confidence = predict_risk(temp, duration)
29
+ emoji = "🟢" if risk == "Low" else "🟠" if risk == "Moderate" else "🔴"
30
+ return f"{emoji} {risk}", f"{confidence}%", get_history_df()
31
+
32
+ predict_btn.click(classify, inputs=[temp, duration], outputs=[result, score, history_table])
33
+ retrain_btn.click(retrain_model, outputs=[retrain_output])
34
+
35
+ # Mount Gradio onto FastAPI
36
+ @app.get("/")
37
+ def read_root():
38
+ return {"message": "Heating Mantle Risk API is running!"}
39
+
40
+ app = gr.mount_gradio_app(app, gradio_app, path="/predict-ui")