Spaces:
Running
on
T4
Running
on
T4
Upload gradio_app.py
Browse files- gradio_app.py +71 -34
gradio_app.py
CHANGED
@@ -347,11 +347,11 @@ def build_app():
|
|
347 |
with gr.Row():
|
348 |
with gr.Column(scale=3):
|
349 |
with gr.Tabs(selected='tab_mv'):
|
350 |
-
with gr.Tab(
|
351 |
with gr.Row():
|
352 |
-
mv_image_front = gr.Image(label='
|
353 |
min_width=100, elem_classes='mv-image')
|
354 |
-
mv_image_back = gr.Image(label='
|
355 |
min_width=100, elem_classes='mv-image')
|
356 |
with gr.Row():
|
357 |
mv_image_left = gr.Image(label='Izquierda', type='pil', image_mode='RGBA', height=140,
|
@@ -360,22 +360,24 @@ def build_app():
|
|
360 |
min_width=100, elem_classes='mv-image')
|
361 |
|
362 |
with gr.Row():
|
363 |
-
btn = gr.Button(value='Generar
|
|
|
|
|
|
|
|
|
364 |
|
365 |
with gr.Group():
|
366 |
file_out = gr.File(label="File", visible=False)
|
367 |
file_out2 = gr.File(label="File", visible=False)
|
368 |
|
369 |
with gr.Tabs(selected='tab_options' if TURBO_MODE else 'tab_export'):
|
370 |
-
with gr.Tab("
|
371 |
-
gen_mode = gr.Radio(label='
|
372 |
-
info='Recommendation: Turbo for most cases, Fast for very complex cases, Standard seldom use.',
|
373 |
choices=['Turbo', 'Fast', 'Standard'], value='Turbo')
|
374 |
-
decode_mode = gr.Radio(label='
|
375 |
-
info='The resolution for exporting mesh from generated vectset',
|
376 |
choices=['Low', 'Standard', 'High'],
|
377 |
value='Standard')
|
378 |
-
with gr.Tab('Advanced Options', id='tab_advanced_options'):
|
379 |
with gr.Row():
|
380 |
check_box_rembg = gr.Checkbox(value=True, label='Remove Background', min_width=100)
|
381 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True, min_width=100)
|
@@ -397,28 +399,28 @@ def build_app():
|
|
397 |
cfg_scale = gr.Number(value=5.0, label='Guidance Scale', min_width=100)
|
398 |
num_chunks = gr.Slider(maximum=5000000, minimum=1000, value=8000,
|
399 |
label='Number of Chunks', min_width=100)
|
400 |
-
with gr.Tab("
|
401 |
with gr.Row():
|
402 |
-
file_type = gr.Dropdown(label='
|
403 |
value='glb', min_width=100)
|
404 |
-
reduce_face = gr.Checkbox(label='
|
405 |
export_texture = gr.Checkbox(label='Include Texture', value=False,
|
406 |
visible=False, min_width=100)
|
407 |
target_face_num = gr.Slider(maximum=1000000, minimum=100, value=10000,
|
408 |
-
label='
|
409 |
with gr.Row():
|
410 |
-
confirm_export = gr.Button(value="
|
411 |
-
file_export = gr.DownloadButton(label="
|
412 |
interactive=False, min_width=100)
|
413 |
|
414 |
with gr.Column(scale=9):
|
415 |
with gr.Tabs(selected='gen_mesh_panel') as tabs_output:
|
416 |
with gr.Tab('Modelo Generado', id='gen_mesh_panel'):
|
417 |
html_gen_mesh = gr.HTML(HTML_OUTPUT_PLACEHOLDER, label='Output')
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
|
423 |
btn.click(
|
424 |
shape_generation,
|
@@ -445,6 +447,31 @@ def build_app():
|
|
445 |
outputs=[tabs_output],
|
446 |
)
|
447 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
448 |
def on_gen_mode_change(value):
|
449 |
if value == 'Turbo':
|
450 |
return gr.update(value=5)
|
@@ -471,20 +498,30 @@ def build_app():
|
|
471 |
|
472 |
print(f'exporting {file_out}')
|
473 |
print(f'reduce face to {target_face_num}')
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
488 |
print(f'export to {path}')
|
489 |
return model_viewer_html, gr.update(value=path, interactive=True)
|
490 |
|
|
|
347 |
with gr.Row():
|
348 |
with gr.Column(scale=3):
|
349 |
with gr.Tabs(selected='tab_mv'):
|
350 |
+
with gr.Tab('Im谩genes', id='tab_mv'):
|
351 |
with gr.Row():
|
352 |
+
mv_image_front = gr.Image(label='Frente', type='pil', image_mode='RGBA', height=140,
|
353 |
min_width=100, elem_classes='mv-image')
|
354 |
+
mv_image_back = gr.Image(label='Atr谩s', type='pil', image_mode='RGBA', height=140,
|
355 |
min_width=100, elem_classes='mv-image')
|
356 |
with gr.Row():
|
357 |
mv_image_left = gr.Image(label='Izquierda', type='pil', image_mode='RGBA', height=140,
|
|
|
360 |
min_width=100, elem_classes='mv-image')
|
361 |
|
362 |
with gr.Row():
|
363 |
+
btn = gr.Button(value='Generar modelo', variant='primary', min_width=100)
|
364 |
+
btn_all = gr.Button(value='Gen Textured Shape',
|
365 |
+
variant='primary',
|
366 |
+
visible=False,
|
367 |
+
min_width=100)
|
368 |
|
369 |
with gr.Group():
|
370 |
file_out = gr.File(label="File", visible=False)
|
371 |
file_out2 = gr.File(label="File", visible=False)
|
372 |
|
373 |
with gr.Tabs(selected='tab_options' if TURBO_MODE else 'tab_export'):
|
374 |
+
with gr.Tab("Opciones", id='tab_options', visible=TURBO_MODE):
|
375 |
+
gen_mode = gr.Radio(label='Modo de Generaci贸n',
|
|
|
376 |
choices=['Turbo', 'Fast', 'Standard'], value='Turbo')
|
377 |
+
decode_mode = gr.Radio(label='Mode de decripci贸n',
|
|
|
378 |
choices=['Low', 'Standard', 'High'],
|
379 |
value='Standard')
|
380 |
+
with gr.Tab('Advanced Options', id='tab_advanced_options', visible=False):
|
381 |
with gr.Row():
|
382 |
check_box_rembg = gr.Checkbox(value=True, label='Remove Background', min_width=100)
|
383 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True, min_width=100)
|
|
|
399 |
cfg_scale = gr.Number(value=5.0, label='Guidance Scale', min_width=100)
|
400 |
num_chunks = gr.Slider(maximum=5000000, minimum=1000, value=8000,
|
401 |
label='Number of Chunks', min_width=100)
|
402 |
+
with gr.Tab("Exportar", id='tab_export'):
|
403 |
with gr.Row():
|
404 |
+
file_type = gr.Dropdown(label='Archivo', choices=SUPPORTED_FORMATS,
|
405 |
value='glb', min_width=100)
|
406 |
+
reduce_face = gr.Checkbox(label='Modelo Simpl.', value=False, min_width=100)
|
407 |
export_texture = gr.Checkbox(label='Include Texture', value=False,
|
408 |
visible=False, min_width=100)
|
409 |
target_face_num = gr.Slider(maximum=1000000, minimum=100, value=10000,
|
410 |
+
label='Numero de frentes objetivo')
|
411 |
with gr.Row():
|
412 |
+
confirm_export = gr.Button(value="Transformar", min_width=100)
|
413 |
+
file_export = gr.DownloadButton(label="Descargar", variant='primary',
|
414 |
interactive=False, min_width=100)
|
415 |
|
416 |
with gr.Column(scale=9):
|
417 |
with gr.Tabs(selected='gen_mesh_panel') as tabs_output:
|
418 |
with gr.Tab('Modelo Generado', id='gen_mesh_panel'):
|
419 |
html_gen_mesh = gr.HTML(HTML_OUTPUT_PLACEHOLDER, label='Output')
|
420 |
+
with gr.Tab('Exporting Mesh', id='export_mesh_panel', visible=False):
|
421 |
+
html_export_mesh = gr.HTML(HTML_OUTPUT_PLACEHOLDER, label='Output', visible=False)
|
422 |
+
with gr.Tab('Mesh Statistic', id='stats_panel'):
|
423 |
+
stats = gr.Json({}, label='Mesh Stats')
|
424 |
|
425 |
btn.click(
|
426 |
shape_generation,
|
|
|
447 |
outputs=[tabs_output],
|
448 |
)
|
449 |
|
450 |
+
btn_all.click(
|
451 |
+
generation_all,
|
452 |
+
inputs=[
|
453 |
+
mv_image_front,
|
454 |
+
mv_image_back,
|
455 |
+
mv_image_left,
|
456 |
+
mv_image_right,
|
457 |
+
num_steps,
|
458 |
+
cfg_scale,
|
459 |
+
seed,
|
460 |
+
octree_resolution,
|
461 |
+
check_box_rembg,
|
462 |
+
num_chunks,
|
463 |
+
randomize_seed,
|
464 |
+
],
|
465 |
+
outputs=[file_out, file_out2, html_gen_mesh, stats, seed]
|
466 |
+
).then(
|
467 |
+
lambda: (gr.update(visible=True, value=True), gr.update(interactive=False), gr.update(interactive=True),
|
468 |
+
gr.update(interactive=False)),
|
469 |
+
outputs=[export_texture, reduce_face, confirm_export, file_export],
|
470 |
+
).then(
|
471 |
+
lambda: gr.update(selected='gen_mesh_panel'),
|
472 |
+
outputs=[tabs_output],
|
473 |
+
)
|
474 |
+
|
475 |
def on_gen_mode_change(value):
|
476 |
if value == 'Turbo':
|
477 |
return gr.update(value=5)
|
|
|
498 |
|
499 |
print(f'exporting {file_out}')
|
500 |
print(f'reduce face to {target_face_num}')
|
501 |
+
if export_texture:
|
502 |
+
mesh = trimesh.load(file_out2)
|
503 |
+
save_folder = gen_save_folder()
|
504 |
+
path = export_mesh(mesh, save_folder, textured=True, type=file_type)
|
505 |
+
|
506 |
+
# for preview
|
507 |
+
save_folder = gen_save_folder()
|
508 |
+
_ = export_mesh(mesh, save_folder, textured=True)
|
509 |
+
model_viewer_html = build_model_viewer_html(save_folder, height=HTML_HEIGHT, width=HTML_WIDTH,
|
510 |
+
textured=True)
|
511 |
+
else:
|
512 |
+
mesh = trimesh.load(file_out)
|
513 |
+
mesh = floater_remove_worker(mesh)
|
514 |
+
mesh = degenerate_face_remove_worker(mesh)
|
515 |
+
if reduce_face:
|
516 |
+
mesh = face_reduce_worker(mesh, target_face_num)
|
517 |
+
save_folder = gen_save_folder()
|
518 |
+
path = export_mesh(mesh, save_folder, textured=False, type=file_type)
|
519 |
+
|
520 |
+
# for preview
|
521 |
+
save_folder = gen_save_folder()
|
522 |
+
_ = export_mesh(mesh, save_folder, textured=False)
|
523 |
+
model_viewer_html = build_model_viewer_html(save_folder, height=HTML_HEIGHT, width=HTML_WIDTH,
|
524 |
+
textured=False)
|
525 |
print(f'export to {path}')
|
526 |
return model_viewer_html, gr.update(value=path, interactive=True)
|
527 |
|