Kayeaelne commited on
Commit
cc5a88a
·
verified ·
1 Parent(s): ef8cb15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -3,7 +3,11 @@ import numpy as np
3
  import matplotlib.pyplot as plt
4
 
5
  # Function to simulate blood glucose changes over time
6
- def predict_glucose(current_glucose, meal_type, meal_time, galvus_dose, galvus_time, exercise_duration, fast_carbs_ml, prediction_time=3):
 
 
 
 
7
  # Constants for glucose reduction effects
8
  post_meal_reduction = 63.6 # mg/dL (avg reduction for Vildagliptin in 2 hours)
9
  fasting_reduction = 27.7 # mg/dL (avg reduction over 6-12 hours)
@@ -18,8 +22,8 @@ def predict_glucose(current_glucose, meal_type, meal_time, galvus_dose, galvus_t
18
  glucose_after_meal = current_glucose + 20 # Small glucose increase due to protein
19
  elif meal_type == 'Low-carb':
20
  glucose_after_meal = current_glucose - 10 # Small reduction due to low-carb meal
21
- elif meal_type == 'Fast carb':
22
- glucose_after_meal = current_glucose + carb_effect # For fast carbs like milk/juice
23
  else:
24
  glucose_after_meal = current_glucose # Normal meal with moderate carbs
25
 
@@ -63,10 +67,12 @@ def build_interface():
63
  # Inputs for current glucose, meal info, medication dose, exercise, fast carbs, and Galvus time
64
  with gr.Row():
65
  current_glucose = gr.Number(label="Current Blood Glucose (mg/dL)", value=150)
66
- meal_type = gr.Radio(choices=["Normal", "High-carb", "Protein-heavy", "Low-carb", "Fast carb"], label="Meal Type", value="Normal")
67
- meal_time = gr.Number(label="Last Meal Time (in hours)", value=2)
 
68
  galvus_dose = gr.Number(label="Galvus Dose (mg)", value=50)
69
- galvus_time = gr.Number(label="Galvus Time of Administration (hours)", value=0) # Input for when Galvus was taken
 
70
  exercise_duration = gr.Number(label="Exercise Duration (min)", value=0)
71
  fast_carbs_ml = gr.Number(label="Fast Carbs (mL)", value=0)
72
 
@@ -81,7 +87,7 @@ def build_interface():
81
  # Set button action
82
  predict_button.click(
83
  predict_glucose,
84
- inputs=[current_glucose, meal_type, meal_time, galvus_dose, galvus_time, exercise_duration, fast_carbs_ml],
85
  outputs=[glucose_1hr_output, glucose_3hr_output, glucose_graph]
86
  )
87
 
 
3
  import matplotlib.pyplot as plt
4
 
5
  # Function to simulate blood glucose changes over time
6
+ def predict_glucose(current_glucose, meal_type, meal_time_hr, meal_time_min, galvus_dose, galvus_time_hr, galvus_time_min, exercise_duration, fast_carbs_ml, prediction_time=3):
7
+ # Convert hours and minutes to total hours
8
+ meal_time = meal_time_hr + (meal_time_min / 60)
9
+ galvus_time = galvus_time_hr + (galvus_time_min / 60)
10
+
11
  # Constants for glucose reduction effects
12
  post_meal_reduction = 63.6 # mg/dL (avg reduction for Vildagliptin in 2 hours)
13
  fasting_reduction = 27.7 # mg/dL (avg reduction over 6-12 hours)
 
22
  glucose_after_meal = current_glucose + 20 # Small glucose increase due to protein
23
  elif meal_type == 'Low-carb':
24
  glucose_after_meal = current_glucose - 10 # Small reduction due to low-carb meal
25
+ elif meal_type == 'Fast-carb':
26
+ glucose_after_meal = current_glucose + carb_effect * 1.2 # Fast carbs spike blood sugar
27
  else:
28
  glucose_after_meal = current_glucose # Normal meal with moderate carbs
29
 
 
67
  # Inputs for current glucose, meal info, medication dose, exercise, fast carbs, and Galvus time
68
  with gr.Row():
69
  current_glucose = gr.Number(label="Current Blood Glucose (mg/dL)", value=150)
70
+ meal_type = gr.Radio(choices=["Normal", "High-carb", "Protein-heavy", "Low-carb", "Fast-carb"], label="Meal Type", value="Normal")
71
+ meal_time_hr = gr.Number(label="Last Meal Time (Hours)", value=2)
72
+ meal_time_min = gr.Number(label="Last Meal Time (Minutes)", value=0)
73
  galvus_dose = gr.Number(label="Galvus Dose (mg)", value=50)
74
+ galvus_time_hr = gr.Number(label="Galvus Administration Time (Hours)", value=0)
75
+ galvus_time_min = gr.Number(label="Galvus Administration Time (Minutes)", value=0)
76
  exercise_duration = gr.Number(label="Exercise Duration (min)", value=0)
77
  fast_carbs_ml = gr.Number(label="Fast Carbs (mL)", value=0)
78
 
 
87
  # Set button action
88
  predict_button.click(
89
  predict_glucose,
90
+ inputs=[current_glucose, meal_type, meal_time_hr, meal_time_min, galvus_dose, galvus_time_hr, galvus_time_min, exercise_duration, fast_carbs_ml],
91
  outputs=[glucose_1hr_output, glucose_3hr_output, glucose_graph]
92
  )
93