Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
-
from fastapi import FastAPI
|
3 |
from risk_model import predict_risk, retrain_model, get_history_df
|
4 |
|
5 |
-
|
6 |
-
fastapi_app = FastAPI()
|
7 |
-
|
8 |
-
# Gradio UI blocks
|
9 |
-
gradio_app = gr.Blocks()
|
10 |
-
|
11 |
-
with gradio_app:
|
12 |
gr.Markdown("## 🔥 Heating Mantle Safety Risk Predictor")
|
13 |
|
14 |
with gr.Row():
|
@@ -23,14 +16,11 @@ with gradio_app:
|
|
23 |
score = gr.Textbox(label="Confidence (%)")
|
24 |
retrain_output = gr.Textbox(label="Retrain Status")
|
25 |
|
26 |
-
history_table = gr.Dataframe(
|
27 |
-
headers=["Temperature", "Duration", "Risk", "Confidence"],
|
28 |
-
label="📈 Prediction History"
|
29 |
-
)
|
30 |
|
31 |
def classify(temp, duration):
|
32 |
if temp <= 0 or duration <= 0:
|
33 |
-
return "Invalid Input", "Use values > 0", get_history_df()
|
34 |
risk, confidence = predict_risk(temp, duration)
|
35 |
emoji = "🟢" if risk == "Low" else "🟠" if risk == "Moderate" else "🔴"
|
36 |
return f"{emoji} {risk}", f"{confidence}%", get_history_df()
|
@@ -38,10 +28,4 @@ with gradio_app:
|
|
38 |
predict_btn.click(classify, inputs=[temp, duration], outputs=[result, score, history_table])
|
39 |
retrain_btn.click(retrain_model, outputs=[retrain_output])
|
40 |
|
41 |
-
|
42 |
-
@fastapi_app.get("/")
|
43 |
-
def root():
|
44 |
-
return {"message": "Heating Mantle FastAPI is working"}
|
45 |
-
|
46 |
-
# ✅ Hugging Face requires this:
|
47 |
-
app = gr.mount_gradio_app(fastapi_app, gradio_app, path="/predict-ui")
|
|
|
1 |
import gradio as gr
|
|
|
2 |
from risk_model import predict_risk, retrain_model, get_history_df
|
3 |
|
4 |
+
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
gr.Markdown("## 🔥 Heating Mantle Safety Risk Predictor")
|
6 |
|
7 |
with gr.Row():
|
|
|
16 |
score = gr.Textbox(label="Confidence (%)")
|
17 |
retrain_output = gr.Textbox(label="Retrain Status")
|
18 |
|
19 |
+
history_table = gr.Dataframe(headers=["Temperature", "Duration", "Risk", "Confidence"], label="📈 Prediction History")
|
|
|
|
|
|
|
20 |
|
21 |
def classify(temp, duration):
|
22 |
if temp <= 0 or duration <= 0:
|
23 |
+
return "❌ Invalid Input", "Use values > 0", get_history_df()
|
24 |
risk, confidence = predict_risk(temp, duration)
|
25 |
emoji = "🟢" if risk == "Low" else "🟠" if risk == "Moderate" else "🔴"
|
26 |
return f"{emoji} {risk}", f"{confidence}%", get_history_df()
|
|
|
28 |
predict_btn.click(classify, inputs=[temp, duration], outputs=[result, score, history_table])
|
29 |
retrain_btn.click(retrain_model, outputs=[retrain_output])
|
30 |
|
31 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|