Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ import torch
|
|
7 |
import rembg
|
8 |
from datetime import datetime
|
9 |
import subprocess
|
10 |
-
import
|
11 |
|
12 |
try:
|
13 |
# running on Hugging Face Spaces
|
@@ -137,83 +137,32 @@ def process_3d(input_image, num_steps=50, cfg_scale=7, grid_res=384, seed=42, si
|
|
137 |
# export the whole mesh
|
138 |
mesh.export(output_glb_path)
|
139 |
|
|
|
140 |
return output_glb_path
|
141 |
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
seg_image = gr.Image(label="Segmentation Result", type="numpy", interactive=False, image_mode="RGBA")
|
169 |
-
with gr.Accordion("Settings", open=True):
|
170 |
-
# inference steps
|
171 |
-
num_steps = gr.Slider(label="Inference steps", minimum=1, maximum=100, step=1, value=50)
|
172 |
-
# cfg scale
|
173 |
-
cfg_scale = gr.Slider(label="CFG scale", minimum=2, maximum=10, step=0.1, value=7.0)
|
174 |
-
# grid resolution
|
175 |
-
input_grid_res = gr.Slider(label="Grid resolution", minimum=256, maximum=512, step=1, value=384)
|
176 |
-
# random seed
|
177 |
-
with gr.Row():
|
178 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
179 |
-
seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0)
|
180 |
-
# simplify mesh
|
181 |
-
with gr.Row():
|
182 |
-
simplify_mesh = gr.Checkbox(label="Simplify mesh", value=False)
|
183 |
-
target_num_faces = gr.Slider(label="Face number", minimum=10000, maximum=1000000, step=1000, value=100000)
|
184 |
-
# gen button
|
185 |
-
button_gen = gr.Button("Generate")
|
186 |
-
|
187 |
-
with gr.Column(scale=1):
|
188 |
-
# glb file
|
189 |
-
output_model = gr.Model3D(label="Geometry", height=512)
|
190 |
-
|
191 |
-
|
192 |
-
with gr.Row():
|
193 |
-
gr.Examples(
|
194 |
-
examples=[
|
195 |
-
["examples/rabbit.png"],
|
196 |
-
["examples/robot.png"],
|
197 |
-
["examples/teapot.png"],
|
198 |
-
["examples/barrel.png"],
|
199 |
-
["examples/cactus.png"],
|
200 |
-
["examples/cyan_car.png"],
|
201 |
-
["examples/pickup.png"],
|
202 |
-
["examples/swivelchair.png"],
|
203 |
-
["examples/warhammer.png"],
|
204 |
-
],
|
205 |
-
fn=process_image, # still need to click button_gen to get the 3d
|
206 |
-
inputs=[input_image],
|
207 |
-
outputs=[seg_image],
|
208 |
-
cache_examples=False,
|
209 |
-
)
|
210 |
-
|
211 |
-
button_gen.click(
|
212 |
-
process_image, inputs=[input_image], outputs=[seg_image]
|
213 |
-
).then(
|
214 |
-
get_random_seed, inputs=[randomize_seed, seed], outputs=[seed]
|
215 |
-
).then(
|
216 |
-
process_3d, inputs=[seg_image, num_steps, cfg_scale, input_grid_res, seed, simplify_mesh, target_num_faces], outputs=[output_model]
|
217 |
-
)
|
218 |
-
|
219 |
-
block.launch(ssr_mode=False)
|
|
|
7 |
import rembg
|
8 |
from datetime import datetime
|
9 |
import subprocess
|
10 |
+
import argparse
|
11 |
|
12 |
try:
|
13 |
# running on Hugging Face Spaces
|
|
|
137 |
# export the whole mesh
|
138 |
mesh.export(output_glb_path)
|
139 |
|
140 |
+
print(f"Saved 3D model to {output_glb_path}")
|
141 |
return output_glb_path
|
142 |
|
143 |
+
if __name__ == '__main__':
|
144 |
+
parser = argparse.ArgumentParser()
|
145 |
+
parser.add_argument('--image_path', type=str, default='examples/robot.png', help='Path to input image')
|
146 |
+
parser.add_argument('--num_steps', type=int, default=50, help='Inference steps')
|
147 |
+
parser.add_argument('--cfg_scale', type=float, default=7.0, help='CFG scale')
|
148 |
+
parser.add_argument('--grid_res', type=int, default=384, help='Grid resolution')
|
149 |
+
parser.add_argument('--seed', type=int, default=42, help='Random seed')
|
150 |
+
parser.add_argument('--randomize_seed', action='store_true', help='Randomize seed')
|
151 |
+
parser.add_argument('--simplify_mesh', action='store_true', help='Simplify mesh')
|
152 |
+
parser.add_argument('--target_num_faces', type=int, default=100000, help='Target number of faces for mesh simplification')
|
153 |
+
|
154 |
+
args = parser.parse_args()
|
155 |
+
|
156 |
+
if args.randomize_seed:
|
157 |
+
args.seed = get_random_seed(args.randomize_seed, args.seed)
|
158 |
+
|
159 |
+
processed_image = process_image(args.image_path)
|
160 |
+
process_3d(
|
161 |
+
input_image=processed_image,
|
162 |
+
num_steps=args.num_steps,
|
163 |
+
cfg_scale=args.cfg_scale,
|
164 |
+
grid_res=args.grid_res,
|
165 |
+
seed=args.seed,
|
166 |
+
simplify_mesh=args.simplify_mesh,
|
167 |
+
target_num_faces=args.target_num_faces
|
168 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|