antonkulaga commited on
Commit
73cfaa5
·
1 Parent(s): ff0c43b

update space

Browse files
.gitignore CHANGED
@@ -7,4 +7,6 @@ files/
7
  .mamba-env/
8
  .mamba-env-cache/
9
  .DS_Store
10
- .vscode/
 
 
 
7
  .mamba-env/
8
  .mamba-env-cache/
9
  .DS_Store
10
+ .vscode/
11
+ .gradio/
12
+ __pycache__
app.py CHANGED
@@ -3,26 +3,61 @@ from tools import *
3
  from format_dexcom import process_csv
4
  import tempfile
5
  import os
 
 
 
 
 
6
 
7
- def process_and_prepare(file):
8
- """Process the raw CSV and prepare it for prediction"""
9
- # Create a temporary file for the processed CSV
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  with tempfile.NamedTemporaryFile(delete=False, suffix='.csv') as tmp_file:
11
  processed_path = tmp_file.name
12
 
13
- # Process the CSV file
14
  process_csv(
15
  input_dir=file.name,
16
  output_file=processed_path
17
  )
18
 
19
- # Run the preparation step with processed file
20
- return prep_predict_glucose_tool(processed_path)
21
 
22
  with gr.Blocks() as demo:
23
  gr.Markdown("# Glucose Prediction Tool")
24
  gr.Markdown("Upload a Dexcom CSV file to get predictions")
25
 
 
 
 
 
 
 
26
  file_input = gr.File(label="Upload Raw Dexcom CSV File")
27
  with gr.Row():
28
  index_slider = gr.Slider(
@@ -39,18 +74,11 @@ with gr.Blocks() as demo:
39
  # Update slider and show total samples when file is uploaded
40
  file_input.change(
41
  fn=process_and_prepare,
42
- inputs=[file_input],
43
  outputs=[index_slider, sample_count],
44
  queue=True
45
  )
46
 
47
- # Update visibility after processing
48
- file_input.change(
49
- fn=lambda: (gr.Slider(visible=True), gr.Markdown(visible=True)),
50
- outputs=[index_slider, sample_count],
51
- queue=True
52
- )
53
-
54
  # Only update plot after processing is complete
55
  index_slider.change(
56
  fn=predict_glucose_tool,
@@ -59,4 +87,4 @@ with gr.Blocks() as demo:
59
  queue=True
60
  )
61
 
62
- demo.launch()
 
3
  from format_dexcom import process_csv
4
  import tempfile
5
  import os
6
+ from huggingface_hub import list_models
7
+ from typing import List, Tuple
8
+ from pathlib import Path
9
+ import plotly.graph_objects as go
10
+ from huggingface_hub import HfApi
11
 
12
+ def get_available_models() -> List[str]:
13
+ """Get list of available gluformer models from HuggingFace."""
14
+ api = HfApi()
15
+ files = api.list_repo_files("Livia-Zaharia/gluformer_models")
16
+
17
+ # Filter for .pth files
18
+ gluformer_models = [
19
+ file for file in files
20
+ if file.endswith('.pth') and "weights" in file.lower() and 'gluformer' in file.lower()
21
+ ]
22
+
23
+ return gluformer_models
24
+
25
+ AVAILABLE_MODELS = get_available_models()
26
+ print(AVAILABLE_MODELS)
27
+
28
+ def process_and_prepare(file: tempfile._TemporaryFileWrapper, model_name: str) -> Tuple[gr.Slider, gr.Markdown]:
29
+ """Process the raw CSV and prepare it for prediction.
30
+
31
+ Args:
32
+ file: Uploaded temporary file object
33
+ model_name: Name of the selected model
34
+
35
+ Returns:
36
+ Tuple containing:
37
+ - Updated slider component
38
+ - Sample count markdown component
39
+ """
40
  with tempfile.NamedTemporaryFile(delete=False, suffix='.csv') as tmp_file:
41
  processed_path = tmp_file.name
42
 
 
43
  process_csv(
44
  input_dir=file.name,
45
  output_file=processed_path
46
  )
47
 
48
+ return prep_predict_glucose_tool(processed_path, model_name)
49
+
50
 
51
  with gr.Blocks() as demo:
52
  gr.Markdown("# Glucose Prediction Tool")
53
  gr.Markdown("Upload a Dexcom CSV file to get predictions")
54
 
55
+ model_selector = gr.Dropdown(
56
+ choices=AVAILABLE_MODELS,
57
+ value="gluformer_1samples_500epochs_10heads_32batch_geluactivation_livia_large_weights.pth",
58
+ label="Select Model",
59
+ interactive=True
60
+ )
61
  file_input = gr.File(label="Upload Raw Dexcom CSV File")
62
  with gr.Row():
63
  index_slider = gr.Slider(
 
74
  # Update slider and show total samples when file is uploaded
75
  file_input.change(
76
  fn=process_and_prepare,
77
+ inputs=[file_input, model_selector],
78
  outputs=[index_slider, sample_count],
79
  queue=True
80
  )
81
 
 
 
 
 
 
 
 
82
  # Only update plot after processing is complete
83
  index_slider.change(
84
  fn=predict_glucose_tool,
 
87
  queue=True
88
  )
89
 
90
+ demo.launch(share=True)
data_formatter/__pycache__/__init__.cpython-311.pyc DELETED
Binary file (182 Bytes)
 
data_formatter/__pycache__/types.cpython-311.pyc DELETED
Binary file (1.09 kB)
 
data_formatter/__pycache__/utils.cpython-311.pyc DELETED
Binary file (19.8 kB)
 
gluformer/__pycache__/__init__.cpython-311.pyc DELETED
Binary file (177 Bytes)
 
gluformer/__pycache__/attention.cpython-311.pyc DELETED
Binary file (5.85 kB)
 
gluformer/__pycache__/decoder.cpython-311.pyc DELETED
Binary file (3.65 kB)
 
gluformer/__pycache__/embed.cpython-311.pyc DELETED
Binary file (6.37 kB)
 
gluformer/__pycache__/encoder.cpython-311.pyc DELETED
Binary file (5.28 kB)
 
gluformer/__pycache__/variance.cpython-311.pyc DELETED
Binary file (1.89 kB)
 
gluformer/utils/__pycache__/__init__.cpython-311.pyc CHANGED
Binary files a/gluformer/utils/__pycache__/__init__.cpython-311.pyc and b/gluformer/utils/__pycache__/__init__.cpython-311.pyc differ
 
gluformer/utils/__pycache__/collate.cpython-311.pyc CHANGED
Binary files a/gluformer/utils/__pycache__/collate.cpython-311.pyc and b/gluformer/utils/__pycache__/collate.cpython-311.pyc differ
 
gluformer/utils/__pycache__/training.cpython-311.pyc CHANGED
Binary files a/gluformer/utils/__pycache__/training.cpython-311.pyc and b/gluformer/utils/__pycache__/training.cpython-311.pyc differ
 
requirements.txt CHANGED
@@ -13,4 +13,5 @@ transformers
13
  datasets
14
  python-multipart
15
  plotly
16
- kaleido
 
 
13
  datasets
14
  python-multipart
15
  plotly
16
+ kaleido
17
+ huggingface-hub
test_environment.yaml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: glucose
2
+ channels:
3
+ - conda-forge
4
+ - defaults
5
+ dependencies:
6
+ - python=3.11
7
+ - pip:
8
+ - torch
9
+ - optuna
10
+ - numpy==1.26.4
11
+ - tensorboard
12
+ - pandas
13
+ - psutil
14
+ - typer
15
+ - darts==0.29.0
16
+ - pmdarima==2.0.4
17
+ - peft
18
+ - transformers
19
+ - datasets
20
+ - python-multipart
21
+ - plotly
22
+ - kaleido
23
+ - huggingface-hub
tools.py CHANGED
@@ -15,12 +15,16 @@ from huggingface_hub import hf_hub_download
15
  import plotly.graph_objects as go
16
  import gradio as gr
17
  from format_dexcom import *
 
 
 
 
18
 
19
 
20
  glucose = Path(os.path.abspath(__file__)).parent.resolve()
21
  file_directory = glucose / "files"
22
 
23
- def plot_forecast(forecasts: np.ndarray, filename: str,ind:int=10):
24
 
25
  forecasts = (forecasts - scalers['target'].min_) / scalers['target'].scale_
26
 
@@ -134,14 +138,14 @@ scalers = None
134
  dataset_test_glufo = None
135
  filename = None
136
 
137
- def prep_predict_glucose_tool(file):
138
  """
139
  Function to predict future glucose of user.
140
  """
141
  global formatter, series, scalers, glufo, dataset_test_glufo, filename
142
 
143
  model = "Livia-Zaharia/gluformer_models"
144
- model_path = hf_hub_download(repo_id=model, filename="gluformer_1samples_10000epochs_10heads_32batch_geluactivation_livia_mini_weights.pth")
145
 
146
  formatter, series, scalers = load_data(
147
  url=str(file),
@@ -198,20 +202,23 @@ def prep_predict_glucose_tool(file):
198
  filename = generate_filename_from_url(file)
199
 
200
  max_index = len(dataset_test_glufo) - 1
 
 
201
 
202
  return (
203
  gr.Slider(
204
  minimum=0,
205
- maximum=max_index,
206
- value=10,
207
  step=1,
208
  label="Select Sample Index",
 
209
  ),
210
- gr.Markdown(f"Total number of test samples: {max_index + 1}")
211
  )
212
 
213
 
214
- def predict_glucose_tool(ind) -> go.Figure:
215
 
216
 
217
  device = "cuda" if torch.cuda.is_available() else "cpu"
 
15
  import plotly.graph_objects as go
16
  import gradio as gr
17
  from format_dexcom import *
18
+ from typing import Tuple, Union, List
19
+ from plotly.graph_objs._figure import Figure
20
+ from gradio.components import Slider
21
+ from gradio.components import Markdown
22
 
23
 
24
  glucose = Path(os.path.abspath(__file__)).parent.resolve()
25
  file_directory = glucose / "files"
26
 
27
+ def plot_forecast(forecasts: np.ndarray, filename: str,ind:int=10) -> Tuple[Path, Figure]:
28
 
29
  forecasts = (forecasts - scalers['target'].min_) / scalers['target'].scale_
30
 
 
138
  dataset_test_glufo = None
139
  filename = None
140
 
141
+ def prep_predict_glucose_tool(file: Union[str, Path], model_name: str = "gluformer_1samples_10000epochs_10heads_32batch_geluactivation_livia_mini_weights.pth") -> Tuple[Slider, Markdown]:
142
  """
143
  Function to predict future glucose of user.
144
  """
145
  global formatter, series, scalers, glufo, dataset_test_glufo, filename
146
 
147
  model = "Livia-Zaharia/gluformer_models"
148
+ model_path = hf_hub_download(repo_id=model, filename=model_name)
149
 
150
  formatter, series, scalers = load_data(
151
  url=str(file),
 
202
  filename = generate_filename_from_url(file)
203
 
204
  max_index = len(dataset_test_glufo) - 1
205
+
206
+ print(f"Total number of test samples: {max_index + 1}")
207
 
208
  return (
209
  gr.Slider(
210
  minimum=0,
211
+ maximum=max_index-1,
212
+ value=max_index,
213
  step=1,
214
  label="Select Sample Index",
215
+ visible=True
216
  ),
217
+ gr.Markdown(f"Total number of test samples: {max_index + 1}", visible=True)
218
  )
219
 
220
 
221
+ def predict_glucose_tool(ind: int) -> Figure:
222
 
223
 
224
  device = "cuda" if torch.cuda.is_available() else "cpu"
utils/__pycache__/__init__.cpython-311.pyc CHANGED
Binary files a/utils/__pycache__/__init__.cpython-311.pyc and b/utils/__pycache__/__init__.cpython-311.pyc differ
 
utils/__pycache__/darts_dataset.cpython-311.pyc CHANGED
Binary files a/utils/__pycache__/darts_dataset.cpython-311.pyc and b/utils/__pycache__/darts_dataset.cpython-311.pyc differ