Spaces:
No application file
No application file
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import joblib
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# Load model
|
| 6 |
+
model = joblib.load("stroke_rf_model.pkl")
|
| 7 |
+
|
| 8 |
+
# Define prediction function
|
| 9 |
+
def predict_stroke(age, hypertension, heart_disease, glucose_level, bmi):
|
| 10 |
+
data = {
|
| 11 |
+
'age': [age],
|
| 12 |
+
'hypertension': [hypertension],
|
| 13 |
+
'heart_disease': [heart_disease],
|
| 14 |
+
'avg_glucose_level': [glucose_level],
|
| 15 |
+
'bmi': [bmi]
|
| 16 |
+
}
|
| 17 |
+
df = pd.DataFrame(data)
|
| 18 |
+
prediction = model.predict(df)
|
| 19 |
+
return "Stroke Risk" if prediction[0] == 1 else "No Stroke Risk"
|
| 20 |
+
|
| 21 |
+
# Create Gradio Interface
|
| 22 |
+
iface = gr.Interface(
|
| 23 |
+
fn=predict_stroke,
|
| 24 |
+
inputs=[
|
| 25 |
+
gr.Number(label="Age"),
|
| 26 |
+
gr.Radio(choices=[0, 1], label="Hypertension (0=No, 1=Yes)"),
|
| 27 |
+
gr.Radio(choices=[0, 1], label="Heart Disease (0=No, 1=Yes)"),
|
| 28 |
+
gr.Number(label="Average Glucose Level"),
|
| 29 |
+
gr.Number(label="BMI")
|
| 30 |
+
],
|
| 31 |
+
outputs="text",
|
| 32 |
+
title="Stroke Prediction Model",
|
| 33 |
+
description="Predict stroke risk based on health metrics."
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
# Launch the app
|
| 37 |
+
iface.launch()
|