N-I-M-I commited on
Commit
8f81f8b
·
verified ·
1 Parent(s): 9a89b41

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +85 -0
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import torch
4
+ from predict import RiskPredictor
5
+
6
+ # Initialize the predictor
7
+ predictor = RiskPredictor()
8
+
9
+ def predict_risk(age, bmi, systolic_bp, diastolic_bp, cholesterol, heart_rate,
10
+ smoking, steps, stress, physical_activity, sleep, family_history,
11
+ diet_quality, alcohol, risk_score):
12
+
13
+ input_data = {
14
+ 'age': age,
15
+ 'bmi': bmi,
16
+ 'systolic_bp': systolic_bp,
17
+ 'diastolic_bp': diastolic_bp,
18
+ 'cholesterol_mg_dl': cholesterol,
19
+ 'resting_heart_rate': heart_rate,
20
+ 'smoking_status': smoking,
21
+ 'daily_steps': steps,
22
+ 'stress_level': stress,
23
+ 'physical_activity_hours_per_week': physical_activity,
24
+ 'sleep_hours': sleep,
25
+ 'family_history_heart_disease': family_history,
26
+ 'diet_quality_score': diet_quality,
27
+ 'alcohol_units_per_week': alcohol,
28
+ 'heart_disease_risk_score': risk_score
29
+ }
30
+
31
+ prediction = predictor.predict_single(input_data)
32
+
33
+ # Return mapping for color-coded feedback
34
+ result_text = f"## Predicted Category: {prediction.upper()}"
35
+
36
+ if prediction == 'Low':
37
+ description = "✅ Low risk! Excellent heart health habits."
38
+ color = "#2ed573"
39
+ elif prediction == 'Medium':
40
+ description = "⚠️ Moderate risk. Consider heart-healthy changes."
41
+ color = "#ffa502"
42
+ else:
43
+ description = "🚨 High risk! Please consult a health professional."
44
+ color = "#ff4757"
45
+
46
+ return f'<div style="background-color: {color}; padding: 20px; border-radius: 10px; color: white;">{result_text}<br>{description}</div>'
47
+
48
+ # Gradio Interface
49
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
50
+ gr.Markdown("# 🏥 CardioGuard: RNN Heart Risk Predictor")
51
+ gr.Markdown("Enter patient data below to analyze cardiovascular risk using a Deep Learning RNN model.")
52
+
53
+ with gr.Row():
54
+ with gr.Column():
55
+ age = gr.Number(label="Age", value=45)
56
+ bmi = gr.Number(label="BMI", value=26.5)
57
+ systolic = gr.Number(label="Systolic BP", value=130)
58
+ diastolic = gr.Number(label="Diastolic BP", value=85)
59
+ cholesterol = gr.Number(label="Cholesterol (mg/dl)", value=210)
60
+
61
+ with gr.Column():
62
+ smoking = gr.Dropdown(["Never", "Former", "Current"], label="Smoking Status", value="Never")
63
+ family_history = gr.Dropdown(["No", "Yes"], label="Family History", value="No")
64
+ steps = gr.Number(label="Daily Steps", value=6000)
65
+ heart_rate = gr.Number(label="Resting Heart Rate", value=72)
66
+ risk_score = gr.Number(label="Internal Risk Score (0-100)", value=35.0)
67
+
68
+ with gr.Column():
69
+ stress = gr.Slider(1, 10, step=1, label="Stress Level", value=5)
70
+ diet = gr.Slider(1, 10, step=1, label="Diet Quality", value=6)
71
+ activity = gr.Number(label="Physical Activity (hrs/wk)", value=3.5)
72
+ sleep = gr.Number(label="Sleep Hours", value=7.5)
73
+ alcohol = gr.Number(label="Alcohol Units/wk", value=2.0)
74
+
75
+ btn = gr.Button("Analyze Risk Profile", variant="primary")
76
+ output = gr.HTML()
77
+
78
+ btn.click(predict_risk, inputs=[
79
+ age, bmi, systolic, diastolic, cholesterol, heart_rate,
80
+ smoking, steps, stress, activity, sleep, family_history,
81
+ diet, alcohol, risk_score
82
+ ], outputs=output)
83
+
84
+ if __name__ == "__main__":
85
+ demo.launch()