Image-to-3D / app.py
frogleo's picture
优化界面和交互
d02142b
raw
history blame
2.75 kB
import spaces
import gradio as gr
from glob import glob
@spaces.GPU(duration=60)
def gen_shape():
print("do nothing")
def get_example_img_list():
print('Loading example img list ...')
return sorted(glob('./assets/example_images/**/*.png', recursive=True))
example_imgs = get_example_img_list()
HTML_OUTPUT_PLACEHOLDER = f"""
<div style='height: {650}px; width: 100%; border-radius: 8px; border-color: #e5e7eb; border-style: solid; border-width: 1px; display: flex; justify-content: center; align-items: center;'>
<div style='text-align: center; font-size: 16px; color: #6b7280;'>
<p style="color: #8d8d8d;">Welcome to Hunyuan3D!</p>
<p style="color: #8d8d8d;">No mesh here.</p>
</div>
</div>
"""
MAX_SEED = 1e7
title = "## Image to 3D"
description = "A lightweight image to 3D converter"
with gr.Blocks().queue() as demo:
gr.Markdown(title)
gr.Markdown(description)
with gr.Row():
with gr.Column(scale=3):
gr.Markdown("#### Image Prompt")
image = gr.Image(sources=["upload"], label='Image', type='pil', image_mode='RGBA', height=290)
with gr.Column():
seed = gr.Slider(
label="Seed",
minimum=0,
maximum=MAX_SEED,
step=1,
value=1234,
min_width=100,
)
with gr.Column():
num_steps = gr.Slider(maximum=100,
minimum=1,
value=5,
step=1, label='Inference Steps')
octree_resolution = gr.Slider(maximum=512, minimum=16, value=256, label='Octree Resolution')
with gr.Column():
cfg_scale = gr.Number(value=5.0, label='Guidance Scale', min_width=100)
num_chunks = gr.Slider(maximum=5000000, minimum=1000, value=8000,
label='Number of Chunks', min_width=100)
with gr.Column(scale=6):
gr.Markdown("#### Generated Mesh")
with gr.Tabs(selected='gen_mesh_panel') as tabs_output:
with gr.Tab('Exporting Mesh', id='export_mesh_panel'):
html_export_mesh = gr.HTML(HTML_OUTPUT_PLACEHOLDER, label='Output')
with gr.Tab('Mesh Statistic', id='stats_panel'):
stats = gr.Json({}, label='Mesh Stats')
with gr.Column(scale=3):
gr.Markdown("#### Image Examples")
gr.Examples(examples=example_imgs, inputs=[image],
label=None, examples_per_page=18)
demo.launch()