Update app.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
|
| 4 |
-
# Load trained model parameters
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
# Mean and standard deviation for normalization (precomputed from dataset)
|
| 8 |
-
mu = np.array([...]) # Replace with actual values
|
| 9 |
-
sigma = np.array([...]) # Replace with actual values
|
| 10 |
-
sigma = np.where(sigma == 0, 1, sigma) # Prevent division by zero
|
| 11 |
|
|
|
|
| 12 |
def predict_stroke_risk(*symptoms):
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
"Chest Pain", "Shortness of Breath", "Irregular Heartbeat", "Fatigue/Weakness", "Dizziness", "Swelling/Edema",
|
| 22 |
-
"Pain in Neck/Jaw/Shoulder/Back", "Excessive Sweating", "Persistent Cough", "Nausea/Vomiting",
|
| 23 |
-
"High Blood Pressure", "Chest Discomfort During Activity", "Cold Hands/Feet", "Snoring/Sleep Apnea",
|
| 24 |
-
"Anxiety/Feeling of Doom", "Age > 50"
|
| 25 |
-
]
|
| 26 |
|
| 27 |
-
|
| 28 |
-
inputs = []
|
| 29 |
-
for symptom in symptoms:
|
| 30 |
-
inputs.append(gr.Row([gr.Markdown(f"**{symptom}**"), gr.Checkbox(label="")]))
|
| 31 |
|
| 32 |
-
|
| 33 |
-
fn=predict_stroke_risk,
|
| 34 |
-
inputs=[inp[1] for inp in inputs],
|
| 35 |
-
outputs="text",
|
| 36 |
-
title="Stroke Predictor",
|
| 37 |
-
description="Tick the symptoms you have",
|
| 38 |
-
layout="vertical"
|
| 39 |
-
)
|
| 40 |
|
| 41 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
|
| 4 |
+
# Load trained model parameters
|
| 5 |
+
theta = np.load("theta_final.npy")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# Define prediction function
|
| 8 |
def predict_stroke_risk(*symptoms):
|
| 9 |
+
symptoms_array = np.array(symptoms).astype(float)
|
| 10 |
+
risk = np.dot(symptoms_array, theta) * 100 # Convert to percentage
|
| 11 |
+
return round(risk, 2)
|
| 12 |
+
|
| 13 |
+
# Define UI
|
| 14 |
+
symptoms_list = ["Symptom 1", "Symptom 2", "Symptom 3", "Symptom 4", "Symptom 5"]
|
| 15 |
+
with gr.Blocks() as demo:
|
| 16 |
+
gr.Markdown("# 🏥 Stroke Risk Predictor 🚑")
|
| 17 |
+
gr.Markdown("Select symptoms and get your stroke risk percentage.")
|
| 18 |
|
| 19 |
+
checkboxes = [gr.Checkbox(label=s) for s in symptoms_list]
|
| 20 |
+
submit = gr.Button("Predict")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
output = gr.Textbox(label="Stroke Risk %")
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
submit.click(predict_stroke_risk, checkboxes, output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
demo.launch()
|