SceneDiffuser commited on
Commit
e9722ce
1 Parent(s): fb3de03

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py CHANGED
@@ -4,6 +4,7 @@ import random
4
  import pickle
5
  import numpy as np
6
  import zipfile
 
7
  from PIL import Image
8
  from huggingface_hub import hf_hub_download
9
 
@@ -16,6 +17,27 @@ def pose_generation(scene, count):
16
  images = [Image.fromarray(results[scene][random.randint(0, 19)]) for i in range(count)]
17
  return images
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  def grasp_generation(case_id):
20
  assert isinstance(case_id, str)
21
  res = f"./results/grasp_generation/results/{case_id}/{random.randint(0, 19)}.glb"
@@ -60,6 +82,15 @@ with gr.Blocks() as demo:
60
  ]
61
  button1.click(pose_generation, inputs=input1, outputs=output1)
62
 
 
 
 
 
 
 
 
 
 
63
  ## motion generation
64
  with gr.Tab("Motion Generation"):
65
  gr.Markdown('Coming soon!')
 
4
  import pickle
5
  import numpy as np
6
  import zipfile
7
+ import trimesh
8
  from PIL import Image
9
  from huggingface_hub import hf_hub_download
10
 
 
17
  images = [Image.fromarray(results[scene][random.randint(0, 19)]) for i in range(count)]
18
  return images
19
 
20
+ def pose_generation_mesh(scene, count):
21
+ assert isinstance(scene, str)
22
+ scene_path = f"./results/pose_generation/mesh_results/{scene}/scene_downsample.ply"
23
+ if not os.path.exists(scene_path):
24
+ results_path = hf_hub_download('SceneDiffuser/SceneDiffuser', 'results/pose_generation/mesh_results.zip')
25
+ os.makedirs('./results/pose_generation/', exist_ok=True)
26
+ with zipfile.ZipFile(results_path, 'r') as zip_ref:
27
+ zip_ref.extractall('./results/pose_generation/')
28
+
29
+ res = './results/pose_generation/tmp.glb'
30
+ S = trimesh.Scene()
31
+ S.add_geometry(trimesh.load(scene_path))
32
+ for i in range(count):
33
+ rid = random.randint(0, 19)
34
+ S.add_geometry(trimesh.load(
35
+ f"./results/pose_generation/mesh_results/{scene}/body{rid:0>3d}.ply"
36
+ ))
37
+ S.export(res)
38
+
39
+ return res
40
+
41
  def grasp_generation(case_id):
42
  assert isinstance(case_id, str)
43
  res = f"./results/grasp_generation/results/{case_id}/{random.randint(0, 19)}.glb"
 
82
  ]
83
  button1.click(pose_generation, inputs=input1, outputs=output1)
84
 
85
+ with gr.Tab("Pose Generation Mesh"):
86
+ input11 = [
87
+ gr.Dropdown(choices=['MPH16', 'MPH1Library', 'N0SittingBooth', 'N3OpenArea'], label='Scenes'),
88
+ gr.Slider(minimum=1, maximum=4, step=1, label='Count', interactive=True)
89
+ ]
90
+ button11 = gr.Button("Generate")
91
+ output11 = gr.Model3D(clear_color=[255, 255, 255, 255], label="Result")
92
+ button11.click(pose_generation_mesh, inputs=input11, outputs=output11)
93
+
94
  ## motion generation
95
  with gr.Tab("Motion Generation"):
96
  gr.Markdown('Coming soon!')