Spaces:
Sleeping
Sleeping
File size: 1,773 Bytes
18cf2cb 82579ab 18cf2cb 82579ab 18cf2cb de5608c 82579ab de5608c 82579ab de5608c 82579ab de5608c 82579ab de5608c 82579ab de5608c 18cf2cb 82579ab de5608c 82579ab de5608c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
import gradio as gr
from tools import *
from format_dexcom import process_csv
import tempfile
import os
def process_and_prepare(file):
"""Process the raw CSV and prepare it for prediction"""
# Create a temporary file for the processed CSV
with tempfile.NamedTemporaryFile(delete=False, suffix='.csv') as tmp_file:
processed_path = tmp_file.name
# Process the CSV file
process_csv(
input_dir=file.name,
output_file=processed_path
)
# Run the preparation step with processed file
return prep_predict_glucose_tool(processed_path)
with gr.Blocks() as demo:
gr.Markdown("# Glucose Prediction Tool")
gr.Markdown("Upload a Dexcom CSV file to get predictions")
file_input = gr.File(label="Upload Raw Dexcom CSV File")
with gr.Row():
index_slider = gr.Slider(
minimum=0,
maximum=100, # This will be updated dynamically
value=10,
step=1,
label="Select Sample Index",
visible=False
)
sample_count = gr.Markdown(visible=False)
plot_output = gr.Plot()
# Update slider and show total samples when file is uploaded
file_input.change(
fn=process_and_prepare,
inputs=[file_input],
outputs=[index_slider, sample_count],
queue=True
)
# Update visibility after processing
file_input.change(
fn=lambda: (gr.Slider(visible=True), gr.Markdown(visible=True)),
outputs=[index_slider, sample_count],
queue=True
)
# Only update plot after processing is complete
index_slider.change(
fn=predict_glucose_tool,
inputs=[index_slider],
outputs=plot_output,
queue=True
)
demo.launch() |