Poojashetty357 commited on
Commit
aa0cae8
·
verified ·
1 Parent(s): c1e970c

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +96 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def analyze_bp(systolic, diastolic):
4
+ if systolic < 120 and diastolic < 80:
5
+ return "Normal Blood Pressure"
6
+ elif 120 <= systolic < 130 and diastolic < 80:
7
+ return "Elevated Blood Pressure"
8
+ elif 130 <= systolic < 140 or 80 <= diastolic < 90:
9
+ return "Hypertension Stage 1"
10
+ elif systolic >= 140 or diastolic >= 90:
11
+ return "Hypertension Stage 2"
12
+ else:
13
+ return "Consult your doctor"
14
+
15
+ def analyze_glucose(glucose_level):
16
+ if 80 < glucose_level < 100:
17
+ return "Normal Glucose Level"
18
+ elif glucose_level <= 80:
19
+ return "Low Blood Glucose"
20
+ elif 100 <= glucose_level < 126:
21
+ return "Prediabetes"
22
+ elif glucose_level >= 126:
23
+ return "Diabetes"
24
+ else:
25
+ return "Consult your doctor"
26
+
27
+ def get_recommendations(bp_analysis, glucose_analysis):
28
+ # Determine the most severe condition
29
+ conditions = {
30
+ "Hypertension Stage 2": 4,
31
+ "Hypertension Stage 1": 3,
32
+ "Elevated Blood Pressure": 2,
33
+ "Normal Blood Pressure": 1,
34
+ "Diabetes": 4,
35
+ "Prediabetes": 3,
36
+ "Low Blood Glucose": 2,
37
+ "Normal Glucose Level": 1
38
+ }
39
+ severity = max(conditions.get(bp_analysis, 0), conditions.get(glucose_analysis, 0))
40
+
41
+ if severity == 4:
42
+ exercise = "Low-impact exercises like walking or swimming"
43
+ food = "Low-sodium and low-sugar diet"
44
+ medication = "Consult your doctor for medication"
45
+ elif severity == 3:
46
+ exercise = "Moderate aerobic exercises"
47
+ food = "Balanced diet with reduced sugar and salt"
48
+ medication = "Monitor regularly; consult doctor if needed"
49
+ elif severity == 2:
50
+ exercise = "Light exercises and stretching"
51
+ food = "Regular meals with complex carbs"
52
+ medication = "Monitor levels and adjust diet accordingly"
53
+ else:
54
+ exercise = "Regular physical activity"
55
+ food = "Balanced diet"
56
+ medication = "No medication needed"
57
+
58
+ return exercise, food, medication
59
+
60
+ def analyze_all(systolic, diastolic, glucose_level):
61
+ bp_result = analyze_bp(systolic, diastolic)
62
+ glucose_result = analyze_glucose(glucose_level)
63
+ exercise, food, medication = get_recommendations(bp_result, glucose_result)
64
+ return bp_result, glucose_result, exercise, food, medication
65
+
66
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
67
+ gr.Markdown("## 🩺 **Health Tracker: Blood Pressure & Glucose Monitor with Recommendations**")
68
+
69
+ with gr.Row():
70
+ with gr.Column():
71
+ gr.Markdown("### 🩸 **Blood Pressure Input**")
72
+ systolic = gr.Number(label="Systolic (mmHg)", value=120)
73
+ diastolic = gr.Number(label="Diastolic (mmHg)", value=80)
74
+
75
+ with gr.Column():
76
+ gr.Markdown("### 🍬 **Blood Glucose Input**")
77
+ glucose = gr.Number(label="Glucose Level (mg/dL)", value=90)
78
+
79
+ analyze_all_button = gr.Button("🔍 Analyze All")
80
+
81
+ with gr.Row():
82
+ bp_output = gr.Textbox(label="🩸 Blood Pressure Analysis")
83
+ glucose_output = gr.Textbox(label="🍬 Glucose Level Analysis")
84
+
85
+ gr.Markdown("### 💡 **Personalized Recommendations**")
86
+ exercise_output = gr.Textbox(label="🏃 Exercise Recommendation")
87
+ food_output = gr.Textbox(label="🥗 Food Recommendation")
88
+ medication_output = gr.Textbox(label="💊 Medication Recommendation")
89
+
90
+ analyze_all_button.click(
91
+ fn=analyze_all,
92
+ inputs=[systolic, diastolic, glucose],
93
+ outputs=[bp_output, glucose_output, exercise_output, food_output, medication_output]
94
+ )
95
+
96
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio