Skip to content

Commit d114bdd

Browse files
committed
update gradio, soft version requirement
1 parent 7200c5e commit d114bdd

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

gradio_app.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
# pip install gradio==3.39.0
21
import os
32
import shutil
43
import time
54
from glob import glob
5+
from pathlib import Path
66

77
import gradio as gr
88
import torch
9+
import uvicorn
10+
from fastapi import FastAPI
11+
from fastapi.staticfiles import StaticFiles
912

1013

1114
def get_example_img_list():
@@ -68,7 +71,7 @@ def build_model_viewer_html(save_folder, height=660, width=790, textured=False):
6871
with open(output_html_path, 'w') as f:
6972
f.write(template_html.replace('<model-viewer>', obj_html))
7073

71-
iframe_tag = f'<iframe src="file/{output_html_path}" height="{height}" width="100%" frameborder="0"></iframe>'
74+
iframe_tag = f'<iframe src="/static/{output_html_path}" height="{height}" width="100%" frameborder="0"></iframe>'
7275
print(f'Find html {output_html_path}, {os.path.exists(output_html_path)}')
7376

7477
return f"""
@@ -357,10 +360,6 @@ def build_app():
357360
example_is = get_example_img_list()
358361
example_ts = get_example_txt_list()
359362

360-
from hy3dgen.shapegen import FaceReducer, FloaterRemover, DegenerateFaceRemover, \
361-
Hunyuan3DDiTFlowMatchingPipeline
362-
from hy3dgen.rembg import BackgroundRemover
363-
364363
try:
365364
from hy3dgen.texgen import Hunyuan3DPaintPipeline
366365

@@ -379,15 +378,24 @@ def build_app():
379378
t2i_worker = HunyuanDiTPipeline('Tencent-Hunyuan/HunyuanDiT-v1.1-Diffusers-Distilled')
380379
HAS_T2I = True
381380

381+
from hy3dgen.shapegen import FaceReducer, FloaterRemover, DegenerateFaceRemover, \
382+
Hunyuan3DDiTFlowMatchingPipeline
383+
from hy3dgen.rembg import BackgroundRemover
384+
382385
rmbg_worker = BackgroundRemover()
383386
i23d_worker = Hunyuan3DDiTFlowMatchingPipeline.from_pretrained('tencent/Hunyuan3D-2')
384387
floater_remove_worker = FloaterRemover()
385388
degenerate_face_remove_worker = DegenerateFaceRemover()
386389
face_reduce_worker = FaceReducer()
387390

391+
# https://discuss.huggingface.co/t/how-to-serve-an-html-file/33921/2
392+
# create a FastAPI app
393+
app = FastAPI()
394+
# create a static directory to store the static files
395+
static_dir = Path('./gradio_cache')
396+
static_dir.mkdir(parents=True, exist_ok=True)
397+
app.mount("/static", StaticFiles(directory=static_dir), name="static")
398+
388399
demo = build_app()
389-
demo.queue().launch(
390-
server_name='0.0.0.0',
391-
server_port=args.port,
392-
allowed_paths=[SAVE_DIR],
393-
)
400+
app = gr.mount_gradio_app(app, demo, path="/")
401+
uvicorn.run(app, host="0.0.0.0", port=args.port)

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
gradio_litmodel3d
21
ninja
32
pybind11
43
trimesh
@@ -15,7 +14,6 @@ ConfigArgParse
1514
xatlas
1615
scikit-learn
1716
scikit-image
18-
tritonclient
1917
gevent
2018
geventhttpclient
2119
facexlib
@@ -31,3 +29,5 @@ onnxruntime
3129
pygltflib
3230
sentencepiece
3331
gradio
32+
fastapi
33+
uvicorn

0 commit comments

Comments
 (0)