File size: 3,839 Bytes
0d986fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aa0cae8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import gradio as gr

def analyze_bp(systolic, diastolic):
    if systolic < 120 and diastolic < 80:
        return "Normal Blood Pressure"
    elif 120 <= systolic < 130 and diastolic < 80:
        return "Elevated Blood Pressure"
    elif 130 <= systolic < 140 or 80 <= diastolic < 90:
        return "Hypertension Stage 1"
    elif systolic >= 140 or diastolic >= 90:
        return "Hypertension Stage 2"
    else:
        return "Consult your doctor"

def analyze_glucose(glucose_level):
    if 80 < glucose_level < 100:
        return "Normal Glucose Level"
    elif glucose_level <= 80:
        return "Low Blood Glucose"
    elif 100 <= glucose_level < 126:
        return "Prediabetes"
    elif glucose_level >= 126:
        return "Diabetes"
    else:
        return "Consult your doctor"

def get_recommendations(bp_analysis, glucose_analysis):
    conditions = {
        "Hypertension Stage 2": 4,
        "Hypertension Stage 1": 3,
        "Elevated Blood Pressure": 2,
        "Normal Blood Pressure": 1,
        "Diabetes": 4,
        "Prediabetes": 3,
        "Low Blood Glucose": 2,
        "Normal Glucose Level": 1
    }
    severity = max(conditions.get(bp_analysis, 0), conditions.get(glucose_analysis, 0))

    if severity == 4:
        exercise = "Low-impact exercises like walking or swimming"
        food = "Low-sodium and low-sugar diet"
        medication = "Consult your doctor for medication"
    elif severity == 3:
        exercise = "Moderate aerobic exercises"
        food = "Balanced diet with reduced sugar and salt"
        medication = "Monitor regularly; consult doctor if needed"
    elif severity == 2:
        exercise = "Light exercises and stretching"
        food = "Regular meals with complex carbs"
        medication = "Monitor levels and adjust diet accordingly"
    else:
        exercise = "Regular physical activity"
        food = "Balanced diet"
        medication = "No medication needed"

    return exercise, food, medication

def analyze_all(systolic, diastolic, glucose_level):
    bp_result = analyze_bp(systolic, diastolic)
    glucose_result = analyze_glucose(glucose_level)
    exercise, food, medication = get_recommendations(bp_result, glucose_result)
    return bp_result, glucose_result, exercise, food, medication

with gr.Blocks(theme=gr.themes.Soft()) as demo:
    gr.Markdown("## 🩺 **Health Tracker: Blood Pressure & Glucose Monitor with Recommendations**")

    with gr.Row():
        with gr.Column():
            gr.Markdown("### 🩸 **Blood Pressure Input**")
            systolic = gr.Number(label="Systolic (mmHg)", value=120)
            diastolic = gr.Number(label="Diastolic (mmHg)", value=80)

        with gr.Column():
            gr.Markdown("### 🍬 **Blood Glucose Input**")
            glucose = gr.Number(label="Glucose Level (mg/dL)", value=90)

    analyze_all_button = gr.Button("πŸ” Analyze All")

    with gr.Row():
        bp_output = gr.Textbox(label="🩸 Blood Pressure Analysis")
        glucose_output = gr.Textbox(label="🍬 Glucose Level Analysis")

    gr.Markdown("### πŸ’‘ **Personalized Recommendations**")
    exercise_output = gr.Textbox(label="πŸƒ Exercise Recommendation")
    food_output = gr.Textbox(label="πŸ₯— Food Recommendation")
    medication_output = gr.Textbox(label="πŸ’Š Medication Recommendation")

    analyze_all_button.click(
        fn=analyze_all,
        inputs=[systolic, diastolic, glucose],
        outputs=[bp_output, glucose_output, exercise_output, food_output, medication_output]
    )

    # βž• Clear Button
    clear_button = gr.Button("🧹 Clear All")
    clear_button.click(
        fn=lambda: (120, 80, 90, "", "", "", "", ""),
        inputs=[],
        outputs=[systolic, diastolic, glucose, bp_output, glucose_output, exercise_output, food_output, medication_output]
    )

demo.launch()