arcan3 commited on
Commit
e44d65b
·
1 Parent(s): de0136c

used uuid as the animation file

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -1,6 +1,7 @@
1
 
2
  import os
3
  import csv
 
4
  import json
5
  import torch
6
  import requests
@@ -18,7 +19,6 @@ from funcs.processor import process_data
18
  from funcs.plot_func import plot_sensor_data_from_json
19
  from funcs.dataloader import BaseDataset2, read_json_files
20
 
21
-
22
  DEVICE = torch.device("cpu")
23
  reducer10d = PHATEAE(epochs=30, n_components=10, lr=.0001, batch_size=128, t='auto', knn=8, relax=True, metric='euclidean')
24
  reducer10d.load('models/r10d_3.pth')
@@ -176,7 +176,6 @@ def scores_to_dataframe(scores, start_time='2022-07-01 09:15:00+05:30', start_sc
176
  return df
177
 
178
  def get_som_mp4_v2(csv_file_box, slice_size_slider, sample_rate, window_size_slider, reducer=reducer10d, cluster=cluster_som):
179
- os.remove('animation.mp4')
180
  processed_file_box, json_file_box, slices_per_leg, plot_box_leg, plot_box_overlay, slice_slider, plot_slice_leg, get_all_slice, slice_json_box, time_list = process_data(csv_file_box,
181
  slice_size_slider,
182
  sample_rate,
@@ -226,7 +225,9 @@ def get_som_mp4_v2(csv_file_box, slice_size_slider, sample_rate, window_size_sli
226
  csv_writer.writerow(header)
227
  csv_writer.writerows(processed_data)
228
 
229
- os.system('curl -X POST -F "csv_file=@animation_table.csv" https://metric-space.ngrok.io/generate --output animation.mp4')
 
 
230
  # #with hhtp requests
231
  # url = "https://metric-space.ngrok.io/generate"
232
  # file = {'csv_file': open('animation_table.csv', 'rb')}
@@ -245,7 +246,7 @@ def get_som_mp4_v2(csv_file_box, slice_size_slider, sample_rate, window_size_sli
245
 
246
  # return processed_file_box, json_file_box, slices_per_leg, plot_box_leg, plot_box_overlay, slice_slider, plot_slice_leg, get_all_slice, slice_json_box, som_video, 'animation.mp4', fig
247
 
248
- return processed_file_box, json_file_box, slices_per_leg, plot_box_leg, plot_box_overlay, slice_slider, plot_slice_leg, get_all_slice, slice_json_box, 'som_sequence.mp4', 'animation.mp4', fig
249
  return processed_file_box, json_file_box, slices_per_leg, plot_box_leg, plot_box_overlay, slice_slider, plot_slice_leg, get_all_slice, slice_json_box, 'som_sequence.mp4', None
250
 
251
  # ml inference
 
1
 
2
  import os
3
  import csv
4
+ import uuid
5
  import json
6
  import torch
7
  import requests
 
19
  from funcs.plot_func import plot_sensor_data_from_json
20
  from funcs.dataloader import BaseDataset2, read_json_files
21
 
 
22
  DEVICE = torch.device("cpu")
23
  reducer10d = PHATEAE(epochs=30, n_components=10, lr=.0001, batch_size=128, t='auto', knn=8, relax=True, metric='euclidean')
24
  reducer10d.load('models/r10d_3.pth')
 
176
  return df
177
 
178
  def get_som_mp4_v2(csv_file_box, slice_size_slider, sample_rate, window_size_slider, reducer=reducer10d, cluster=cluster_som):
 
179
  processed_file_box, json_file_box, slices_per_leg, plot_box_leg, plot_box_overlay, slice_slider, plot_slice_leg, get_all_slice, slice_json_box, time_list = process_data(csv_file_box,
180
  slice_size_slider,
181
  sample_rate,
 
225
  csv_writer.writerow(header)
226
  csv_writer.writerows(processed_data)
227
 
228
+ name_animation_file = f'animation-{str(uuid.uuid4())}.mp4'
229
+
230
+ os.system('curl -X POST -F "csv_file=@animation_table.csv" https://metric-space.ngrok.io/generate --output name_animation_file')
231
  # #with hhtp requests
232
  # url = "https://metric-space.ngrok.io/generate"
233
  # file = {'csv_file': open('animation_table.csv', 'rb')}
 
246
 
247
  # return processed_file_box, json_file_box, slices_per_leg, plot_box_leg, plot_box_overlay, slice_slider, plot_slice_leg, get_all_slice, slice_json_box, som_video, 'animation.mp4', fig
248
 
249
+ return processed_file_box, json_file_box, slices_per_leg, plot_box_leg, plot_box_overlay, slice_slider, plot_slice_leg, get_all_slice, slice_json_box, 'som_sequence.mp4', name_animation_file, fig
250
  return processed_file_box, json_file_box, slices_per_leg, plot_box_leg, plot_box_overlay, slice_slider, plot_slice_leg, get_all_slice, slice_json_box, 'som_sequence.mp4', None
251
 
252
  # ml inference