edward2021 commited on
Commit
ce1fcfd
1 Parent(s): 2becbfc
Files changed (1) hide show
  1. app.py +67 -0
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+
4
+ from torch import is_inference
5
+ from pq3d.inference import inference
6
+
7
+ MESH_DIR = 'assets/mesh'
8
+ MESH_NAMES = sorted([os.path.splitext(fname)[0] for fname in os.listdir(MESH_DIR)])
9
+
10
+ def change_scene(dropdown_scene: str):
11
+ # reset 3D scene and chatbot history
12
+ return os.path.join(MESH_DIR, f'{dropdown_scene}.glb')
13
+
14
+ with gr.Blocks(title='PQ3D Demo') as demo:
15
+ gr.HTML(value="<h1 align='center'>Unifying 3D Vision Language Understanding vis Promptable Queries </h1>")
16
+ #gr.HTML(value="<div align='center' style='margin-top:-1em; margin-bottom:-1em;'><img src='/file=assets/leo.svg' width='4%'></div>")
17
+ # gr.HTML(value="<img src='/file=assets/teaser.png' alt='Teaser' width='760px' style='display: block; margin: auto;'>")
18
+ #gr.HTML(value="<p align='center' style='font-size: 1.2em; color: #485fc7;'><a href='https://arxiv.org/abs/2311.12871' target='_blank'>arXiv</a> | <a href='https://embodied-generalist.github.io/' target='_blank'>Project Page</a> | <a href='https://github.com/embodied-generalist/embodied-generalist' target='_blank'>Code</a></p>")
19
+ #gr.HTML(value="<p align='center' style='font-size: 1.15em;'><i>LEO: an embodied generalist agent capable of perceiving, grounding, reasoning, planning, and acting in 3D world.</i></p>")
20
+
21
+ with gr.Row():
22
+ with gr.Column(scale=5):
23
+ dropdown_scene = gr.Dropdown(
24
+ choices=MESH_NAMES,
25
+ value='scene0050_00',
26
+ interactive=True,
27
+ label='Select a 3D scene',
28
+ )
29
+ model_3d = gr.Model3D(
30
+ value=os.path.join(MESH_DIR, f'scene0050_00.glb'),
31
+ clear_color=[0.0, 0.0, 0.0, 0.0],
32
+ label='3D Scene',
33
+ camera_position=(80, 100, 6),
34
+ height=659,
35
+ )
36
+ gr.HTML(
37
+ """<center><strong>
38
+ 👆 SCROLL and DRAG on the 3D Scene
39
+ to zoom in/out and rotate. Press CTRL and DRAG to pan.
40
+ </strong></center>
41
+ """
42
+ )
43
+
44
+ dropdown_scene.change(
45
+ fn=change_scene,
46
+ inputs=[dropdown_scene],
47
+ outputs=[model_3d],
48
+ queue=False
49
+ )
50
+
51
+ def inference_wrapper(text):
52
+ scan_id = model_3d.value['orig_name'].split('.')[0]
53
+ inst_id = inference(scan_id, text)
54
+ return f"assets/mask/{scan_id}/{scan_id}_obj_{inst_id}.glb"
55
+
56
+ gr.Interface(
57
+ fn=inference_wrapper,
58
+ inputs=["text"],
59
+ outputs=gr.Model3D(
60
+ clear_color=[0.0, 0.0, 0.0, 0.0], camera_position=(80, 100, 6), label="3D Model"),
61
+ examples=[
62
+ ["armchair"], ["Sofa"], ["left computer on the desk"]
63
+ ],
64
+ title="Input text, Output 3D Mask, Red denotes predicted object"
65
+ )
66
+
67
+ demo.queue().launch(share=True, allowed_paths=['assets'])