NikoNovice commited on
Commit
3095e49
·
1 Parent(s): 5f10340

inital commit

Browse files
Files changed (4) hide show
  1. .gitignore.py +168 -0
  2. README.md +0 -13
  3. app.py +395 -0
  4. requirements.txt +40 -0
.gitignore.py ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+ gradio_cache/
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
README.md DELETED
@@ -1,13 +0,0 @@
1
- ---
2
- title: Test2
3
- emoji: 🐢
4
- colorFrom: gray
5
- colorTo: yellow
6
- sdk: gradio
7
- sdk_version: 5.13.1
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app.py ADDED
@@ -0,0 +1,395 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import shutil
3
+ import time
4
+ from glob import glob
5
+ from pathlib import Path
6
+
7
+ import gradio as gr
8
+ import torch
9
+ import uvicorn
10
+ from fastapi import FastAPI
11
+ from fastapi.staticfiles import StaticFiles
12
+
13
+
14
+ def get_example_img_list():
15
+ print('Loading example img list ...')
16
+ return sorted(glob('./assets/example_images/*.png'))
17
+
18
+
19
+ def get_example_txt_list():
20
+ print('Loading example txt list ...')
21
+ txt_list = list()
22
+ for line in open('./assets/example_prompts.txt', encoding='utf-8'):
23
+ txt_list.append(line.strip())
24
+ return txt_list
25
+
26
+
27
+ def gen_save_folder(max_size=60):
28
+ os.makedirs(SAVE_DIR, exist_ok=True)
29
+ exists = set(int(_) for _ in os.listdir(SAVE_DIR) if _.isdigit())
30
+ cur_id = min(set(range(max_size)) - exists) if len(exists) < max_size else -1
31
+ if os.path.exists(f"{SAVE_DIR}/{(cur_id + 1) % max_size}"):
32
+ shutil.rmtree(f"{SAVE_DIR}/{(cur_id + 1) % max_size}")
33
+ print(f"remove {SAVE_DIR}/{(cur_id + 1) % max_size} success !!!")
34
+ save_folder = f"{SAVE_DIR}/{max(0, cur_id)}"
35
+ os.makedirs(save_folder, exist_ok=True)
36
+ print(f"mkdir {save_folder} suceess !!!")
37
+ return save_folder
38
+
39
+
40
+ def export_mesh(mesh, save_folder, textured=False):
41
+ if textured:
42
+ path = os.path.join(save_folder, f'textured_mesh.glb')
43
+ else:
44
+ path = os.path.join(save_folder, f'white_mesh.glb')
45
+ mesh.export(path, include_normals=textured)
46
+ return path
47
+
48
+
49
+ def build_model_viewer_html(save_folder, height=660, width=790, textured=False):
50
+ # Remove first folder from path to make relative path
51
+ if textured:
52
+ related_path = f"./textured_mesh.glb"
53
+ template_name = './assets/modelviewer-textured-template.html'
54
+ output_html_path = os.path.join(save_folder, f'textured_mesh.html')
55
+ else:
56
+ related_path = f"./white_mesh.glb"
57
+ template_name = './assets/modelviewer-template.html'
58
+ output_html_path = os.path.join(save_folder, f'white_mesh.html')
59
+
60
+ with open(os.path.join(CURRENT_DIR, template_name), 'r', encoding='utf-8') as f:
61
+ template_html = f.read()
62
+ obj_html = f"""
63
+ <div class="column is-mobile is-centered">
64
+ <model-viewer style="height: {height - 10}px; width: {width}px;" rotation-per-second="10deg" id="modelViewer"
65
+ src="{related_path}/" disable-tap
66
+ environment-image="neutral" auto-rotate camera-target="0m 0m 0m" orientation="0deg 0deg 170deg" shadow-intensity=".9"
67
+ ar auto-rotate camera-controls>
68
+ </model-viewer>
69
+ </div>
70
+ """
71
+
72
+ with open(output_html_path, 'w', encoding='utf-8') as f:
73
+ f.write(template_html.replace('<model-viewer>', obj_html))
74
+
75
+ rel_path = os.path.relpath(output_html_path, SAVE_DIR)
76
+ iframe_tag = f'<iframe src="/static/{rel_path}" height="{height}" width="100%" frameborder="0"></iframe>'
77
+ print(
78
+ f'Find html file {output_html_path}, {os.path.exists(output_html_path)}, relative HTML path is /static/{rel_path}')
79
+
80
+ return f"""
81
+ <div style='height: {height}; width: 100%;'>
82
+ {iframe_tag}
83
+ </div>
84
+ """
85
+
86
+
87
+ def _gen_shape(
88
+ caption,
89
+ image,
90
+ steps=50,
91
+ guidance_scale=7.5,
92
+ seed=1234,
93
+ octree_resolution=256,
94
+ check_box_rembg=False,
95
+ ):
96
+ if caption: print('prompt is', caption)
97
+ save_folder = gen_save_folder()
98
+ stats = {}
99
+ time_meta = {}
100
+ start_time_0 = time.time()
101
+
102
+ if image is None:
103
+ start_time = time.time()
104
+ try:
105
+ image = t2i_worker(caption)
106
+ except Exception as e:
107
+ raise gr.Error(f"Text to 3D is disable. Please enable it by `python gradio_app.py --enable_t23d`.")
108
+ time_meta['text2image'] = time.time() - start_time
109
+
110
+ image.save(os.path.join(save_folder, 'input.png'))
111
+
112
+ print(image.mode)
113
+ if check_box_rembg or image.mode == "RGB":
114
+ start_time = time.time()
115
+ image = rmbg_worker(image.convert('RGB'))
116
+ time_meta['rembg'] = time.time() - start_time
117
+
118
+ image.save(os.path.join(save_folder, 'rembg.png'))
119
+
120
+ # image to white model
121
+ start_time = time.time()
122
+
123
+ generator = torch.Generator()
124
+ generator = generator.manual_seed(int(seed))
125
+ mesh = i23d_worker(
126
+ image=image,
127
+ num_inference_steps=steps,
128
+ guidance_scale=guidance_scale,
129
+ generator=generator,
130
+ octree_resolution=octree_resolution
131
+ )[0]
132
+
133
+ mesh = FloaterRemover()(mesh)
134
+ mesh = DegenerateFaceRemover()(mesh)
135
+ mesh = FaceReducer()(mesh)
136
+
137
+ stats['number_of_faces'] = mesh.faces.shape[0]
138
+ stats['number_of_vertices'] = mesh.vertices.shape[0]
139
+
140
+ time_meta['image_to_textured_3d'] = {'total': time.time() - start_time}
141
+ time_meta['total'] = time.time() - start_time_0
142
+ stats['time'] = time_meta
143
+ return mesh, image, save_folder
144
+
145
+
146
+ def generation_all(
147
+ caption,
148
+ image,
149
+ steps=50,
150
+ guidance_scale=7.5,
151
+ seed=1234,
152
+ octree_resolution=256,
153
+ check_box_rembg=False
154
+ ):
155
+ mesh, image, save_folder = _gen_shape(
156
+ caption,
157
+ image,
158
+ steps=steps,
159
+ guidance_scale=guidance_scale,
160
+ seed=seed,
161
+ octree_resolution=octree_resolution,
162
+ check_box_rembg=check_box_rembg
163
+ )
164
+ path = export_mesh(mesh, save_folder, textured=False)
165
+ model_viewer_html = build_model_viewer_html(save_folder, height=596, width=700)
166
+
167
+ textured_mesh = texgen_worker(mesh, image)
168
+ path_textured = export_mesh(textured_mesh, save_folder, textured=True)
169
+ model_viewer_html_textured = build_model_viewer_html(save_folder, height=596, width=700, textured=True)
170
+
171
+ return (
172
+ gr.update(value=path, visible=True),
173
+ gr.update(value=path_textured, visible=True),
174
+ model_viewer_html,
175
+ model_viewer_html_textured,
176
+ )
177
+
178
+
179
+ def shape_generation(
180
+ caption,
181
+ image,
182
+ steps=50,
183
+ guidance_scale=7.5,
184
+ seed=1234,
185
+ octree_resolution=256,
186
+ check_box_rembg=False,
187
+ ):
188
+ mesh, image, save_folder = _gen_shape(
189
+ caption,
190
+ image,
191
+ steps=steps,
192
+ guidance_scale=guidance_scale,
193
+ seed=seed,
194
+ octree_resolution=octree_resolution,
195
+ check_box_rembg=check_box_rembg
196
+ )
197
+
198
+ path = export_mesh(mesh, save_folder, textured=False)
199
+ model_viewer_html = build_model_viewer_html(save_folder, height=596, width=700)
200
+
201
+ return (
202
+ gr.update(value=path, visible=True),
203
+ model_viewer_html,
204
+ )
205
+
206
+
207
+ def build_app():
208
+ title_html = """
209
+ <div style="font-size: 2em; font-weight: bold; text-align: center; margin-bottom: 5px">
210
+
211
+ Hunyuan3D-2: Scaling Diffusion Models for High Resolution Textured 3D Assets Generation
212
+ </div>
213
+ <div align="center">
214
+ Tencent Hunyuan3D Team
215
+ </div>
216
+ <div align="center">
217
+ <a href="https://github.com/tencent/Hunyuan3D-2">Github Page</a> &ensp;
218
+ <a href="http://3d-models.hunyuan.tencent.com">Homepage</a> &ensp;
219
+ <a href="#">Technical Report</a> &ensp;
220
+ <a href="https://huggingface.co/Tencent/Hunyuan3D-2"> Models</a> &ensp;
221
+ </div>
222
+ """
223
+
224
+ with gr.Blocks(theme=gr.themes.Base(), title='Hunyuan-3D-2.0') as demo:
225
+ gr.HTML(title_html)
226
+
227
+ with gr.Row():
228
+ with gr.Column(scale=2):
229
+ with gr.Tabs() as tabs_prompt:
230
+ with gr.Tab('Image Prompt', id='tab_img_prompt') as tab_ip:
231
+ image = gr.Image(label='Image', type='pil', image_mode='RGBA', height=290)
232
+ with gr.Row():
233
+ check_box_rembg = gr.Checkbox(value=True, label='Remove Background')
234
+
235
+ with gr.Tab('Text Prompt', id='tab_txt_prompt', visible=HAS_T2I) as tab_tp:
236
+ caption = gr.Textbox(label='Text Prompt',
237
+ placeholder='HunyuanDiT will be used to generate image.',
238
+ info='Example: A 3D model of a cute cat, white background')
239
+
240
+ with gr.Accordion('Advanced Options', open=False):
241
+ num_steps = gr.Slider(maximum=50, minimum=20, value=30, step=1, label='Inference Steps')
242
+ octree_resolution = gr.Dropdown([256, 384, 512], value=256, label='Octree Resolution')
243
+ cfg_scale = gr.Number(value=5.5, label='Guidance Scale')
244
+ seed = gr.Slider(maximum=1e7, minimum=0, value=1234, label='Seed')
245
+
246
+ with gr.Group():
247
+ btn = gr.Button(value='Generate Shape Only', variant='primary')
248
+ btn_all = gr.Button(value='Generate Shape and Texture', variant='primary', visible=HAS_TEXTUREGEN)
249
+
250
+ with gr.Group():
251
+ file_out = gr.File(label="File", visible=False)
252
+ file_out2 = gr.File(label="File", visible=False)
253
+
254
+ with gr.Column(scale=5):
255
+ with gr.Tabs():
256
+ with gr.Tab('Generated Mesh') as mesh1:
257
+ html_output1 = gr.HTML(HTML_OUTPUT_PLACEHOLDER, label='Output')
258
+ with gr.Tab('Generated Textured Mesh') as mesh2:
259
+ html_output2 = gr.HTML(HTML_OUTPUT_PLACEHOLDER, label='Output')
260
+
261
+ with gr.Column(scale=2):
262
+ with gr.Tabs() as gallery:
263
+ with gr.Tab('Image to 3D Gallery', id='tab_img_gallery') as tab_gi:
264
+ with gr.Row():
265
+ gr.Examples(examples=example_is, inputs=[image],
266
+ label="Image Prompts", examples_per_page=18)
267
+
268
+ with gr.Tab('Text to 3D Gallery', id='tab_txt_gallery', visible=HAS_T2I) as tab_gt:
269
+ with gr.Row():
270
+ gr.Examples(examples=example_ts, inputs=[caption],
271
+ label="Text Prompts", examples_per_page=18)
272
+
273
+ if not HAS_TEXTUREGEN:
274
+ gr.HTML("""
275
+ <div style="margin-top: 20px;">
276
+ <b>Warning: </b>
277
+ Texture synthesis is disable due to missing requirements,
278
+ please install requirements following README.md to activate it.
279
+ </div>
280
+ """)
281
+ if not args.enable_t23d:
282
+ gr.HTML("""
283
+ <div style="margin-top: 20px;">
284
+ <b>Warning: </b>
285
+ Text to 3D is disable. To activate it, please run `python gradio_app.py --enable_t23d`.
286
+ </div>
287
+ """)
288
+
289
+ tab_gi.select(fn=lambda: gr.update(selected='tab_img_prompt'), outputs=tabs_prompt)
290
+ if HAS_T2I:
291
+ tab_gt.select(fn=lambda: gr.update(selected='tab_txt_prompt'), outputs=tabs_prompt)
292
+
293
+ btn.click(
294
+ shape_generation,
295
+ inputs=[
296
+ caption,
297
+ image,
298
+ num_steps,
299
+ cfg_scale,
300
+ seed,
301
+ octree_resolution,
302
+ check_box_rembg,
303
+ ],
304
+ outputs=[file_out, html_output1]
305
+ ).then(
306
+ lambda: gr.update(visible=True),
307
+ outputs=[file_out],
308
+ )
309
+
310
+ btn_all.click(
311
+ generation_all,
312
+ inputs=[
313
+ caption,
314
+ image,
315
+ num_steps,
316
+ cfg_scale,
317
+ seed,
318
+ octree_resolution,
319
+ check_box_rembg,
320
+ ],
321
+ outputs=[file_out, file_out2, html_output1, html_output2]
322
+ ).then(
323
+ lambda: (gr.update(visible=True), gr.update(visible=True)),
324
+ outputs=[file_out, file_out2],
325
+ )
326
+
327
+ return demo
328
+
329
+
330
+ if __name__ == '__main__':
331
+ import argparse
332
+
333
+ parser = argparse.ArgumentParser()
334
+ parser.add_argument('--port', type=int, default=8080)
335
+ parser.add_argument('--host', type=str, default='0.0.0.0')
336
+ parser.add_argument('--cache-path', type=str, default='gradio_cache')
337
+ parser.add_argument('--enable_t23d', action='store_true')
338
+ args = parser.parse_args()
339
+
340
+ SAVE_DIR = args.cache_path
341
+ os.makedirs(SAVE_DIR, exist_ok=True)
342
+
343
+ CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
344
+
345
+ HTML_OUTPUT_PLACEHOLDER = """
346
+ <div style='height: 596px; width: 100%; border-radius: 8px; border-color: #e5e7eb; order-style: solid; border-width: 1px;'></div>
347
+ """
348
+
349
+ INPUT_MESH_HTML = """
350
+ <div style='height: 490px; width: 100%; border-radius: 8px;
351
+ border-color: #e5e7eb; order-style: solid; border-width: 1px;'>
352
+ </div>
353
+ """
354
+ example_is = get_example_img_list()
355
+ example_ts = get_example_txt_list()
356
+
357
+ try:
358
+ from hy3dgen.texgen import Hunyuan3DPaintPipeline
359
+
360
+ texgen_worker = Hunyuan3DPaintPipeline.from_pretrained('tencent/Hunyuan3D-2')
361
+ HAS_TEXTUREGEN = True
362
+ except Exception as e:
363
+ print(e)
364
+ print("Failed to load texture generator.")
365
+ print('Please try to install requirements by following README.md')
366
+ HAS_TEXTUREGEN = False
367
+
368
+ HAS_T2I = False
369
+ if args.enable_t23d:
370
+ from hy3dgen.text2image import HunyuanDiTPipeline
371
+
372
+ t2i_worker = HunyuanDiTPipeline('Tencent-Hunyuan/HunyuanDiT-v1.1-Diffusers-Distilled')
373
+ HAS_T2I = True
374
+
375
+ from hy3dgen.shapegen import FaceReducer, FloaterRemover, DegenerateFaceRemover, \
376
+ Hunyuan3DDiTFlowMatchingPipeline
377
+ from hy3dgen.rembg import BackgroundRemover
378
+
379
+ rmbg_worker = BackgroundRemover()
380
+ i23d_worker = Hunyuan3DDiTFlowMatchingPipeline.from_pretrained('tencent/Hunyuan3D-2')
381
+ floater_remove_worker = FloaterRemover()
382
+ degenerate_face_remove_worker = DegenerateFaceRemover()
383
+ face_reduce_worker = FaceReducer()
384
+
385
+ # https://discuss.huggingface.co/t/how-to-serve-an-html-file/33921/2
386
+ # create a FastAPI app
387
+ app = FastAPI()
388
+ # create a static directory to store the static files
389
+ static_dir = Path(SAVE_DIR).absolute()
390
+ static_dir.mkdir(parents=True, exist_ok=True)
391
+ app.mount("/static", StaticFiles(directory=static_dir, html=True), name="static")
392
+
393
+ demo = build_app()
394
+ app = gr.mount_gradio_app(app, demo, path="/")
395
+ uvicorn.run(app, host=args.host, port=args.port)
requirements.txt ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ninja
2
+ pybind11
3
+
4
+ diffusers
5
+ einops
6
+ opencv-python
7
+ numpy
8
+ torch
9
+ transformers
10
+ torchvision
11
+ #taming-transformers-rom1504
12
+ #ConfigArgParse
13
+ #ipdb
14
+ omegaconf
15
+
16
+ #sentencepiece
17
+ tqdm
18
+
19
+ # Mesh Processing
20
+ trimesh
21
+ pymeshlab
22
+ pygltflib
23
+ xatlas
24
+ #kornia
25
+ #facexlib
26
+
27
+ # Training
28
+ accelerate
29
+ #pytorch_lightning
30
+ #scikit-learn
31
+ #scikit-image
32
+
33
+ # Demo only
34
+ gradio
35
+ fastapi
36
+ uvicorn
37
+ rembg
38
+ onnxruntime
39
+ #gevent
40
+ #geventhttpclient