Spaces:
Running
on
L40S
Running
on
L40S
Commit
·
3ee2e41
1
Parent(s):
ce16420
bbox sliders always present
Browse files- Dockerfile +1 -1
- app.py +34 -30
Dockerfile
CHANGED
@@ -30,6 +30,6 @@ RUN git clone https://github.com/Roblox/cube.git
|
|
30 |
|
31 |
WORKDIR /home/user/app/cube
|
32 |
RUN pip install .[meshlab]
|
33 |
-
RUN huggingface-cli download Roblox/cube3d-v0.
|
34 |
|
35 |
WORKDIR /home/user/app
|
|
|
30 |
|
31 |
WORKDIR /home/user/app/cube
|
32 |
RUN pip install .[meshlab]
|
33 |
+
RUN huggingface-cli download Roblox/cube3d-v0.5 --local-dir ./model_weights
|
34 |
|
35 |
WORKDIR /home/user/app
|
app.py
CHANGED
@@ -6,6 +6,7 @@ import torch
|
|
6 |
import trimesh
|
7 |
import sys
|
8 |
from pathlib import Path
|
|
|
9 |
|
10 |
pathdir = Path(__file__).parent / 'cube'
|
11 |
sys.path.append(pathdir.as_posix())
|
@@ -49,8 +50,8 @@ def gen_save_folder(max_size=200):
|
|
49 |
return new_folder
|
50 |
|
51 |
@spaces.GPU
|
52 |
-
def handle_text_prompt(input_prompt,
|
53 |
-
print(f"prompt: {input_prompt},
|
54 |
|
55 |
if "engine_fast" not in GLOBAL_STATE:
|
56 |
config_path = GLOBAL_STATE["config_path"]
|
@@ -66,19 +67,13 @@ def handle_text_prompt(input_prompt, bbox_option="No Bounding Box", bbox_x=1.0,
|
|
66 |
|
67 |
# Determine bounding box size based on option
|
68 |
bbox_size = None
|
69 |
-
if
|
70 |
-
bbox_size = [1.0, 1.0, 1.0]
|
71 |
-
elif bbox_option == "1x2x1":
|
72 |
-
bbox_size = [1.0, 2.0, 1.0]
|
73 |
-
elif bbox_option == "2x3x1":
|
74 |
-
bbox_size = [2.0, 3.0, 1.0]
|
75 |
-
elif bbox_option == "Custom":
|
76 |
bbox_size = [bbox_x, bbox_y, bbox_z]
|
77 |
# For "No Bounding Box", bbox_size remains None
|
78 |
|
79 |
normalized_bbox = normalize_bbox(bbox_size) if bbox_size is not None else None
|
80 |
|
81 |
-
resolution_base =
|
82 |
mesh_v_f = GLOBAL_STATE["engine_fast"].t2s([input_prompt], use_kv_cache=True, resolution_base=resolution_base, bounding_box_xyz=normalized_bbox)
|
83 |
# save output
|
84 |
vertices, faces = mesh_v_f[0][0], mesh_v_f[0][1]
|
@@ -91,9 +86,17 @@ def handle_text_prompt(input_prompt, bbox_option="No Bounding Box", bbox_x=1.0,
|
|
91 |
vertices = mesh.vertex_matrix()
|
92 |
faces = mesh.face_matrix()
|
93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
save_folder = gen_save_folder()
|
95 |
output_path = os.path.join(save_folder, "output.glb")
|
96 |
-
trimesh.Trimesh(vertices=vertices, faces=faces).export(output_path)
|
|
|
97 |
return output_path
|
98 |
|
99 |
def build_interface():
|
@@ -116,25 +119,27 @@ def build_interface():
|
|
116 |
label="Prompt",
|
117 |
lines=2,
|
118 |
)
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
)
|
124 |
-
with gr.Group(visible=False) as bbox_group:
|
125 |
-
bbox_x = gr.Slider(minimum=0.1, maximum=2.0, step=0.1, value=1.0, label="Bbox X")
|
126 |
-
bbox_y = gr.Slider(minimum=0.1, maximum=2.0, step=0.1, value=1.0, label="Bbox Y")
|
127 |
-
bbox_z = gr.Slider(minimum=0.1, maximum=2.0, step=0.1, value=1.0, label="Bbox Z")
|
128 |
|
129 |
-
# Show/hide bbox sliders based on dropdown
|
130 |
-
def toggle_bbox_visibility(bbox_option):
|
131 |
-
return gr.Group(visible=bbox_option == "Custom")
|
132 |
-
|
133 |
-
bbox_option.change(
|
134 |
-
toggle_bbox_visibility,
|
135 |
-
inputs=[bbox_option],
|
136 |
-
outputs=[bbox_group]
|
137 |
-
)
|
138 |
hi_res = gr.Checkbox(label="Hi-Res", value=False)
|
139 |
with gr.Row():
|
140 |
submit_button = gr.Button("Submit", variant="primary")
|
@@ -147,7 +152,7 @@ def build_interface():
|
|
147 |
handle_text_prompt,
|
148 |
inputs=[
|
149 |
input_text_box,
|
150 |
-
|
151 |
bbox_x,
|
152 |
bbox_y,
|
153 |
bbox_z,
|
@@ -159,7 +164,6 @@ def build_interface():
|
|
159 |
)
|
160 |
|
161 |
return interface
|
162 |
-
|
163 |
def generate(args):
|
164 |
GLOBAL_STATE["config_path"] = args.config_path
|
165 |
GLOBAL_STATE["SAVE_DIR"] = args.save_dir
|
|
|
6 |
import trimesh
|
7 |
import sys
|
8 |
from pathlib import Path
|
9 |
+
import numpy as np
|
10 |
|
11 |
pathdir = Path(__file__).parent / 'cube'
|
12 |
sys.path.append(pathdir.as_posix())
|
|
|
50 |
return new_folder
|
51 |
|
52 |
@spaces.GPU
|
53 |
+
def handle_text_prompt(input_prompt, use_bbox = True, bbox_x=1.0, bbox_y=1.0, bbox_z=1.0, hi_res=False):
|
54 |
+
print(f"prompt: {input_prompt}, use_bbox: {use_bbox}, bbox_x: {bbox_x}, bbox_y: {bbox_y}, bbox_z: {bbox_z}, hi_res: {hi_res}")
|
55 |
|
56 |
if "engine_fast" not in GLOBAL_STATE:
|
57 |
config_path = GLOBAL_STATE["config_path"]
|
|
|
67 |
|
68 |
# Determine bounding box size based on option
|
69 |
bbox_size = None
|
70 |
+
if use_bbox:
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
bbox_size = [bbox_x, bbox_y, bbox_z]
|
72 |
# For "No Bounding Box", bbox_size remains None
|
73 |
|
74 |
normalized_bbox = normalize_bbox(bbox_size) if bbox_size is not None else None
|
75 |
|
76 |
+
resolution_base = 9.0 if hi_res else 8.0
|
77 |
mesh_v_f = GLOBAL_STATE["engine_fast"].t2s([input_prompt], use_kv_cache=True, resolution_base=resolution_base, bounding_box_xyz=normalized_bbox)
|
78 |
# save output
|
79 |
vertices, faces = mesh_v_f[0][0], mesh_v_f[0][1]
|
|
|
86 |
vertices = mesh.vertex_matrix()
|
87 |
faces = mesh.face_matrix()
|
88 |
|
89 |
+
min_extents = np.min(mesh.vertex_matrix(), axis = 0)
|
90 |
+
max_extents = np.max(mesh.vertex_matrix(), axis = 0)
|
91 |
+
|
92 |
+
mesh = trimesh.Trimesh(vertices=vertices, faces=faces)
|
93 |
+
scene = trimesh.scene.Scene()
|
94 |
+
scene.add_geometry(mesh)
|
95 |
+
|
96 |
save_folder = gen_save_folder()
|
97 |
output_path = os.path.join(save_folder, "output.glb")
|
98 |
+
# trimesh.Trimesh(vertices=vertices, faces=faces).export(output_path)
|
99 |
+
scene.export(output_path)
|
100 |
return output_path
|
101 |
|
102 |
def build_interface():
|
|
|
119 |
label="Prompt",
|
120 |
lines=2,
|
121 |
)
|
122 |
+
|
123 |
+
use_bbox = gr.Checkbox(label="Use Bbox", value=False)
|
124 |
+
|
125 |
+
with gr.Group() as bbox_group:
|
126 |
+
bbox_x = gr.Slider(minimum=0.1, maximum=2.0, step=0.1, value=1.0, label="Length", interactive=False)
|
127 |
+
bbox_y = gr.Slider(minimum=0.1, maximum=2.0, step=0.1, value=1.0, label="Height", interactive=False)
|
128 |
+
bbox_z = gr.Slider(minimum=0.1, maximum=2.0, step=0.1, value=1.0, label="Depth", interactive=False)
|
129 |
+
|
130 |
+
# Enable/disable bbox sliders based on use_bbox checkbox
|
131 |
+
def toggle_bbox_interactivity(use_bbox):
|
132 |
+
return (
|
133 |
+
gr.Slider(interactive=use_bbox),
|
134 |
+
gr.Slider(interactive=use_bbox),
|
135 |
+
gr.Slider(interactive=use_bbox)
|
136 |
+
)
|
137 |
+
use_bbox.change(
|
138 |
+
toggle_bbox_interactivity,
|
139 |
+
inputs=[use_bbox],
|
140 |
+
outputs=[bbox_x, bbox_y, bbox_z]
|
141 |
)
|
|
|
|
|
|
|
|
|
142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
hi_res = gr.Checkbox(label="Hi-Res", value=False)
|
144 |
with gr.Row():
|
145 |
submit_button = gr.Button("Submit", variant="primary")
|
|
|
152 |
handle_text_prompt,
|
153 |
inputs=[
|
154 |
input_text_box,
|
155 |
+
use_bbox,
|
156 |
bbox_x,
|
157 |
bbox_y,
|
158 |
bbox_z,
|
|
|
164 |
)
|
165 |
|
166 |
return interface
|
|
|
167 |
def generate(args):
|
168 |
GLOBAL_STATE["config_path"] = args.config_path
|
169 |
GLOBAL_STATE["SAVE_DIR"] = args.save_dir
|