Kayeaelne commited on
Commit
a8e848d
·
verified ·
1 Parent(s): 1103a86

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -8
app.py CHANGED
@@ -3,11 +3,15 @@ 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)
10
 
 
 
 
 
11
  # Adjust for fast carbs (milk, juice, etc.)
12
  carb_effect = fast_carbs_ml * 1.5 # Approximate glucose rise per mL of fast carbs
13
 
@@ -18,21 +22,28 @@ 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
  else:
22
  glucose_after_meal = current_glucose # Normal meal with moderate carbs
23
 
24
- # Simulate blood glucose levels over 1 hour and 3 hours
25
  glucose_1hr = glucose_after_meal - post_meal_reduction + carb_effect * 0.5 # Adjust for carb effect
26
  glucose_3hr = glucose_1hr - fasting_reduction
27
 
28
  # Adjust the effects of Galvus based on its administration time (medication effect starts at galvus_time + 1-2 hours)
29
- time_since_galvus = meal_time - galvus_time
30
- if time_since_galvus >= 1: # After 1 hour, the effects of Galvus start kicking in
31
  glucose_3hr -= fasting_reduction # Galvus effect after 3 hours
32
 
33
  # Exercise effect on glucose (hypothetical value, may vary based on intensity)
34
  glucose_3hr -= exercise_duration * 2 # Exercise reduces glucose by 2 mg/dL per minute
35
 
 
 
 
 
 
36
  # Plotting the graph of glucose prediction over time
37
  time_points = [0, 1, 3] # Time: 0 hours, 1 hour, 3 hours
38
  glucose_values = [current_glucose, glucose_1hr, glucose_3hr]
@@ -61,12 +72,15 @@ def build_interface():
61
  # Inputs for current glucose, meal info, medication dose, exercise, fast carbs, and Galvus time
62
  with gr.Row():
63
  current_glucose = gr.Number(label="Current Blood Glucose (mg/dL)", value=105)
64
- meal_type = gr.Radio(choices=["Normal", "High-carb", "Protein-heavy", "Low-carb"], label="Meal Type", value="Low-carb")
65
- meal_time = gr.Number(label="Last Meal Time (in hours)", value=6)
 
66
  galvus_dose = gr.Number(label="Galvus Dose (mg)", value=50)
67
- galvus_time = gr.Number(label="Galvus Time of Administration (hours)", value=2) # Input for when Galvus was taken
 
68
  exercise_duration = gr.Number(label="Exercise Duration (min)", value=60)
69
  fast_carbs_ml = gr.Number(label="Fast Carbs (mL)", value=0)
 
70
 
71
  # Output predictions and graph
72
  glucose_1hr_output = gr.Textbox(label="Predicted Glucose Level in 1 Hour (mg/dL)")
@@ -79,7 +93,7 @@ def build_interface():
79
  # Set button action
80
  predict_button.click(
81
  predict_glucose,
82
- inputs=[current_glucose, meal_type, meal_time, galvus_dose, galvus_time, exercise_duration, fast_carbs_ml],
83
  outputs=[glucose_1hr_output, glucose_3hr_output, glucose_graph]
84
  )
85
 
 
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, chocolate_time_min, 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)
10
 
11
+ # Convert meal time and Galvus time to minutes for easier calculations
12
+ meal_time_total_min = meal_time_hr * 60 + meal_time_min
13
+ galvus_time_total_min = galvus_time_hr * 60 + galvus_time_min
14
+
15
  # Adjust for fast carbs (milk, juice, etc.)
16
  carb_effect = fast_carbs_ml * 1.5 # Approximate glucose rise per mL of fast carbs
17
 
 
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 # Fast carbs like juice, milk increase glucose quickly
27
  else:
28
  glucose_after_meal = current_glucose # Normal meal with moderate carbs
29
 
30
+ # Calculate glucose levels over 1 hour and 3 hours
31
  glucose_1hr = glucose_after_meal - post_meal_reduction + carb_effect * 0.5 # Adjust for carb effect
32
  glucose_3hr = glucose_1hr - fasting_reduction
33
 
34
  # Adjust the effects of Galvus based on its administration time (medication effect starts at galvus_time + 1-2 hours)
35
+ time_since_galvus = meal_time_total_min - galvus_time_total_min
36
+ if time_since_galvus >= 60: # After 1 hour, the effects of Galvus start kicking in
37
  glucose_3hr -= fasting_reduction # Galvus effect after 3 hours
38
 
39
  # Exercise effect on glucose (hypothetical value, may vary based on intensity)
40
  glucose_3hr -= exercise_duration * 2 # Exercise reduces glucose by 2 mg/dL per minute
41
 
42
+ # Chocolate bar effect
43
+ if chocolate_time_min <= 60: # If the chocolate bar is eaten within 1 hour
44
+ glucose_1hr += 40 # Approximate glucose rise from chocolate
45
+ glucose_3hr += 30 # This would still contribute to an increase at 3 hours
46
+
47
  # Plotting the graph of glucose prediction over time
48
  time_points = [0, 1, 3] # Time: 0 hours, 1 hour, 3 hours
49
  glucose_values = [current_glucose, glucose_1hr, glucose_3hr]
 
72
  # Inputs for current glucose, meal info, medication dose, exercise, fast carbs, and Galvus time
73
  with gr.Row():
74
  current_glucose = gr.Number(label="Current Blood Glucose (mg/dL)", value=105)
75
+ meal_type = gr.Radio(choices=["Normal", "High-carb", "Protein-heavy", "Low-carb", "Fast carb"], label="Meal Type", value="Low-carb")
76
+ meal_time_hr = gr.Number(label="Last Meal Time (hours)", value=6)
77
+ meal_time_min = gr.Number(label="Last Meal Time (minutes)", value=0)
78
  galvus_dose = gr.Number(label="Galvus Dose (mg)", value=50)
79
+ galvus_time_hr = gr.Number(label="Galvus Time of Administration (hours)", value=2)
80
+ galvus_time_min = gr.Number(label="Galvus Time of Administration (minutes)", value=0)
81
  exercise_duration = gr.Number(label="Exercise Duration (min)", value=60)
82
  fast_carbs_ml = gr.Number(label="Fast Carbs (mL)", value=0)
83
+ chocolate_time_min = gr.Number(label="Time After Meal When Chocolate Bar Is Eaten (min)", value=60)
84
 
85
  # Output predictions and graph
86
  glucose_1hr_output = gr.Textbox(label="Predicted Glucose Level in 1 Hour (mg/dL)")
 
93
  # Set button action
94
  predict_button.click(
95
  predict_glucose,
96
+ inputs=[current_glucose, meal_type, meal_time_hr, meal_time_min, galvus_dose, galvus_time_hr, galvus_time_min, exercise_duration, fast_carbs_ml, chocolate_time_min],
97
  outputs=[glucose_1hr_output, glucose_3hr_output, glucose_graph]
98
  )
99