Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -98,27 +98,36 @@ def predict_glucose(current_glucose, last_meal, meal_time, last_med, med_time, e
|
|
| 98 |
# Define Gradio interface
|
| 99 |
fast_carb_amount_input = gr.Number(label="Amount of Fast Carbs (grams)", value=0)
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
iface = gr.Interface(
|
| 102 |
fn=predict_glucose,
|
| 103 |
inputs=[
|
| 104 |
gr.Number(label="Current Blood Glucose (mg/dL)", value=100),
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
fast_carb_amount_input
|
| 111 |
],
|
| 112 |
outputs="text",
|
| 113 |
title="Blood Glucose Prediction (Now, 1 Hour, and 3 Hours Later)",
|
| 114 |
description="Enter your latest meal, medication, and exercise details to predict your blood sugar trend over the next 3 hours. Specify amount of fast carbs if applicable."
|
| 115 |
)
|
| 116 |
|
| 117 |
-
# Update visibility
|
| 118 |
-
|
| 119 |
-
return fast_carb_amount_input.update(visible=(last_meal == "Fast Carb (Juice, Glucose Tablet, etc.)"))
|
| 120 |
-
|
| 121 |
-
iface.inputs[1].change(fn=update_fast_carb_visibility, inputs=iface.inputs[1], outputs=fast_carb_amount_input)
|
| 122 |
|
| 123 |
# Run app
|
| 124 |
if __name__ == "__main__":
|
|
|
|
| 98 |
# Define Gradio interface
|
| 99 |
fast_carb_amount_input = gr.Number(label="Amount of Fast Carbs (grams)", value=0)
|
| 100 |
|
| 101 |
+
# Create the interface components
|
| 102 |
+
meal_input = gr.Dropdown(["Fast Carb (Juice, Glucose Tablet, etc.)", "High Carb", "Balanced", "Protein/Fat", "Skipped"], label="Last Meal Type")
|
| 103 |
+
meal_time_input = gr.Textbox(label="Time of Last Meal (HH:MM)", placeholder="e.g. 13:30")
|
| 104 |
+
med_input = gr.Dropdown(["None", "Metformin", "Insulin", "Sulfonylurea"], label="Last Medication Taken")
|
| 105 |
+
med_time_input = gr.Textbox(label="Time of Last Medication (HH:MM)", placeholder="e.g. 08:00")
|
| 106 |
+
exercise_input = gr.Number(label="Exercise in Last 2 Hours (minutes)", value=0)
|
| 107 |
+
|
| 108 |
+
# Function to show/hide the fast carb amount input
|
| 109 |
+
def update_fast_carb_visibility(last_meal):
|
| 110 |
+
return gr.update(visible=(last_meal == "Fast Carb (Juice, Glucose Tablet, etc.)"))
|
| 111 |
+
|
| 112 |
+
# Define Gradio Interface
|
| 113 |
iface = gr.Interface(
|
| 114 |
fn=predict_glucose,
|
| 115 |
inputs=[
|
| 116 |
gr.Number(label="Current Blood Glucose (mg/dL)", value=100),
|
| 117 |
+
meal_input,
|
| 118 |
+
meal_time_input,
|
| 119 |
+
med_input,
|
| 120 |
+
med_time_input,
|
| 121 |
+
exercise_input,
|
| 122 |
+
fast_carb_amount_input
|
| 123 |
],
|
| 124 |
outputs="text",
|
| 125 |
title="Blood Glucose Prediction (Now, 1 Hour, and 3 Hours Later)",
|
| 126 |
description="Enter your latest meal, medication, and exercise details to predict your blood sugar trend over the next 3 hours. Specify amount of fast carbs if applicable."
|
| 127 |
)
|
| 128 |
|
| 129 |
+
# Update visibility based on the selected meal type
|
| 130 |
+
meal_input.change(fn=update_fast_carb_visibility, inputs=meal_input, outputs=fast_carb_amount_input)
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
# Run app
|
| 133 |
if __name__ == "__main__":
|