han-xudong commited on
Commit
dc15397
·
verified ·
1 Parent(s): 9a81f5f

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +5 -1
  2. requirements.txt +1 -0
app.py CHANGED
@@ -13,6 +13,7 @@ import gradio as gr
13
  import matplotlib as mpl
14
  from huggingface_hub import hf_hub_download
15
  import onnxruntime as ort
 
16
 
17
  model_dict = {
18
  "BallNet": "asRobotics/ballnet",
@@ -77,6 +78,7 @@ def make_double_sided(mesh: trimesh.Trimesh) -> trimesh.Trimesh:
77
  return mesh_double
78
 
79
 
 
80
  def predict_from_motion(dx, dy, dz, rx, ry, rz, model_name):
81
  motion = np.array(
82
  [dx, dy, dz, rx / 180.0 * np.pi, ry / 180.0 * np.pi, rz / 180.0 * np.pi],
@@ -92,7 +94,8 @@ def predict_from_motion(dx, dy, dz, rx, ry, rz, model_name):
92
  force.reshape(1, -1),
93
  columns=["Fx (N)", "Fy (N)", "Fz (N)", "Tx (Nmm)", "Ty (Nmm)", "Tz (Nmm)"],
94
  )
95
- df = df.style.format("{:.3f}")
 
96
 
97
  delta_vertices = np.zeros_like(vertices_dict[model_name])
98
  delta_vertices[def_index_dict[model_name] - 1] += nodes.reshape(-1, 3)
@@ -120,6 +123,7 @@ def predict_from_motion(dx, dy, dz, rx, ry, rz, model_name):
120
 
121
  tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".glb")
122
  mesh.export(tmp_file.name, file_type="glb")
 
123
 
124
  return df, tmp_file.name
125
 
 
13
  import matplotlib as mpl
14
  from huggingface_hub import hf_hub_download
15
  import onnxruntime as ort
16
+ import spaces
17
 
18
  model_dict = {
19
  "BallNet": "asRobotics/ballnet",
 
78
  return mesh_double
79
 
80
 
81
+ @spaces.GPU
82
  def predict_from_motion(dx, dy, dz, rx, ry, rz, model_name):
83
  motion = np.array(
84
  [dx, dy, dz, rx / 180.0 * np.pi, ry / 180.0 * np.pi, rz / 180.0 * np.pi],
 
94
  force.reshape(1, -1),
95
  columns=["Fx (N)", "Fy (N)", "Fz (N)", "Tx (Nmm)", "Ty (Nmm)", "Tz (Nmm)"],
96
  )
97
+ # Round to 3 decimal places for display (avoids pickle error with style objects)
98
+ df = df.round(3)
99
 
100
  delta_vertices = np.zeros_like(vertices_dict[model_name])
101
  delta_vertices[def_index_dict[model_name] - 1] += nodes.reshape(-1, 3)
 
123
 
124
  tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".glb")
125
  mesh.export(tmp_file.name, file_type="glb")
126
+ tmp_file.close()
127
 
128
  return df, tmp_file.name
129
 
requirements.txt CHANGED
@@ -6,3 +6,4 @@ pandas
6
  matplotlib
7
  trimesh
8
  scipy
 
 
6
  matplotlib
7
  trimesh
8
  scipy
9
+ spaces