Spaces:
Runtime error
Runtime error
Update gradio_app.py
Browse files- gradio_app.py +102 -97
gradio_app.py
CHANGED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
-
#
|
| 2 |
# except for the third-party components listed below.
|
| 3 |
-
#
|
| 4 |
-
# in the
|
| 5 |
# Users must comply with all terms and conditions of original licenses of these third-party
|
| 6 |
# components and must ensure that the usage of the third party components adheres to
|
| 7 |
# all relevant laws and regulations.
|
| 8 |
|
| 9 |
-
# For avoidance of doubts,
|
| 10 |
# their software and algorithms, including trained model weights, parameters (including
|
| 11 |
# optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
|
| 12 |
# fine-tuning enabling code and other elements of the foregoing made publicly available
|
|
@@ -133,12 +133,12 @@ def build_model_viewer_html(save_folder, height=660, width=790, textured=False):
|
|
| 133 |
f.write(template_html)
|
| 134 |
|
| 135 |
rel_path = os.path.relpath(output_html_path, SAVE_DIR)
|
| 136 |
-
iframe_tag = f'<iframe src="/static/{rel_path}" height="{height}" width="100%" frameborder="0" style="border-radius: 8px; box-shadow: 0 4px 6px rgba(
|
| 137 |
print(
|
| 138 |
f'Find html file {output_html_path}, {os.path.exists(output_html_path)}, relative HTML path is /static/{rel_path}')
|
| 139 |
|
| 140 |
return f"""
|
| 141 |
-
<div style='height: {height}px; width: 100%; display: flex; justify-content: center; align-items: center; padding: 10px; background: #
|
| 142 |
{iframe_tag}
|
| 143 |
</div>
|
| 144 |
"""
|
|
@@ -363,16 +363,16 @@ def shape_generation(
|
|
| 363 |
|
| 364 |
|
| 365 |
def build_app():
|
| 366 |
-
title = '
|
| 367 |
if MV_MODE:
|
| 368 |
-
title = '
|
| 369 |
if 'mini' in args.subfolder:
|
| 370 |
-
title = '
|
| 371 |
if TURBO_MODE:
|
| 372 |
title = title.replace(':', '-Turbo: Fast ')
|
| 373 |
|
| 374 |
title_html = f"""
|
| 375 |
-
<div style="font-size: 2.5em; font-weight: bold; text-align: center; margin-bottom: 15px; background: linear-gradient(90deg, #
|
| 376 |
{title}
|
| 377 |
</div>
|
| 378 |
<div align="center">
|
|
@@ -383,78 +383,113 @@ def build_app():
|
|
| 383 |
custom_css = """
|
| 384 |
.app.svelte-wpkpf6.svelte-wpkpf6:not(.fill_width) {
|
| 385 |
max-width: 1500px;
|
| 386 |
-
background-color: #
|
| 387 |
padding: 20px;
|
| 388 |
border-radius: 12px;
|
| 389 |
-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.
|
| 390 |
}
|
| 391 |
.mv-image button .wrap {
|
| 392 |
font-size: 12px;
|
| 393 |
-
background-color: #
|
|
|
|
| 394 |
border-radius: 6px;
|
| 395 |
padding: 5px;
|
| 396 |
transition: all 0.3s ease;
|
| 397 |
}
|
| 398 |
.mv-image button:hover .wrap {
|
| 399 |
-
background-color: #
|
| 400 |
-
color: #
|
| 401 |
}
|
| 402 |
.mv-image .icon-wrap {
|
| 403 |
width: 22px;
|
| 404 |
-
background-color: #
|
| 405 |
border-radius: 50%;
|
| 406 |
}
|
| 407 |
.gr-button {
|
| 408 |
-
background-color: #
|
| 409 |
-
color:
|
| 410 |
border-radius: 8px;
|
| 411 |
padding: 10px 20px;
|
| 412 |
transition: all 0.3s ease;
|
| 413 |
}
|
| 414 |
.gr-button:hover {
|
| 415 |
-
background-color: #
|
| 416 |
transform: translateY(-2px);
|
| 417 |
}
|
| 418 |
.gr-slider, .gr-dropdown, .gr-checkbox, .gr-number {
|
| 419 |
-
border-color: #
|
| 420 |
border-radius: 8px;
|
| 421 |
-
background-color: #
|
|
|
|
| 422 |
}
|
| 423 |
.gr-tab {
|
| 424 |
-
background-color: #
|
|
|
|
| 425 |
border-radius: 8px;
|
| 426 |
padding: 5px;
|
| 427 |
}
|
| 428 |
.gr-tab:hover, .gr-tab:active {
|
| 429 |
-
background-color: #
|
| 430 |
}
|
| 431 |
"""
|
| 432 |
|
| 433 |
-
with gr.Blocks(theme=gr.themes.
|
| 434 |
gr.HTML(title_html)
|
| 435 |
|
| 436 |
with gr.Row():
|
| 437 |
with gr.Column(scale=3):
|
| 438 |
-
with gr.Tabs(selected='
|
| 439 |
-
with gr.Tab(
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
with gr.
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
|
| 459 |
with gr.Row():
|
| 460 |
btn = gr.Button(value='Gen Shape', variant='primary', min_width=100)
|
|
@@ -467,37 +502,7 @@ def build_app():
|
|
| 467 |
file_out = gr.File(label="File", visible=False)
|
| 468 |
file_out2 = gr.File(label="File", visible=False)
|
| 469 |
|
| 470 |
-
with gr.Tabs(selected='
|
| 471 |
-
with gr.Tab("Options", id='tab_options', visible=TURBO_MODE):
|
| 472 |
-
gen_mode = gr.Radio(label='Generation Mode',
|
| 473 |
-
info='Recommendation: Turbo for most cases, Fast for very complex cases, Standard seldom use.',
|
| 474 |
-
choices=['Turbo', 'Fast', 'Standard'], value='Turbo')
|
| 475 |
-
decode_mode = gr.Radio(label='Decoding Mode',
|
| 476 |
-
info='The resolution for exporting mesh from generated vectset',
|
| 477 |
-
choices=['Low', 'Standard', 'High'],
|
| 478 |
-
value='Standard')
|
| 479 |
-
with gr.Tab('Advanced Options', id='tab_advanced_options'):
|
| 480 |
-
with gr.Row():
|
| 481 |
-
check_box_rembg = gr.Checkbox(value=True, label='Remove Background', min_width=100)
|
| 482 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=True, min_width=100)
|
| 483 |
-
seed = gr.Slider(
|
| 484 |
-
label="Seed",
|
| 485 |
-
minimum=0,
|
| 486 |
-
maximum=MAX_SEED,
|
| 487 |
-
step=1,
|
| 488 |
-
value=1234,
|
| 489 |
-
min_width=100,
|
| 490 |
-
)
|
| 491 |
-
with gr.Row():
|
| 492 |
-
num_steps = gr.Slider(maximum=100,
|
| 493 |
-
minimum=1,
|
| 494 |
-
value=5 if 'turbo' in args.subfolder else 30,
|
| 495 |
-
step=1, label='Inference Steps')
|
| 496 |
-
octree_resolution = gr.Slider(maximum=512, minimum=16, value=256, label='Octree Resolution')
|
| 497 |
-
with gr.Row():
|
| 498 |
-
cfg_scale = gr.Number(value=5.0, label='Guidance Scale', min_width=100)
|
| 499 |
-
num_chunks = gr.Slider(maximum=5000000, minimum=1000, value=8000,
|
| 500 |
-
label='Number of Chunks', min_width=100)
|
| 501 |
with gr.Tab("Export", id='tab_export'):
|
| 502 |
with gr.Row():
|
| 503 |
file_type = gr.Dropdown(label='File Type', choices=SUPPORTED_FORMATS,
|
|
@@ -512,7 +517,7 @@ def build_app():
|
|
| 512 |
file_export = gr.DownloadButton(label="Download", variant='primary',
|
| 513 |
interactive=False, min_width=100)
|
| 514 |
|
| 515 |
-
with gr.Column(scale=
|
| 516 |
with gr.Tabs(selected='gen_mesh_panel') as tabs_output:
|
| 517 |
with gr.Tab('Generated Mesh', id='gen_mesh_panel'):
|
| 518 |
html_gen_mesh = gr.HTML(HTML_OUTPUT_PLACEHOLDER, label='Output')
|
|
@@ -539,22 +544,22 @@ def build_app():
|
|
| 539 |
label=None, examples_per_page=6)
|
| 540 |
|
| 541 |
gr.HTML(f"""
|
| 542 |
-
<div align="center" style="background-color: #
|
| 543 |
-
Activated Model - Shape Generation ({args.model_path}/{args.subfolder}) ; Texture Generation ({'
|
| 544 |
</div>
|
| 545 |
""")
|
| 546 |
if not HAS_TEXTUREGEN:
|
| 547 |
gr.HTML("""
|
| 548 |
-
<div style="margin-top: 5px; background-color: #
|
| 549 |
-
<b style="color: #
|
| 550 |
Texture synthesis is disable due to missing requirements,
|
| 551 |
-
please install requirements following <a href="https://github.com/Tencent/Hunyuan3D-2?tab=readme-ov-file#install-requirements">README.md</a>to activate it.
|
| 552 |
</div>
|
| 553 |
""")
|
| 554 |
if not args.enable_t23d:
|
| 555 |
gr.HTML("""
|
| 556 |
-
<div style="margin-top: 5px; background-color: #
|
| 557 |
-
<b style="color: #
|
| 558 |
Text to 3D is disable. To activate it, please run `python gradio_app.py --enable_t23d`.
|
| 559 |
</div>
|
| 560 |
""")
|
|
@@ -686,9 +691,9 @@ if __name__ == '__main__':
|
|
| 686 |
import argparse
|
| 687 |
|
| 688 |
parser = argparse.ArgumentParser()
|
| 689 |
-
parser.add_argument("--model_path", type=str, default='tencent/
|
| 690 |
-
parser.add_argument("--subfolder", type=str, default='
|
| 691 |
-
parser.add_argument("--texgen_model_path", type=str, default='tencent/
|
| 692 |
parser.add_argument('--port', type=int, default=7860)
|
| 693 |
parser.add_argument('--host', type=str, default='0.0.0.0')
|
| 694 |
parser.add_argument('--device', type=str, default='cuda')
|
|
@@ -714,17 +719,17 @@ if __name__ == '__main__':
|
|
| 714 |
HTML_HEIGHT = 690 if MV_MODE else 650
|
| 715 |
HTML_WIDTH = 500
|
| 716 |
HTML_OUTPUT_PLACEHOLDER = f"""
|
| 717 |
-
<div style='height: {650}px; width: 100%; border-radius: 8px; border-color: #
|
| 718 |
-
<div style='text-align: center; font-size: 18px; color: #
|
| 719 |
-
<p style="color: #
|
| 720 |
-
<p style="color: #
|
| 721 |
</div>
|
| 722 |
</div>
|
| 723 |
"""
|
| 724 |
|
| 725 |
INPUT_MESH_HTML = """
|
| 726 |
<div style='height: 490px; width: 100%; border-radius: 8px;
|
| 727 |
-
border-color: #
|
| 728 |
</div>
|
| 729 |
"""
|
| 730 |
example_is = get_example_img_list()
|
|
@@ -736,9 +741,9 @@ if __name__ == '__main__':
|
|
| 736 |
HAS_TEXTUREGEN = False
|
| 737 |
if not args.disable_tex:
|
| 738 |
try:
|
| 739 |
-
from hy3dgen.texgen import
|
| 740 |
|
| 741 |
-
texgen_worker =
|
| 742 |
if args.low_vram_mode:
|
| 743 |
texgen_worker.enable_model_cpu_offload()
|
| 744 |
# Not help much, ignore for now.
|
|
@@ -756,18 +761,18 @@ if __name__ == '__main__':
|
|
| 756 |
|
| 757 |
HAS_T2I = True
|
| 758 |
if args.enable_t23d:
|
| 759 |
-
from hy3dgen.text2image import
|
| 760 |
|
| 761 |
-
t2i_worker =
|
| 762 |
HAS_T2I = True
|
| 763 |
|
| 764 |
from hy3dgen.shapegen import FaceReducer, FloaterRemover, DegenerateFaceRemover, MeshSimplifier, \
|
| 765 |
-
|
| 766 |
from hy3dgen.shapegen.pipelines import export_to_trimesh
|
| 767 |
from hy3dgen.rembg import BackgroundRemover
|
| 768 |
|
| 769 |
rmbg_worker = BackgroundRemover()
|
| 770 |
-
i23d_worker =
|
| 771 |
args.model_path,
|
| 772 |
subfolder=args.subfolder,
|
| 773 |
use_safetensors=True,
|
|
|
|
| 1 |
+
# PolyGenix AI is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
|
| 2 |
# except for the third-party components listed below.
|
| 3 |
+
# PolyGenix AI does not impose any additional limitations beyond what is outlined
|
| 4 |
+
# in the respective licenses of these third-party components.
|
| 5 |
# Users must comply with all terms and conditions of original licenses of these third-party
|
| 6 |
# components and must ensure that the usage of the third party components adheres to
|
| 7 |
# all relevant laws and regulations.
|
| 8 |
|
| 9 |
+
# For avoidance of doubts, PolyGenix AI means the large language models and
|
| 10 |
# their software and algorithms, including trained model weights, parameters (including
|
| 11 |
# optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
|
| 12 |
# fine-tuning enabling code and other elements of the foregoing made publicly available
|
|
|
|
| 133 |
f.write(template_html)
|
| 134 |
|
| 135 |
rel_path = os.path.relpath(output_html_path, SAVE_DIR)
|
| 136 |
+
iframe_tag = f'<iframe src="/static/{rel_path}" height="{height}" width="100%" frameborder="0" style="border-radius: 8px; box-shadow: 0 4px 6px rgba(128, 0, 128, 0.3);"></iframe>'
|
| 137 |
print(
|
| 138 |
f'Find html file {output_html_path}, {os.path.exists(output_html_path)}, relative HTML path is /static/{rel_path}')
|
| 139 |
|
| 140 |
return f"""
|
| 141 |
+
<div style='height: {height}px; width: 100%; display: flex; justify-content: center; align-items: center; padding: 10px; background: #3a3a3a; border-radius: 8px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);'>
|
| 142 |
{iframe_tag}
|
| 143 |
</div>
|
| 144 |
"""
|
|
|
|
| 363 |
|
| 364 |
|
| 365 |
def build_app():
|
| 366 |
+
title = 'PolyGenix AI: High Resolution Textured 3D Assets Generation'
|
| 367 |
if MV_MODE:
|
| 368 |
+
title = 'PolyGenix AI-2mv: Image to 3D Generation with 1-4 Views'
|
| 369 |
if 'mini' in args.subfolder:
|
| 370 |
+
title = 'PolyGenix AI-2mini: Strong 0.6B Image to Shape Generator'
|
| 371 |
if TURBO_MODE:
|
| 372 |
title = title.replace(':', '-Turbo: Fast ')
|
| 373 |
|
| 374 |
title_html = f"""
|
| 375 |
+
<div style="font-size: 2.5em; font-weight: bold; text-align: center; margin-bottom: 15px; background: linear-gradient(90deg, #2d2d2d, #800080); -webkit-background-clip: text; color: #ffffff; padding: 10px; border-radius: 8px; text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);">
|
| 376 |
{title}
|
| 377 |
</div>
|
| 378 |
<div align="center">
|
|
|
|
| 383 |
custom_css = """
|
| 384 |
.app.svelte-wpkpf6.svelte-wpkpf6:not(.fill_width) {
|
| 385 |
max-width: 1500px;
|
| 386 |
+
background-color: #2d2d2d;
|
| 387 |
padding: 20px;
|
| 388 |
border-radius: 12px;
|
| 389 |
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
|
| 390 |
}
|
| 391 |
.mv-image button .wrap {
|
| 392 |
font-size: 12px;
|
| 393 |
+
background-color: #3a3a3a;
|
| 394 |
+
color: #ffffff;
|
| 395 |
border-radius: 6px;
|
| 396 |
padding: 5px;
|
| 397 |
transition: all 0.3s ease;
|
| 398 |
}
|
| 399 |
.mv-image button:hover .wrap {
|
| 400 |
+
background-color: #800080;
|
| 401 |
+
color: #ffffff;
|
| 402 |
}
|
| 403 |
.mv-image .icon-wrap {
|
| 404 |
width: 22px;
|
| 405 |
+
background-color: #3a3a3a;
|
| 406 |
border-radius: 50%;
|
| 407 |
}
|
| 408 |
.gr-button {
|
| 409 |
+
background-color: #800080;
|
| 410 |
+
color: #ffffff;
|
| 411 |
border-radius: 8px;
|
| 412 |
padding: 10px 20px;
|
| 413 |
transition: all 0.3s ease;
|
| 414 |
}
|
| 415 |
.gr-button:hover {
|
| 416 |
+
background-color: #660066;
|
| 417 |
transform: translateY(-2px);
|
| 418 |
}
|
| 419 |
.gr-slider, .gr-dropdown, .gr-checkbox, .gr-number {
|
| 420 |
+
border-color: #4a4a4a;
|
| 421 |
border-radius: 8px;
|
| 422 |
+
background-color: #3a3a3a;
|
| 423 |
+
color: #ffffff;
|
| 424 |
}
|
| 425 |
.gr-tab {
|
| 426 |
+
background-color: #4a4a4a;
|
| 427 |
+
color: #ffffff;
|
| 428 |
border-radius: 8px;
|
| 429 |
padding: 5px;
|
| 430 |
}
|
| 431 |
.gr-tab:hover, .gr-tab:active {
|
| 432 |
+
background-color: #800080;
|
| 433 |
}
|
| 434 |
"""
|
| 435 |
|
| 436 |
+
with gr.Blocks(theme=gr.themes.Base(primary_hue="purple", secondary_hue="gray"), title='PolyGenix AI-2.0', analytics_enabled=False, css=custom_css) as demo:
|
| 437 |
gr.HTML(title_html)
|
| 438 |
|
| 439 |
with gr.Row():
|
| 440 |
with gr.Column(scale=3):
|
| 441 |
+
with gr.Tabs(selected='tab_options') as tabs_options:
|
| 442 |
+
with gr.Tab("Options", id='tab_options', visible=TURBO_MODE):
|
| 443 |
+
gen_mode = gr.Radio(label='Generation Mode',
|
| 444 |
+
info='Recommendation: Turbo for most cases, Fast for very complex cases, Standard seldom use.',
|
| 445 |
+
choices=['Turbo', 'Fast', 'Standard'], value='Turbo')
|
| 446 |
+
decode_mode = gr.Radio(label='Decoding Mode',
|
| 447 |
+
info='The resolution for exporting mesh from generated vectset',
|
| 448 |
+
choices=['Low', 'Standard', 'High'],
|
| 449 |
+
value='Standard')
|
| 450 |
+
with gr.Tabs(selected='tab_advanced_options') as tabs_advanced:
|
| 451 |
+
with gr.Tab('Advanced Options', id='tab_advanced_options'):
|
| 452 |
+
with gr.Row():
|
| 453 |
+
check_box_rembg = gr.Checkbox(value=True, label='Remove Background', min_width=100)
|
| 454 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True, min_width=100)
|
| 455 |
+
seed = gr.Slider(
|
| 456 |
+
label="Seed",
|
| 457 |
+
minimum=0,
|
| 458 |
+
maximum=MAX_SEED,
|
| 459 |
+
step=1,
|
| 460 |
+
value=1234,
|
| 461 |
+
min_width=100,
|
| 462 |
+
)
|
| 463 |
+
with gr.Row():
|
| 464 |
+
num_steps = gr.Slider(maximum=100,
|
| 465 |
+
minimum=1,
|
| 466 |
+
value=5 if 'turbo' in args.subfolder else 30,
|
| 467 |
+
step=1, label='Inference Steps')
|
| 468 |
+
octree_resolution = gr.Slider(maximum=512, minimum=16, value=256, label='Octree Resolution')
|
| 469 |
+
with gr.Row():
|
| 470 |
+
cfg_scale = gr.Number(value=5.0, label='Guidance Scale', min_width=100)
|
| 471 |
+
num_chunks = gr.Slider(maximum=5000000, minimum=1000, value=8000,
|
| 472 |
+
label='Number of Chunks', min_width=100)
|
| 473 |
+
with gr.Tabs(selected='tab_img_prompt') as tabs_prompt:
|
| 474 |
+
with gr.Tab('Image Prompt', id='tab_img_prompt', visible=not MV_MODE) as tab_ip:
|
| 475 |
+
image = gr.Image(label='Image', type='pil', image_mode='RGBA', height=290)
|
| 476 |
+
|
| 477 |
+
with gr.Tab('Text Prompt', id='tab_txt_prompt', visible=HAS_T2I and not MV_MODE) as tab_tp:
|
| 478 |
+
caption = gr.Textbox(label='Text Prompt',
|
| 479 |
+
placeholder='PolyGenix AI DiT will be used to generate image.',
|
| 480 |
+
info='Example: A 3D model of a cute cat, white background')
|
| 481 |
+
with gr.Tab('MultiView Prompt', visible=MV_MODE) as tab_mv:
|
| 482 |
+
# gr.Label('Please upload at least one front image.')
|
| 483 |
+
with gr.Row():
|
| 484 |
+
mv_image_front = gr.Image(label='Front', type='pil', image_mode='RGBA', height=140,
|
| 485 |
+
min_width=100, elem_classes='mv-image')
|
| 486 |
+
mv_image_back = gr.Image(label='Back', type='pil', image_mode='RGBA', height=140,
|
| 487 |
+
min_width=100, elem_classes='mv-image')
|
| 488 |
+
with gr.Row():
|
| 489 |
+
mv_image_left = gr.Image(label='Left', type='pil', image_mode='RGBA', height=140,
|
| 490 |
+
min_width=100, elem_classes='mv-image')
|
| 491 |
+
mv_image_right = gr.Image(label='Right', type='pil', image_mode='RGBA', height=140,
|
| 492 |
+
min_width=100, elem_classes='mv-image')
|
| 493 |
|
| 494 |
with gr.Row():
|
| 495 |
btn = gr.Button(value='Gen Shape', variant='primary', min_width=100)
|
|
|
|
| 502 |
file_out = gr.File(label="File", visible=False)
|
| 503 |
file_out2 = gr.File(label="File", visible=False)
|
| 504 |
|
| 505 |
+
with gr.Tabs(selected='tab_export'):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 506 |
with gr.Tab("Export", id='tab_export'):
|
| 507 |
with gr.Row():
|
| 508 |
file_type = gr.Dropdown(label='File Type', choices=SUPPORTED_FORMATS,
|
|
|
|
| 517 |
file_export = gr.DownloadButton(label="Download", variant='primary',
|
| 518 |
interactive=False, min_width=100)
|
| 519 |
|
| 520 |
+
with gr.Column(scale=7):
|
| 521 |
with gr.Tabs(selected='gen_mesh_panel') as tabs_output:
|
| 522 |
with gr.Tab('Generated Mesh', id='gen_mesh_panel'):
|
| 523 |
html_gen_mesh = gr.HTML(HTML_OUTPUT_PLACEHOLDER, label='Output')
|
|
|
|
| 544 |
label=None, examples_per_page=6)
|
| 545 |
|
| 546 |
gr.HTML(f"""
|
| 547 |
+
<div align="center" style="background-color: #3a3a3a; padding: 10px; border-radius: 8px; margin-top: 10px; color: #ffffff;">
|
| 548 |
+
Activated Model - Shape Generation ({args.model_path}/{args.subfolder}) ; Texture Generation ({'PolyGenix AI-2' if HAS_TEXTUREGEN else 'Unavailable'})
|
| 549 |
</div>
|
| 550 |
""")
|
| 551 |
if not HAS_TEXTUREGEN:
|
| 552 |
gr.HTML("""
|
| 553 |
+
<div style="margin-top: 5px; background-color: #4a2d2d; padding: 10px; border-radius: 8px; border: 1px solid #800000; color: #ffffff;" align="center">
|
| 554 |
+
<b style="color: #ff4040;">Warning: </b>
|
| 555 |
Texture synthesis is disable due to missing requirements,
|
| 556 |
+
please install requirements following <a href="https://github.com/Tencent/Hunyuan3D-2?tab=readme-ov-file#install-requirements" style="color: #800080;">README.md</a> to activate it.
|
| 557 |
</div>
|
| 558 |
""")
|
| 559 |
if not args.enable_t23d:
|
| 560 |
gr.HTML("""
|
| 561 |
+
<div style="margin-top: 5px; background-color: #4a2d2d; padding: 10px; border-radius: 8px; border: 1px solid #800000; color: #ffffff;" align="center">
|
| 562 |
+
<b style="color: #ff4040;">Warning: </b>
|
| 563 |
Text to 3D is disable. To activate it, please run `python gradio_app.py --enable_t23d`.
|
| 564 |
</div>
|
| 565 |
""")
|
|
|
|
| 691 |
import argparse
|
| 692 |
|
| 693 |
parser = argparse.ArgumentParser()
|
| 694 |
+
parser.add_argument("--model_path", type=str, default='tencent/PolyGenix AI-2')
|
| 695 |
+
parser.add_argument("--subfolder", type=str, default='polygenix-dit-v2-0')
|
| 696 |
+
parser.add_argument("--texgen_model_path", type=str, default='tencent/PolyGenix AI-2')
|
| 697 |
parser.add_argument('--port', type=int, default=7860)
|
| 698 |
parser.add_argument('--host', type=str, default='0.0.0.0')
|
| 699 |
parser.add_argument('--device', type=str, default='cuda')
|
|
|
|
| 719 |
HTML_HEIGHT = 690 if MV_MODE else 650
|
| 720 |
HTML_WIDTH = 500
|
| 721 |
HTML_OUTPUT_PLACEHOLDER = f"""
|
| 722 |
+
<div style='height: {650}px; width: 100%; border-radius: 8px; border-color: #4a4a4a; border-style: solid; border-width: 1px; display: flex; justify-content: center; align-items: center; background-color: #3a3a3a; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.5);'>
|
| 723 |
+
<div style='text-align: center; font-size: 18px; color: #ffffff;'>
|
| 724 |
+
<p style="color: #cccccc;">Welcome to PolyGenix AI!</p>
|
| 725 |
+
<p style="color: #cccccc;">No mesh here.</p>
|
| 726 |
</div>
|
| 727 |
</div>
|
| 728 |
"""
|
| 729 |
|
| 730 |
INPUT_MESH_HTML = """
|
| 731 |
<div style='height: 490px; width: 100%; border-radius: 8px;
|
| 732 |
+
border-color: #4a4a4a; order-style: solid; border-width: 1px;'>
|
| 733 |
</div>
|
| 734 |
"""
|
| 735 |
example_is = get_example_img_list()
|
|
|
|
| 741 |
HAS_TEXTUREGEN = False
|
| 742 |
if not args.disable_tex:
|
| 743 |
try:
|
| 744 |
+
from hy3dgen.texgen import PolyGenix AIPaintPipeline
|
| 745 |
|
| 746 |
+
texgen_worker = PolyGenix AIPaintPipeline.from_pretrained(args.texgen_model_path)
|
| 747 |
if args.low_vram_mode:
|
| 748 |
texgen_worker.enable_model_cpu_offload()
|
| 749 |
# Not help much, ignore for now.
|
|
|
|
| 761 |
|
| 762 |
HAS_T2I = True
|
| 763 |
if args.enable_t23d:
|
| 764 |
+
from hy3dgen.text2image import PolyGenix AIDiTPipeline
|
| 765 |
|
| 766 |
+
t2i_worker = PolyGenix AIDiTPipeline('Tencent-Hunyuan/PolyGenix AIDiT-v1.1-Diffusers-Distilled')
|
| 767 |
HAS_T2I = True
|
| 768 |
|
| 769 |
from hy3dgen.shapegen import FaceReducer, FloaterRemover, DegenerateFaceRemover, MeshSimplifier, \
|
| 770 |
+
PolyGenix AIDiTFlowMatchingPipeline
|
| 771 |
from hy3dgen.shapegen.pipelines import export_to_trimesh
|
| 772 |
from hy3dgen.rembg import BackgroundRemover
|
| 773 |
|
| 774 |
rmbg_worker = BackgroundRemover()
|
| 775 |
+
i23d_worker = PolyGenix AIDiTFlowMatchingPipeline.from_pretrained(
|
| 776 |
args.model_path,
|
| 777 |
subfolder=args.subfolder,
|
| 778 |
use_safetensors=True,
|