Update app.py
Browse files
app.py
CHANGED
@@ -7,11 +7,15 @@ model = joblib.load('logistic_regression_model.pkl')
|
|
7 |
scaler = joblib.load('scaler.pkl')
|
8 |
|
9 |
def initial_risk_check(features):
|
|
|
10 |
features_scaled = scaler.transform([features])
|
11 |
prediction = model.predict_proba(features_scaled)[:, 1]
|
|
|
|
|
12 |
high_risk_threshold = 0.75
|
13 |
moderate_risk_threshold = 0.5
|
14 |
|
|
|
15 |
if prediction >= high_risk_threshold:
|
16 |
return "High risk. Please consult a doctor immediately.", prediction
|
17 |
elif prediction >= moderate_risk_threshold:
|
@@ -20,7 +24,7 @@ def initial_risk_check(features):
|
|
20 |
return "Low risk. Maintain a healthy lifestyle and schedule routine check-ups.", prediction
|
21 |
|
22 |
def launch_interface():
|
23 |
-
with gr.Blocks(css
|
24 |
.gradio-container {
|
25 |
font-family: Arial, sans-serif;
|
26 |
background-color: #f9f9f9;
|
@@ -36,13 +40,13 @@ def launch_interface():
|
|
36 |
.gr-textbox {
|
37 |
margin-bottom: 1em;
|
38 |
}
|
39 |
-
|
40 |
|
41 |
-
gr.Markdown(
|
42 |
# Gestational Diabetes Risk Calculator
|
43 |
This calculator helps you assess your risk for gestational diabetes. Enter your details below and get an initial risk assessment.
|
44 |
If you are above medium risk, please provide more detailed information for a more accurate assessment.
|
45 |
-
|
46 |
|
47 |
with gr.Row():
|
48 |
pregnancies = gr.Number(label="Number of Pregnancies")
|
@@ -53,7 +57,7 @@ def launch_interface():
|
|
53 |
with gr.Row():
|
54 |
ogtt = gr.Number(label="OGTT", visible=False)
|
55 |
sys_bp = gr.Number(label="Systolic Blood Pressure", visible=False)
|
56 |
-
hdl = gr.Number(label="HDL", visible=False)
|
57 |
|
58 |
submit_button = gr.Button("Submit")
|
59 |
output = gr.Textbox(label="Result")
|
@@ -62,7 +66,7 @@ def launch_interface():
|
|
62 |
if detailed:
|
63 |
features = [pregnancies, ogtt, sys_bp, bmi, hdl, age]
|
64 |
else:
|
65 |
-
features = [pregnancies, 120, 120, bmi, 0.5, age]
|
66 |
result, prediction = initial_risk_check(features)
|
67 |
return result
|
68 |
|
|
|
7 |
scaler = joblib.load('scaler.pkl')
|
8 |
|
9 |
def initial_risk_check(features):
|
10 |
+
# Scale and predict risk based on the features
|
11 |
features_scaled = scaler.transform([features])
|
12 |
prediction = model.predict_proba(features_scaled)[:, 1]
|
13 |
+
|
14 |
+
# Define risk thresholds
|
15 |
high_risk_threshold = 0.75
|
16 |
moderate_risk_threshold = 0.5
|
17 |
|
18 |
+
# Determine risk level and recommendation
|
19 |
if prediction >= high_risk_threshold:
|
20 |
return "High risk. Please consult a doctor immediately.", prediction
|
21 |
elif prediction >= moderate_risk_threshold:
|
|
|
24 |
return "Low risk. Maintain a healthy lifestyle and schedule routine check-ups.", prediction
|
25 |
|
26 |
def launch_interface():
|
27 |
+
with gr.Blocks(css="""
|
28 |
.gradio-container {
|
29 |
font-family: Arial, sans-serif;
|
30 |
background-color: #f9f9f9;
|
|
|
40 |
.gr-textbox {
|
41 |
margin-bottom: 1em;
|
42 |
}
|
43 |
+
""") as app:
|
44 |
|
45 |
+
gr.Markdown("""
|
46 |
# Gestational Diabetes Risk Calculator
|
47 |
This calculator helps you assess your risk for gestational diabetes. Enter your details below and get an initial risk assessment.
|
48 |
If you are above medium risk, please provide more detailed information for a more accurate assessment.
|
49 |
+
""")
|
50 |
|
51 |
with gr.Row():
|
52 |
pregnancies = gr.Number(label="Number of Pregnancies")
|
|
|
57 |
with gr.Row():
|
58 |
ogtt = gr.Number(label="OGTT", visible=False)
|
59 |
sys_bp = gr.Number(label="Systolic Blood Pressure", visible=False)
|
60 |
+
hdl = gr.Number(label="HDL", visible=False) # Assuming HDL is used for DPF
|
61 |
|
62 |
submit_button = gr.Button("Submit")
|
63 |
output = gr.Textbox(label="Result")
|
|
|
66 |
if detailed:
|
67 |
features = [pregnancies, ogtt, sys_bp, bmi, hdl, age]
|
68 |
else:
|
69 |
+
features = [pregnancies, 120, 120, bmi, 0.5, age] # Default values for detailed inputs
|
70 |
result, prediction = initial_risk_check(features)
|
71 |
return result
|
72 |
|