Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- .gitattributes +1 -0
- app.py +21 -39
- chocolate_lab_butterfly_pic.png +3 -0
.gitattributes
CHANGED
|
@@ -37,3 +37,4 @@ a[[:space:]]dog[[:space:]]with[[:space:]]a[[:space:]]butterf.png filter=lfs diff
|
|
| 37 |
dog_butterfly.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
dog_butterfly_flap.png filter=lfs diff=lfs merge=lfs -text
|
| 39 |
butterfly_cute.gif filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 37 |
dog_butterfly.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
dog_butterfly_flap.png filter=lfs diff=lfs merge=lfs -text
|
| 39 |
butterfly_cute.gif filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
chocolate_lab_butterfly_pic.png filter=lfs diff=lfs merge=lfs -text
|
app.py
CHANGED
|
@@ -9,9 +9,7 @@ import os
|
|
| 9 |
from datasets import load_dataset, Dataset
|
| 10 |
from huggingface_hub import login
|
| 11 |
|
| 12 |
-
# Authenticate with your HF token stored as a secret
|
| 13 |
login(token=os.getenv("sitetoken"))
|
| 14 |
-
|
| 15 |
DATASET_NAME = "Mephesto1/Diabetic-tracker"
|
| 16 |
|
| 17 |
# Load or create dataset
|
|
@@ -45,12 +43,7 @@ def load_last_inputs():
|
|
| 45 |
sensor_site = ""
|
| 46 |
if pod_site not in [s["site"] for s in sites]:
|
| 47 |
pod_site = ""
|
| 48 |
-
return (
|
| 49 |
-
sensor_site,
|
| 50 |
-
last["sensor_date"],
|
| 51 |
-
pod_site,
|
| 52 |
-
last["pod_date"]
|
| 53 |
-
)
|
| 54 |
return "", "", "", ""
|
| 55 |
|
| 56 |
def convert_date_format(date_input):
|
|
@@ -108,7 +101,6 @@ def generate_schedules(sensor_site, sensor_date, pod_site, pod_date):
|
|
| 108 |
|
| 109 |
site_rotation = {}
|
| 110 |
|
| 111 |
-
# ๐ Apply selected starting pod site for first change
|
| 112 |
sensor_info_for_start = next(
|
| 113 |
(s for s in reversed(sensor_schedule) if s["date"] <= pod_date),
|
| 114 |
sensor_schedule[0]
|
|
@@ -120,12 +112,10 @@ def generate_schedules(sensor_site, sensor_date, pod_site, pod_date):
|
|
| 120 |
|
| 121 |
for i in range(pod_num_changes):
|
| 122 |
pod_change_date = pod_start_date + timedelta(days=i * pod_change_days)
|
| 123 |
-
|
| 124 |
sensor_info = next(
|
| 125 |
(s for s in reversed(sensor_schedule) if s["date"] <= pod_change_date.strftime("%Y-%m-%d")),
|
| 126 |
sensor_schedule[0]
|
| 127 |
)
|
| 128 |
-
|
| 129 |
key = f"{sensor_info['site']}_{sensor_info['date']}"
|
| 130 |
available_pod_sites = pod_sites_map.get(sensor_info["site"], ["Left Stomach", "Right Stomach"])
|
| 131 |
|
|
@@ -150,9 +140,7 @@ def generate_schedules(sensor_site, sensor_date, pod_site, pod_date):
|
|
| 150 |
elif type_ == "pod":
|
| 151 |
return "\n".join([f"Pod on {entry['date']} at {entry['pod_site']} โ Sensor is on {entry['sensor_site']}" for entry in schedule])
|
| 152 |
|
| 153 |
-
|
| 154 |
-
formatted_pod_schedule = format_schedule(pod_schedule, "pod")
|
| 155 |
-
return formatted_sensor_schedule, formatted_pod_schedule
|
| 156 |
|
| 157 |
pod_sites_map = {
|
| 158 |
"Left Arm": ["Left Leg", "Left Stomach", "Left Arm"],
|
|
@@ -161,46 +149,40 @@ pod_sites_map = {
|
|
| 161 |
"Right Arm": ["Right Leg", "Right Stomach", "Right Arm"]
|
| 162 |
}
|
| 163 |
|
| 164 |
-
#
|
| 165 |
-
|
| 166 |
-
|
| 167 |
|
| 168 |
-
def
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
time.sleep(0.4)
|
| 172 |
-
yield dog_static, sensor_sched, pod_sched
|
| 173 |
|
| 174 |
# ๐๏ธ Build the interface
|
| 175 |
with gr.Blocks() as demo:
|
| 176 |
-
gr.Markdown("###
|
| 177 |
|
| 178 |
last_sensor_site, last_sensor_date, last_pod_site, last_pod_date = load_last_inputs()
|
| 179 |
dropdown_sites = [site["site"] for site in sites]
|
| 180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
sensor_site = gr.Dropdown(dropdown_sites, label="Sensor Site", value=last_sensor_site)
|
| 182 |
sensor_date = Calendar(type="datetime", label="Sensor Change Date", value=last_sensor_date)
|
| 183 |
pod_site = gr.Dropdown(dropdown_sites, label="Pod Site", value=last_pod_site)
|
| 184 |
pod_date = Calendar(type="datetime", label="Pod Change Date", value=last_pod_date)
|
| 185 |
|
| 186 |
-
butterfly_display = gr.Image(
|
| 187 |
-
|
| 188 |
-
sensor_output = gr.Textbox(label="Sensor Schedule", lines=10, value="", interactive=True)
|
| 189 |
-
pod_output = gr.Textbox(label="Pod Schedule", lines=10, value="", interactive=True)
|
| 190 |
|
| 191 |
paw_button = gr.Button("๐พ Press your paw here to save!")
|
| 192 |
-
paw_button.click(
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
outputs=[butterfly_display, sensor_output, pod_output])
|
| 198 |
-
|
| 199 |
-
# Trigger image + schedules on load
|
| 200 |
-
sensor_sched, pod_sched = generate_schedules(last_sensor_site, last_sensor_date, last_pod_site, last_pod_date)
|
| 201 |
-
butterfly_display.value = dog_static
|
| 202 |
-
sensor_output.value = sensor_sched
|
| 203 |
-
pod_output.value = pod_sched
|
| 204 |
|
| 205 |
if __name__ == "__main__":
|
| 206 |
demo.launch()
|
|
|
|
| 9 |
from datasets import load_dataset, Dataset
|
| 10 |
from huggingface_hub import login
|
| 11 |
|
|
|
|
| 12 |
login(token=os.getenv("sitetoken"))
|
|
|
|
| 13 |
DATASET_NAME = "Mephesto1/Diabetic-tracker"
|
| 14 |
|
| 15 |
# Load or create dataset
|
|
|
|
| 43 |
sensor_site = ""
|
| 44 |
if pod_site not in [s["site"] for s in sites]:
|
| 45 |
pod_site = ""
|
| 46 |
+
return (sensor_site, last["sensor_date"], pod_site, last["pod_date"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
return "", "", "", ""
|
| 48 |
|
| 49 |
def convert_date_format(date_input):
|
|
|
|
| 101 |
|
| 102 |
site_rotation = {}
|
| 103 |
|
|
|
|
| 104 |
sensor_info_for_start = next(
|
| 105 |
(s for s in reversed(sensor_schedule) if s["date"] <= pod_date),
|
| 106 |
sensor_schedule[0]
|
|
|
|
| 112 |
|
| 113 |
for i in range(pod_num_changes):
|
| 114 |
pod_change_date = pod_start_date + timedelta(days=i * pod_change_days)
|
|
|
|
| 115 |
sensor_info = next(
|
| 116 |
(s for s in reversed(sensor_schedule) if s["date"] <= pod_change_date.strftime("%Y-%m-%d")),
|
| 117 |
sensor_schedule[0]
|
| 118 |
)
|
|
|
|
| 119 |
key = f"{sensor_info['site']}_{sensor_info['date']}"
|
| 120 |
available_pod_sites = pod_sites_map.get(sensor_info["site"], ["Left Stomach", "Right Stomach"])
|
| 121 |
|
|
|
|
| 140 |
elif type_ == "pod":
|
| 141 |
return "\n".join([f"Pod on {entry['date']} at {entry['pod_site']} โ Sensor is on {entry['sensor_site']}" for entry in schedule])
|
| 142 |
|
| 143 |
+
return format_schedule(sensor_schedule, "sensor"), format_schedule(pod_schedule, "pod")
|
|
|
|
|
|
|
| 144 |
|
| 145 |
pod_sites_map = {
|
| 146 |
"Left Arm": ["Left Leg", "Left Stomach", "Left Arm"],
|
|
|
|
| 149 |
"Right Arm": ["Right Leg", "Right Stomach", "Right Arm"]
|
| 150 |
}
|
| 151 |
|
| 152 |
+
# ๐ถ Load image and gif
|
| 153 |
+
display_image = Image.open("chocolate_lab_butterfly_pic.png")
|
| 154 |
+
butterfly_gif = Image.open("butterfly_cute.gif")
|
| 155 |
|
| 156 |
+
def show_gif_after_save(sensor_site, sensor_date, pod_site, pod_date):
|
| 157 |
+
save_to_dataset(sensor_site, sensor_date, pod_site, pod_date)
|
| 158 |
+
return butterfly_gif
|
|
|
|
|
|
|
| 159 |
|
| 160 |
# ๐๏ธ Build the interface
|
| 161 |
with gr.Blocks() as demo:
|
| 162 |
+
gr.Markdown("### Hello, let's plan your new pod and sensor change. ๐ถ๐ฆ")
|
| 163 |
|
| 164 |
last_sensor_site, last_sensor_date, last_pod_site, last_pod_date = load_last_inputs()
|
| 165 |
dropdown_sites = [site["site"] for site in sites]
|
| 166 |
|
| 167 |
+
gr.Image(value=display_image, show_label=False)
|
| 168 |
+
|
| 169 |
+
sensor_sched, pod_sched = generate_schedules(last_sensor_site, last_sensor_date, last_pod_site, last_pod_date)
|
| 170 |
+
sensor_output = gr.Textbox(label="Sensor Schedule", lines=10, value=sensor_sched, interactive=True)
|
| 171 |
+
pod_output = gr.Textbox(label="Pod Schedule", lines=10, value=pod_sched, interactive=True)
|
| 172 |
+
|
| 173 |
sensor_site = gr.Dropdown(dropdown_sites, label="Sensor Site", value=last_sensor_site)
|
| 174 |
sensor_date = Calendar(type="datetime", label="Sensor Change Date", value=last_sensor_date)
|
| 175 |
pod_site = gr.Dropdown(dropdown_sites, label="Pod Site", value=last_pod_site)
|
| 176 |
pod_date = Calendar(type="datetime", label="Pod Change Date", value=last_pod_date)
|
| 177 |
|
| 178 |
+
butterfly_display = gr.Image(show_label=False)
|
|
|
|
|
|
|
|
|
|
| 179 |
|
| 180 |
paw_button = gr.Button("๐พ Press your paw here to save!")
|
| 181 |
+
paw_button.click(
|
| 182 |
+
fn=show_gif_after_save,
|
| 183 |
+
inputs=[sensor_site, sensor_date, pod_site, pod_date],
|
| 184 |
+
outputs=butterfly_display
|
| 185 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
|
| 187 |
if __name__ == "__main__":
|
| 188 |
demo.launch()
|
chocolate_lab_butterfly_pic.png
ADDED
|
|
Git LFS Details
|