Kayeaelne commited on
Commit
76db320
·
verified ·
1 Parent(s): 878c400

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -23
app.py CHANGED
@@ -109,26 +109,27 @@ exercise_input = gr.Number(label="Exercise in Last 2 Hours (minutes)", value=0)
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__":
134
- iface.launch()
 
 
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 in a Blocks context
113
+ with gr.Blocks() as iface:
114
+ current_glucose_input = gr.Number(label="Current Blood Glucose (mg/dL)", value=100)
115
+ meal_input = gr.Dropdown(["Fast Carb (Juice, Glucose Tablet, etc.)", "High Carb", "Balanced", "Protein/Fat", "Skipped"], label="Last Meal Type")
116
+ meal_time_input = gr.Textbox(label="Time of Last Meal (HH:MM)", placeholder="e.g. 13:30")
117
+ med_input = gr.Dropdown(["None", "Metformin", "Insulin", "Sulfonylurea"], label="Last Medication Taken")
118
+ med_time_input = gr.Textbox(label="Time of Last Medication (HH:MM)", placeholder="e.g. 08:00")
119
+ exercise_input = gr.Number(label="Exercise in Last 2 Hours (minutes)", value=0)
120
+ fast_carb_amount_input = gr.Number(label="Amount of Fast Carbs (grams)", value=0)
121
+
122
+ # Event to show/hide the fast carb input field
123
+ meal_input.change(fn=update_fast_carb_visibility, inputs=meal_input, outputs=fast_carb_amount_input)
124
+
125
+ output = gr.Textbox()
126
+
127
+ # Call the prediction function on form submission
128
+ gr.Button("Predict").click(
129
+ fn=predict_glucose,
130
+ inputs=[current_glucose_input, meal_input, meal_time_input, med_input, med_time_input, exercise_input, fast_carb_amount_input],
131
+ outputs=output
132
+ )
133
+
134
+ # Launch the interface
135
+ iface.launch()