1
- # pip install gradio==3.39.0
2
1
import os
3
2
import shutil
4
3
import time
5
4
from glob import glob
5
+ from pathlib import Path
6
6
7
7
import gradio as gr
8
8
import torch
9
+ import uvicorn
10
+ from fastapi import FastAPI
11
+ from fastapi .staticfiles import StaticFiles
9
12
10
13
11
14
def get_example_img_list ():
@@ -68,7 +71,7 @@ def build_model_viewer_html(save_folder, height=660, width=790, textured=False):
68
71
with open (output_html_path , 'w' ) as f :
69
72
f .write (template_html .replace ('<model-viewer>' , obj_html ))
70
73
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>'
72
75
print (f'Find html { output_html_path } , { os .path .exists (output_html_path )} ' )
73
76
74
77
return f"""
@@ -357,10 +360,6 @@ def build_app():
357
360
example_is = get_example_img_list ()
358
361
example_ts = get_example_txt_list ()
359
362
360
- from hy3dgen .shapegen import FaceReducer , FloaterRemover , DegenerateFaceRemover , \
361
- Hunyuan3DDiTFlowMatchingPipeline
362
- from hy3dgen .rembg import BackgroundRemover
363
-
364
363
try :
365
364
from hy3dgen .texgen import Hunyuan3DPaintPipeline
366
365
@@ -379,15 +378,24 @@ def build_app():
379
378
t2i_worker = HunyuanDiTPipeline ('Tencent-Hunyuan/HunyuanDiT-v1.1-Diffusers-Distilled' )
380
379
HAS_T2I = True
381
380
381
+ from hy3dgen .shapegen import FaceReducer , FloaterRemover , DegenerateFaceRemover , \
382
+ Hunyuan3DDiTFlowMatchingPipeline
383
+ from hy3dgen .rembg import BackgroundRemover
384
+
382
385
rmbg_worker = BackgroundRemover ()
383
386
i23d_worker = Hunyuan3DDiTFlowMatchingPipeline .from_pretrained ('tencent/Hunyuan3D-2' )
384
387
floater_remove_worker = FloaterRemover ()
385
388
degenerate_face_remove_worker = DegenerateFaceRemover ()
386
389
face_reduce_worker = FaceReducer ()
387
390
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
+
388
399
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 )
0 commit comments