attiquers commited on
Commit
ef2acb6
·
verified ·
1 Parent(s): eff7710

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -32
app.py CHANGED
@@ -1,41 +1,26 @@
1
  import gradio as gr
2
  import numpy as np
3
 
4
- # Load trained model parameters (assumed to be saved as .npy file)
5
- theta_final = np.load("theta_final.npy") # Save your trained theta and upload it to HF Spaces
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
- user_input = np.array([symptoms])
14
- normalized_input = (user_input - mu) / sigma
15
- normalized_input = np.c_[np.ones((normalized_input.shape[0], 1)), normalized_input] # Add bias term
16
- y_pred = normalized_input @ theta_final
17
- return f"Predicted Stroke Risk: {y_pred[0][0]:.2f}%"
 
 
 
 
18
 
19
- # Symptoms list
20
- symptoms = [
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
- # Creating grid layout
28
- inputs = []
29
- for symptom in symptoms:
30
- inputs.append(gr.Row([gr.Markdown(f"**{symptom}**"), gr.Checkbox(label="")]))
31
 
32
- demo = gr.Interface(
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()