SChnee commited on
Commit
0278f2d
·
verified ·
1 Parent(s): 24f0b53

Upload 5 files

Browse files
Files changed (5) hide show
  1. app.py +107 -0
  2. app.py.txt +0 -0
  3. requirements.txt +7 -0
  4. stroke_clf.pkl +3 -0
  5. stroke_reg.pkl +3 -0
app.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import pickle
4
+
5
+ # Load the trained models
6
+ with open("stroke_clf.pkl", "rb") as f:
7
+ clf_model = pickle.load(f)
8
+
9
+ with open("stroke_reg.pkl", "rb") as f:
10
+ reg_model = pickle.load(f)
11
+
12
+ def predict_stroke(chest_pain, shortness_breath, irregular_heartbeat, fatigue_weakness,
13
+ dizziness, swelling, pain_neck_jaw, excessive_sweating,
14
+ persistent_cough, nausea_vomiting, high_bp, chest_discomfort,
15
+ cold_hands_feet, snoring, anxiety, age):
16
+ """
17
+ Prepares the input features and returns stroke risk prediction using both the classification
18
+ and regression models.
19
+ """
20
+ # Convert boolean inputs to 1 (True) or 0 (False), keeping age as numeric.
21
+ features = [
22
+ 1 if chest_pain else 0,
23
+ 1 if shortness_breath else 0,
24
+ 1 if irregular_heartbeat else 0,
25
+ 1 if fatigue_weakness else 0,
26
+ 1 if dizziness else 0,
27
+ 1 if swelling else 0,
28
+ 1 if pain_neck_jaw else 0,
29
+ 1 if excessive_sweating else 0,
30
+ 1 if persistent_cough else 0,
31
+ 1 if nausea_vomiting else 0,
32
+ 1 if high_bp else 0,
33
+ 1 if chest_discomfort else 0,
34
+ 1 if cold_hands_feet else 0,
35
+ 1 if snoring else 0,
36
+ 1 if anxiety else 0,
37
+ age
38
+ ]
39
+
40
+ sample_input = np.array([features])
41
+
42
+ # Get predictions
43
+ classification_result = clf_model.predict(sample_input)[0]
44
+ risk_class = "At Risk" if classification_result == 1 else "Not At Risk"
45
+
46
+ regression_result = reg_model.predict(sample_input)[0]
47
+ risk_percentage = round(regression_result, 2)
48
+
49
+ return (f"**Classification Result:** {risk_class}\n"
50
+ f"**Regression Result:** {risk_percentage}% stroke risk")
51
+
52
+ # Build Gradio Interface using Blocks for a clean, organized UI
53
+ with gr.Blocks(css=".output { white-space: pre-wrap; }") as demo:
54
+ gr.Markdown(
55
+ """
56
+ # Stroke Risk Prediction
57
+ This application uses two machine learning models to predict stroke risk:
58
+
59
+ - **Classification Model:** Determines if an individual is at risk (Yes/No).
60
+ - **Regression Model:** Estimates the stroke risk percentage.
61
+
62
+ **Provide the following information based on your symptoms:**
63
+ """
64
+ )
65
+
66
+ with gr.Row():
67
+ with gr.Column():
68
+ chest_pain = gr.Checkbox(label="Chest Pain")
69
+ shortness_breath = gr.Checkbox(label="Shortness of Breath")
70
+ irregular_heartbeat = gr.Checkbox(label="Irregular Heartbeat")
71
+ fatigue_weakness = gr.Checkbox(label="Fatigue & Weakness")
72
+ dizziness = gr.Checkbox(label="Dizziness")
73
+ swelling = gr.Checkbox(label="Swelling (Edema)")
74
+ pain_neck_jaw = gr.Checkbox(label="Pain in Neck/Jaw/Shoulder/Back")
75
+ excessive_sweating = gr.Checkbox(label="Excessive Sweating")
76
+ with gr.Column():
77
+ persistent_cough = gr.Checkbox(label="Persistent Cough")
78
+ nausea_vomiting = gr.Checkbox(label="Nausea/Vomiting")
79
+ high_bp = gr.Checkbox(label="High Blood Pressure")
80
+ chest_discomfort = gr.Checkbox(label="Chest Discomfort (During Activity)")
81
+ cold_hands_feet = gr.Checkbox(label="Cold Hands/Feet")
82
+ snoring = gr.Checkbox(label="Snoring/Sleep Apnea")
83
+ anxiety = gr.Checkbox(label="Anxiety/Feeling of Doom")
84
+ age = gr.Number(label="Age", value=50)
85
+
86
+ predict_btn = gr.Button("Predict Stroke Risk", variant="primary")
87
+ output = gr.Markdown(label="Prediction Results", elem_classes="output")
88
+
89
+ predict_btn.click(
90
+ predict_stroke,
91
+ inputs=[
92
+ chest_pain, shortness_breath, irregular_heartbeat, fatigue_weakness,
93
+ dizziness, swelling, pain_neck_jaw, excessive_sweating,
94
+ persistent_cough, nausea_vomiting, high_bp, chest_discomfort,
95
+ cold_hands_feet, snoring, anxiety, age
96
+ ],
97
+ outputs=output
98
+ )
99
+
100
+ gr.Markdown(
101
+ """
102
+ ---
103
+ **Disclaimer:** This tool is intended for informational purposes only and should not be used as a substitute for professional medical advice.
104
+ """
105
+ )
106
+
107
+ demo.launch()
app.py.txt ADDED
File without changes
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ gradio
2
+ matplotlib==3.10.0
3
+ numpy==1.26.4
4
+ pandas==2.2.2
5
+ seaborn==0.13.2
6
+ scikit-learn==1.6.1
7
+ xgboost==2.1.4
stroke_clf.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1bbc260597cd7b227c994ae30c014610b45bf247e6691feecef096b8cccc4cd8
3
+ size 117998965
stroke_reg.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:83390fa3edb13b0119e41f4078a260da3bf1c69de4b46867e805765c550d4e06
3
+ size 471045835