Spaces:
Running
on
T4
Running
on
T4
Upload gradio_app.py
Browse files- gradio_app.py +20 -22
gradio_app.py
CHANGED
@@ -137,7 +137,21 @@ def build_model_viewer_html(save_folder, height=660, width=790, textured=False):
|
|
137 |
template_html = template_html.replace('#src#', f'{related_path}/')
|
138 |
f.write(template_html)
|
139 |
|
140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
# Encode the GLB file as base64 to embed directly in the HTML
|
142 |
with open(mesh_file, "rb") as f:
|
143 |
glb_data = f.read()
|
@@ -403,15 +417,15 @@ def build_app():
|
|
403 |
with gr.Row():
|
404 |
with gr.Column(scale=3):
|
405 |
with gr.Tabs(selected='tab_img_prompt') as tabs_prompt:
|
406 |
-
with gr.Tab('Image Prompt', id='tab_img_prompt', visible=
|
407 |
image = gr.Image(label='Image', type='pil', image_mode='RGBA', height=290)
|
408 |
|
409 |
-
with gr.Tab('Text Prompt', id='tab_txt_prompt', visible=
|
410 |
caption = gr.Textbox(label='Text Prompt',
|
411 |
placeholder='HunyuanDiT will be used to generate image.',
|
412 |
info='Example: A 3D model of a cute cat, white background')
|
413 |
|
414 |
-
with gr.Tab('MultiView Prompt', visible=
|
415 |
# gr.Label('Please upload at least one front image.')
|
416 |
with gr.Row():
|
417 |
mv_image_front = gr.Image(label='Front', type='pil', image_mode='RGBA', height=140,
|
@@ -480,7 +494,7 @@ def build_app():
|
|
480 |
file_export = gr.DownloadButton(label="Download", variant='primary',
|
481 |
interactive=False, min_width=100)
|
482 |
|
483 |
-
with gr.Column(scale=
|
484 |
with gr.Tabs(selected='gen_mesh_panel') as tabs_output:
|
485 |
with gr.Tab('Generated Mesh', id='gen_mesh_panel'):
|
486 |
html_gen_mesh = gr.HTML(HTML_OUTPUT_PLACEHOLDER, label='Output')
|
@@ -489,22 +503,6 @@ def build_app():
|
|
489 |
with gr.Tab('Mesh Statistic', id='stats_panel'):
|
490 |
stats = gr.Json({}, label='Mesh Stats')
|
491 |
|
492 |
-
with gr.Column(scale=3 if MV_MODE else 2):
|
493 |
-
with gr.Tabs(selected='tab_img_gallery') as gallery:
|
494 |
-
with gr.Tab('Image to 3D Gallery', id='tab_img_gallery', visible=not MV_MODE) as tab_gi:
|
495 |
-
with gr.Row():
|
496 |
-
gr.Examples(examples=example_is, inputs=[image],
|
497 |
-
label=None, examples_per_page=18)
|
498 |
-
|
499 |
-
with gr.Tab('Text to 3D Gallery', id='tab_txt_gallery', visible=HAS_T2I and not MV_MODE) as tab_gt:
|
500 |
-
with gr.Row():
|
501 |
-
gr.Examples(examples=example_ts, inputs=[caption],
|
502 |
-
label=None, examples_per_page=18)
|
503 |
-
with gr.Tab('MultiView to 3D Gallery', id='tab_mv_gallery', visible=MV_MODE) as tab_mv:
|
504 |
-
with gr.Row():
|
505 |
-
gr.Examples(examples=example_mvs,
|
506 |
-
inputs=[mv_image_front, mv_image_back, mv_image_left, mv_image_right],
|
507 |
-
label=None, examples_per_page=6)
|
508 |
|
509 |
tab_ip.select(fn=lambda: gr.update(selected='tab_img_gallery'), outputs=gallery)
|
510 |
if HAS_T2I:
|
@@ -739,4 +737,4 @@ if __name__ == '__main__':
|
|
739 |
if args.low_vram_mode:
|
740 |
torch.cuda.empty_cache()
|
741 |
demo = build_app()
|
742 |
-
demo.launch()
|
|
|
137 |
template_html = template_html.replace('#src#', f'{related_path}/')
|
138 |
f.write(template_html)
|
139 |
|
140 |
+
#iframe_tag = f'<iframe src="file={output_html_path}" height="{height}" width="100%" frameborder="0"></iframe>'
|
141 |
+
#print(
|
142 |
+
# f'Find html file {output_html_path}, {os.path.exists(output_html_path)}, relative HTML path is /static/{rel_path}')
|
143 |
+
|
144 |
+
#return f"""
|
145 |
+
# <div style='height: {height}; width: 100%;'>
|
146 |
+
# {iframe_tag}
|
147 |
+
# </div>
|
148 |
+
#"""
|
149 |
+
|
150 |
+
if textured:
|
151 |
+
mesh_file = os.path.join(save_folder, "textured_mesh.glb")
|
152 |
+
else:
|
153 |
+
mesh_file = os.path.join(save_folder, "white_mesh.glb")
|
154 |
+
|
155 |
# Encode the GLB file as base64 to embed directly in the HTML
|
156 |
with open(mesh_file, "rb") as f:
|
157 |
glb_data = f.read()
|
|
|
417 |
with gr.Row():
|
418 |
with gr.Column(scale=3):
|
419 |
with gr.Tabs(selected='tab_img_prompt') as tabs_prompt:
|
420 |
+
with gr.Tab('Image Prompt', id='tab_img_prompt', visible=False) as tab_ip:
|
421 |
image = gr.Image(label='Image', type='pil', image_mode='RGBA', height=290)
|
422 |
|
423 |
+
with gr.Tab('Text Prompt', id='tab_txt_prompt', visible=False) as tab_tp:
|
424 |
caption = gr.Textbox(label='Text Prompt',
|
425 |
placeholder='HunyuanDiT will be used to generate image.',
|
426 |
info='Example: A 3D model of a cute cat, white background')
|
427 |
|
428 |
+
with gr.Tab('MultiView Prompt', visible=True) as tab_mv:
|
429 |
# gr.Label('Please upload at least one front image.')
|
430 |
with gr.Row():
|
431 |
mv_image_front = gr.Image(label='Front', type='pil', image_mode='RGBA', height=140,
|
|
|
494 |
file_export = gr.DownloadButton(label="Download", variant='primary',
|
495 |
interactive=False, min_width=100)
|
496 |
|
497 |
+
with gr.Column(scale=9):
|
498 |
with gr.Tabs(selected='gen_mesh_panel') as tabs_output:
|
499 |
with gr.Tab('Generated Mesh', id='gen_mesh_panel'):
|
500 |
html_gen_mesh = gr.HTML(HTML_OUTPUT_PLACEHOLDER, label='Output')
|
|
|
503 |
with gr.Tab('Mesh Statistic', id='stats_panel'):
|
504 |
stats = gr.Json({}, label='Mesh Stats')
|
505 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
506 |
|
507 |
tab_ip.select(fn=lambda: gr.update(selected='tab_img_gallery'), outputs=gallery)
|
508 |
if HAS_T2I:
|
|
|
737 |
if args.low_vram_mode:
|
738 |
torch.cuda.empty_cache()
|
739 |
demo = build_app()
|
740 |
+
demo.launch(share=True)
|