Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add faces menu to Gradio py, plus slight increases to teh resolutions offered. I demonstrated teh improvements in model output in teh other pull request (that one is a dud, i did it right here) #79

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions gradio_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles

from mmgp import offload

def get_example_img_list():
print('Loading example img list ...')
Expand All @@ -33,7 +34,7 @@ def gen_save_folder(max_size=60):
print(f"remove {SAVE_DIR}/{(cur_id + 1) % max_size} success !!!")
save_folder = f"{SAVE_DIR}/{max(0, cur_id)}"
os.makedirs(save_folder, exist_ok=True)
print(f"mkdir {save_folder} success !!!")
print(f"mkdir {save_folder} suceess !!!")
return save_folder


Expand Down Expand Up @@ -92,6 +93,7 @@ def _gen_shape(
seed=1234,
octree_resolution=256,
check_box_rembg=False,
max_facenum = 40000,
):
if caption: print('prompt is', caption)
save_folder = gen_save_folder()
Expand All @@ -104,7 +106,7 @@ def _gen_shape(
try:
image = t2i_worker(caption)
except Exception as e:
raise gr.Error(f"Text to 3D is disabled. Please enable it by restarted the app with `python gradio_app.py --enable_t23d`.")
raise gr.Error(f"Text to 3D is disable. Please enable it by `python gradio_app.py --enable_t23d`.")
time_meta['text2image'] = time.time() - start_time

image.save(os.path.join(save_folder, 'input.png'))
Expand Down Expand Up @@ -132,7 +134,7 @@ def _gen_shape(

mesh = FloaterRemover()(mesh)
mesh = DegenerateFaceRemover()(mesh)
mesh = FaceReducer()(mesh)
mesh = FaceReducer()(mesh, max_facenum=max_facenum)

stats['number_of_faces'] = mesh.faces.shape[0]
stats['number_of_vertices'] = mesh.vertices.shape[0]
Expand All @@ -150,7 +152,8 @@ def generation_all(
guidance_scale=7.5,
seed=1234,
octree_resolution=256,
check_box_rembg=False
check_box_rembg=False,
max_facenum = 40000
):
mesh, image, save_folder = _gen_shape(
caption,
Expand All @@ -159,8 +162,10 @@ def generation_all(
guidance_scale=guidance_scale,
seed=seed,
octree_resolution=octree_resolution,
check_box_rembg=check_box_rembg
check_box_rembg=check_box_rembg,
max_facenum=max_facenum
)

path = export_mesh(mesh, save_folder, textured=False)
model_viewer_html = build_model_viewer_html(save_folder, height=596, width=700)

Expand All @@ -184,6 +189,7 @@ def shape_generation(
seed=1234,
octree_resolution=256,
check_box_rembg=False,
max_facenum = 40000
):
mesh, image, save_folder = _gen_shape(
caption,
Expand All @@ -192,7 +198,8 @@ def shape_generation(
guidance_scale=guidance_scale,
seed=seed,
octree_resolution=octree_resolution,
check_box_rembg=check_box_rembg
check_box_rembg=check_box_rembg,
max_facenum=max_facenum
)

path = export_mesh(mesh, save_folder, textured=False)
Expand Down Expand Up @@ -238,9 +245,10 @@ def build_app():
info='Example: A 3D model of a cute cat, white background')

with gr.Accordion('Advanced Options', open=False):
num_steps = gr.Slider(maximum=50, minimum=20, value=30, step=1, label='Inference Steps')
octree_resolution = gr.Dropdown([256, 384, 512], value=256, label='Octree Resolution')
num_steps = gr.Slider(maximum=100, minimum=20, value=30, step=1, label='Inference Steps')
octree_resolution = gr.Dropdown([256, 384, 512, 768, 1024], value=256, label='Octree Resolution')
cfg_scale = gr.Number(value=5.5, label='Guidance Scale')
max_facenum_slider = gr.Slider(maximum=150000, minimum=20000, value=40000, step=1000, label='Faces')
seed = gr.Slider(maximum=1e7, minimum=0, value=1234, label='Seed')

with gr.Group():
Expand Down Expand Up @@ -274,15 +282,15 @@ def build_app():
gr.HTML("""
<div style="margin-top: 20px;">
<b>Warning: </b>
Texture synthesis is disabled due to missing requirements,
please refer to the README.md and install the missing requirements to activate it.
Texture synthesis is disable due to missing requirements,
please install requirements following README.md to activate it.
</div>
""")
if not args.enable_t23d:
gr.HTML("""
<div style="margin-top: 20px;">
<b>Warning: </b>
Text to 3D is disabled. Please enable it by restarted the app with `python gradio_app.py --enable_t23d`.
Text to 3D is disable. To activate it, please run `python gradio_app.py --enable_t23d`.
</div>
""")

Expand All @@ -300,6 +308,7 @@ def build_app():
seed,
octree_resolution,
check_box_rembg,
max_facenum_slider
],
outputs=[file_out, html_output1]
).then(
Expand All @@ -317,6 +326,7 @@ def build_app():
seed,
octree_resolution,
check_box_rembg,
max_facenum_slider
],
outputs=[file_out, file_out2, html_output1, html_output2]
).then(
Expand All @@ -335,6 +345,9 @@ def build_app():
parser.add_argument('--host', type=str, default='0.0.0.0')
parser.add_argument('--cache-path', type=str, default='gradio_cache')
parser.add_argument('--enable_t23d', action='store_true')
parser.add_argument('--profile', type=str, default="4")
parser.add_argument('--verbose', type=str, default="1")

args = parser.parse_args()

SAVE_DIR = args.cache_path
Expand All @@ -354,6 +367,7 @@ def build_app():
example_is = get_example_img_list()
example_ts = get_example_txt_list()

torch.set_default_device("cpu")
try:
from hy3dgen.texgen import Hunyuan3DPaintPipeline

Expand Down