Health-Analyzer / app.py
Poojashetty357's picture
Update app.py
0d986fc verified
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()