Spaces:
Running
on
L4
Running
on
L4
FrozenBurning
commited on
Commit
•
1936a56
1
Parent(s):
0ad853d
Update app.py
Browse files
app.py
CHANGED
@@ -141,7 +141,7 @@ def process(input_cond, input_num_steps, input_seed=42, input_cfg=6.0):
|
|
141 |
prim_params = {'srt_param': recon_srt_param[0].detach().cpu(), 'feat_param': recon_feat_param[0].detach().cpu()}
|
142 |
return output_rgb_video_path, output_prim_video_path, output_mat_video_path, prim_params
|
143 |
|
144 |
-
def export_mesh(prim_params, uv_unwrap="Faster", remesh="No", mc_resolution=256
|
145 |
# exporting GLB mesh
|
146 |
output_glb_path = os.path.join(config.output_dir, GRADIO_GLB_PATH)
|
147 |
if remesh == "No":
|
@@ -152,7 +152,6 @@ def export_mesh(prim_params, uv_unwrap="Faster", remesh="No", mc_resolution=256,
|
|
152 |
config.inference.fast_unwrap = True
|
153 |
elif uv_unwrap == "Better":
|
154 |
config.inference.fast_unwrap = False
|
155 |
-
config.inference.decimate = decimate
|
156 |
config.inference.mc_resolution = mc_resolution
|
157 |
config.inference.batch_size = 8192
|
158 |
model_primx.load_state_dict(prim_params)
|
@@ -161,7 +160,7 @@ def export_mesh(prim_params, uv_unwrap="Faster", remesh="No", mc_resolution=256,
|
|
161 |
with torch.no_grad():
|
162 |
model_primx.srt_param[:, 1:4] *= 0.85
|
163 |
extract_texmesh(config.inference, model_primx, config.output_dir, device)
|
164 |
-
return output_glb_path, gr.update(visible=True)
|
165 |
|
166 |
# gradio UI
|
167 |
_TITLE = '''3DTopia-XL'''
|
@@ -192,18 +191,21 @@ with block:
|
|
192 |
input_image = gr.Image(label="image", type='pil')
|
193 |
# background removal
|
194 |
removal_previewer = gr.Image(label="Background Removal Preview", type='pil', interactive=False)
|
195 |
-
# inference steps
|
196 |
-
input_num_steps = gr.Radio(choices=[25, 50, 100, 200], label="DDIM steps. Larger for robustness but slower.", value=25)
|
197 |
-
# random seed
|
198 |
-
input_cfg = gr.Slider(label="CFG scale", minimum=0, maximum=15, step=0.5, value=6, info="Typically CFG in a range of 4-7")
|
199 |
-
# random seed
|
200 |
-
input_seed = gr.Slider(label="random seed", minimum=0, maximum=10000, step=1, value=42, info="Try different seed if the result is not satisfying as this is a generative model!")
|
201 |
with gr.Row():
|
202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
input_remesh = gr.Radio(choices=["No", "Yes"], label="Remesh", value="No", info="Remesh or not?")
|
204 |
-
input_unwrap = gr.Radio(choices=["Faster", "Better"], label="UV", value="
|
205 |
# gen button
|
206 |
-
|
|
|
|
|
207 |
|
208 |
with gr.Column(scale=1):
|
209 |
with gr.Row():
|
@@ -248,7 +250,8 @@ with block:
|
|
248 |
|
249 |
input_image.change(background_remove_process, inputs=[input_image], outputs=[button_gen, current_fg_state, removal_previewer])
|
250 |
button_gen.click(process, inputs=[current_fg_state, input_num_steps, input_seed, input_cfg], outputs=[output_rgb_video, output_prim_video, output_mat_video, prim_param_state])
|
251 |
-
prim_param_state.change(export_mesh, inputs=[prim_param_state, input_unwrap, input_remesh, input_mc_resolution], outputs=[output_glb, hdr_row])
|
|
|
252 |
|
253 |
gr.Examples(
|
254 |
examples=[
|
|
|
141 |
prim_params = {'srt_param': recon_srt_param[0].detach().cpu(), 'feat_param': recon_feat_param[0].detach().cpu()}
|
142 |
return output_rgb_video_path, output_prim_video_path, output_mat_video_path, prim_params
|
143 |
|
144 |
+
def export_mesh(prim_params, uv_unwrap="Faster", remesh="No", mc_resolution=256):
|
145 |
# exporting GLB mesh
|
146 |
output_glb_path = os.path.join(config.output_dir, GRADIO_GLB_PATH)
|
147 |
if remesh == "No":
|
|
|
152 |
config.inference.fast_unwrap = True
|
153 |
elif uv_unwrap == "Better":
|
154 |
config.inference.fast_unwrap = False
|
|
|
155 |
config.inference.mc_resolution = mc_resolution
|
156 |
config.inference.batch_size = 8192
|
157 |
model_primx.load_state_dict(prim_params)
|
|
|
160 |
with torch.no_grad():
|
161 |
model_primx.srt_param[:, 1:4] *= 0.85
|
162 |
extract_texmesh(config.inference, model_primx, config.output_dir, device)
|
163 |
+
return output_glb_path, gr.update(visible=True), gr.update(interactive=True), gr.update(value="assets/hdri/metro_noord_1k.hdr")
|
164 |
|
165 |
# gradio UI
|
166 |
_TITLE = '''3DTopia-XL'''
|
|
|
191 |
input_image = gr.Image(label="image", type='pil')
|
192 |
# background removal
|
193 |
removal_previewer = gr.Image(label="Background Removal Preview", type='pil', interactive=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
with gr.Row():
|
195 |
+
# inference steps
|
196 |
+
input_num_steps = gr.Radio(choices=[25, 50, 100, 200], label="DDIM steps", value=25, info="Larger for robustness but slower.")
|
197 |
+
# random seed
|
198 |
+
input_cfg = gr.Slider(label="CFG scale", minimum=0, maximum=15, step=0.5, value=6, info="Typically CFG in a range of 4-7")
|
199 |
+
# random seed
|
200 |
+
input_seed = gr.Slider(label="random seed", minimum=0, maximum=10000, step=1, value=42, info="Try different seed if the result is not satisfying as this is a generative model!")
|
201 |
+
with gr.Row():
|
202 |
+
input_mc_resolution = gr.Radio(choices=[128, 256], label="MC Resolution", value=128, info="Cube resolution for mesh extraction. Larger for better quality but slower.")
|
203 |
input_remesh = gr.Radio(choices=["No", "Yes"], label="Remesh", value="No", info="Remesh or not?")
|
204 |
+
input_unwrap = gr.Radio(choices=["Faster", "Better"], label="UV Unwrap", value="Better", info="UV unwrapping algorithm. Trade-off between quality and speed.")
|
205 |
# gen button
|
206 |
+
with gr.Row():
|
207 |
+
button_gen = gr.Button(value="Generate", interactive=False)
|
208 |
+
export_glb_btn = gr.Button(value="Export Current GLB", interactive=False)
|
209 |
|
210 |
with gr.Column(scale=1):
|
211 |
with gr.Row():
|
|
|
250 |
|
251 |
input_image.change(background_remove_process, inputs=[input_image], outputs=[button_gen, current_fg_state, removal_previewer])
|
252 |
button_gen.click(process, inputs=[current_fg_state, input_num_steps, input_seed, input_cfg], outputs=[output_rgb_video, output_prim_video, output_mat_video, prim_param_state])
|
253 |
+
prim_param_state.change(export_mesh, inputs=[prim_param_state, input_unwrap, input_remesh, input_mc_resolution], outputs=[output_glb, hdr_row, export_glb_btn, hdr_illumination_file])
|
254 |
+
export_glb_btn.click(export_mesh, inputs=[prim_param_state, input_unwrap, input_remesh, input_mc_resolution], outputs=[output_glb, hdr_row, export_glb_btn, hdr_illumination_file])
|
255 |
|
256 |
gr.Examples(
|
257 |
examples=[
|