arcan3 commited on
Commit
bafccae
·
1 Parent(s): e78e5ad

new release

Browse files
Files changed (3) hide show
  1. app.py +14 -3
  2. funcs/processor.py +2 -2
  3. funcs/som.py +5 -1
app.py CHANGED
@@ -3,6 +3,8 @@ import os
3
  import csv
4
  import json
5
  import torch
 
 
6
  import numpy as np
7
  import pandas as pd
8
  import gradio as gr
@@ -21,10 +23,10 @@ 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_6.pth')
25
 
26
  cluster_som = ClusterSOM()
27
- cluster_som.load("models/cluster_som6.pkl")
28
 
29
  def score(self, data, midpoints=None, threshold_radius=4):
30
  """
@@ -223,7 +225,16 @@ def get_som_mp4_v2(csv_file_box, slice_size_slider, sample_rate, window_size_sli
223
  csv_writer.writerow(header)
224
  csv_writer.writerows(processed_data)
225
 
226
- os.system('curl -X POST -F "csv_file=@animation_table.csv" https://metric-space.ngrok.io/generate --output animation.mp4')
 
 
 
 
 
 
 
 
 
227
 
228
  # prediction = cluster_som.predict(embedding10d)
229
  som_video = cluster.plot_activation(embedding10d)
 
3
  import csv
4
  import json
5
  import torch
6
+ import requests
7
+
8
  import numpy as np
9
  import pandas as pd
10
  import gradio as gr
 
23
 
24
  DEVICE = torch.device("cpu")
25
  reducer10d = PHATEAE(epochs=30, n_components=10, lr=.0001, batch_size=128, t='auto', knn=8, relax=True, metric='euclidean')
26
+ reducer10d.load('models/r10d_3.pth')
27
 
28
  cluster_som = ClusterSOM()
29
+ cluster_som.load("models/cluster_som3.pkl")
30
 
31
  def score(self, data, midpoints=None, threshold_radius=4):
32
  """
 
225
  csv_writer.writerow(header)
226
  csv_writer.writerows(processed_data)
227
 
228
+ # os.system('curl -X POST -F "csv_file=@animation_table.csv" https://metric-space.ngrok.io/generate --output animation.mp4')
229
+ #with hhtp requests
230
+ url = "https://metric-space.ngrok.io/generate"
231
+ file = {'csv_file': open('animation_table.csv', 'rb')}
232
+ response = requests.post(url, files=file)
233
+
234
+ # The response will contain the binary data of the MP4 file.
235
+ # You can write it to a file like this:
236
+ with open('animation.mp4', 'wb') as f:
237
+ f.write(response.content)
238
 
239
  # prediction = cluster_som.predict(embedding10d)
240
  som_video = cluster.plot_activation(embedding10d)
funcs/processor.py CHANGED
@@ -74,8 +74,8 @@ def process_data(input_file, slice_size=64, min_slice_size=10, sample_rate=20, w
74
  # Save the resulting DataFrame to a new file
75
  data.to_csv('output.csv', sep=";", na_rep="NaN", float_format="%.0f")
76
 
77
- # file, len_ = slice_csv_to_json('output.csv', slice_size, min_slice_size, sample_rate, window_size=window_size)
78
- file, len_ = slice_csv_to_json_v2('output.csv', slice_size, min_slice_size, sample_rate)
79
  # get the plot automatically
80
  sensor_fig, slice_fig, get_all_slice, slice_json, overlay_fig = plot_sensor_data_from_json(file, "GZ1")
81
  # overlay_fig = plot_overlay_data_from_json(file, ["GZ1", "GZ2", "GZ3", "GZ4"])
 
74
  # Save the resulting DataFrame to a new file
75
  data.to_csv('output.csv', sep=";", na_rep="NaN", float_format="%.0f")
76
 
77
+ file, len_ = slice_csv_to_json('output.csv', slice_size, min_slice_size, sample_rate, window_size=window_size)
78
+ # file, len_ = slice_csv_to_json_v2('output.csv', slice_size, min_slice_size, sample_rate)
79
  # get the plot automatically
80
  sensor_fig, slice_fig, get_all_slice, slice_json, overlay_fig = plot_sensor_data_from_json(file, "GZ1")
81
  # overlay_fig = plot_overlay_data_from_json(file, ["GZ1", "GZ2", "GZ3", "GZ4"])
funcs/som.py CHANGED
@@ -185,8 +185,12 @@ class ClusterSOM:
185
  images.append(img)
186
  plt.close()
187
 
 
 
 
 
188
  # Create the video using moviepy and save it as a mp4 file
189
- video = ImageSequenceClip(images, fps=1)
190
 
191
  return video
192
 
 
185
  images.append(img)
186
  plt.close()
187
 
188
+ # Set default frame duration if `times` is not provided.
189
+ if times is None:
190
+ times = [500 for _ in range(len(images))]
191
+
192
  # Create the video using moviepy and save it as a mp4 file
193
+ video = ImageSequenceClip(images, fps=30)
194
 
195
  return video
196