Kayeaelne commited on
Commit
878c400
·
verified ·
1 Parent(s): 5ef7452

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -11
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
- gr.Dropdown(["Fast Carb (Juice, Glucose Tablet, etc.)", "High Carb", "Balanced", "Protein/Fat", "Skipped"], label="Last Meal Type"),
106
- gr.Textbox(label="Time of Last Meal (HH:MM)", placeholder="e.g. 13:30"),
107
- gr.Dropdown(["None", "Metformin", "Insulin", "Sulfonylurea"], label="Last Medication Taken"),
108
- gr.Textbox(label="Time of Last Medication (HH:MM)", placeholder="e.g. 08:00"),
109
- gr.Number(label="Exercise in Last 2 Hours (minutes)", value=0),
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 of Fast Carb amount input based on selection
118
- def update_fast_carb_visibility(last_meal):
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__":