Spaces:
Running
on
Zero
Running
on
Zero
Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +1 -0
- .ipynb_checkpoints/README-checkpoint.md +201 -0
- .ipynb_checkpoints/gradio_app-checkpoint.py +392 -0
- .ipynb_checkpoints/hg_app-checkpoint.py +416 -0
- .ipynb_checkpoints/requirements-checkpoint.txt +35 -0
- assets/modelviewer-template.html +3 -2
- assets/modelviewer-textured-template.html +3 -2
- gradio_cache/0/input.png +0 -0
- gradio_cache/0/rembg.png +0 -0
- gradio_cache/0/textured_mesh.glb +3 -0
- gradio_cache/0/textured_mesh.html +40 -0
- gradio_cache/0/white_mesh.glb +0 -0
- gradio_cache/0/white_mesh.html +57 -0
- gradio_cache/1/input.png +0 -0
- gradio_cache/1/rembg.png +0 -0
- gradio_cache/1/textured_mesh.glb +3 -0
- gradio_cache/1/textured_mesh.html +40 -0
- gradio_cache/1/white_mesh.glb +0 -0
- gradio_cache/1/white_mesh.html +57 -0
- gradio_cache/2/input.png +0 -0
- gradio_cache/2/rembg.png +0 -0
- gradio_cache/2/white_mesh.glb +0 -0
- gradio_cache/2/white_mesh.html +57 -0
- gradio_cache/3/input.png +0 -0
- gradio_cache/3/rembg.png +0 -0
- gradio_cache/3/textured_mesh.glb +3 -0
- gradio_cache/3/textured_mesh.html +40 -0
- gradio_cache/3/white_mesh.glb +0 -0
- gradio_cache/3/white_mesh.html +57 -0
- gradio_cache/4/input.png +0 -0
- gradio_cache/4/rembg.png +0 -0
- gradio_cache/4/textured_mesh.glb +3 -0
- gradio_cache/4/textured_mesh.html +40 -0
- gradio_cache/4/white_mesh.glb +0 -0
- gradio_cache/4/white_mesh.html +57 -0
- hg_app.py +1 -1
- hy3dgen/.ipynb_checkpoints/text2image-checkpoint.py +92 -0
- hy3dgen/__pycache__/__init__.cpython-311.pyc +0 -0
- hy3dgen/__pycache__/rembg.cpython-311.pyc +0 -0
- hy3dgen/__pycache__/text2image.cpython-311.pyc +0 -0
- hy3dgen/shapegen/__pycache__/__init__.cpython-311.pyc +0 -0
- hy3dgen/shapegen/__pycache__/pipelines.cpython-311.pyc +0 -0
- hy3dgen/shapegen/__pycache__/postprocessors.cpython-311.pyc +0 -0
- hy3dgen/shapegen/__pycache__/preprocessors.cpython-311.pyc +0 -0
- hy3dgen/shapegen/__pycache__/schedulers.cpython-311.pyc +0 -0
- hy3dgen/shapegen/models/__pycache__/__init__.cpython-311.pyc +0 -0
- hy3dgen/shapegen/models/__pycache__/conditioner.cpython-311.pyc +0 -0
- hy3dgen/shapegen/models/__pycache__/hunyuan3ddit.cpython-311.pyc +0 -0
- hy3dgen/shapegen/models/__pycache__/vae.cpython-311.pyc +0 -0
- hy3dgen/texgen/__pycache__/__init__.cpython-311.pyc +0 -0
.gitattributes
CHANGED
@@ -43,3 +43,4 @@ gradio_cache/3/textured_mesh.glb filter=lfs diff=lfs merge=lfs -text
|
|
43 |
gradio_cache/4/textured_mesh.glb filter=lfs diff=lfs merge=lfs -text
|
44 |
gradio_cache/5/textured_mesh.glb filter=lfs diff=lfs merge=lfs -text
|
45 |
*.whl filter=lfs diff=lfs merge=lfs -text
|
|
|
|
43 |
gradio_cache/4/textured_mesh.glb filter=lfs diff=lfs merge=lfs -text
|
44 |
gradio_cache/5/textured_mesh.glb filter=lfs diff=lfs merge=lfs -text
|
45 |
*.whl filter=lfs diff=lfs merge=lfs -text
|
46 |
+
gradio_cache/1/textured_mesh.glb filter=lfs diff=lfs merge=lfs -text
|
.ipynb_checkpoints/README-checkpoint.md
ADDED
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Hunyuan3D-2.0
|
3 |
+
emoji: 🌍
|
4 |
+
colorFrom: purple
|
5 |
+
colorTo: red
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 4.44.1
|
8 |
+
app_file: hg_app.py
|
9 |
+
pinned: false
|
10 |
+
short_description: Text-to-3D and Image-to-3D Generation
|
11 |
+
---
|
12 |
+
|
13 |
+
[中文阅读](README_zh_cn.md)
|
14 |
+
|
15 |
+
<p align="center">
|
16 |
+
<img src="./assets/images/teaser.jpg">
|
17 |
+
|
18 |
+
|
19 |
+
</p>
|
20 |
+
|
21 |
+
<div align="center">
|
22 |
+
<a href=https://3d.hunyuan.tencent.com target="_blank"><img src=https://img.shields.io/badge/Hunyuan3D-black.svg?logo=homepage height=22px></a>
|
23 |
+
<a href=https://huggingface.co/spaces/tencent/Hunyuan3D-2 target="_blank"><img src=https://img.shields.io/badge/%F0%9F%A4%97%20Demo-276cb4.svg height=22px></a>
|
24 |
+
<a href=https://huggingface.co/tencent/Hunyuan3D-2 target="_blank"><img src=https://img.shields.io/badge/%F0%9F%A4%97%20Models-d96902.svg height=22px></a>
|
25 |
+
<a href=https://3d-models.hunyuan.tencent.com/ target="_blank"><img src= https://img.shields.io/badge/Page-bb8a2e.svg?logo=github height=22px></a>
|
26 |
+
<a href=https://discord.gg/GuaWYwzKbX target="_blank"><img src= https://img.shields.io/badge/Page-white.svg?logo=discord height=22px></a>
|
27 |
+
</div>
|
28 |
+
|
29 |
+
|
30 |
+
[//]: # ( <a href=# target="_blank"><img src=https://img.shields.io/badge/Report-b5212f.svg?logo=arxiv height=22px></a>)
|
31 |
+
|
32 |
+
[//]: # ( <a href=# target="_blank"><img src= https://img.shields.io/badge/Colab-8f2628.svg?logo=googlecolab height=22px></a>)
|
33 |
+
|
34 |
+
[//]: # ( <a href="#"><img alt="PyPI - Downloads" src="https://img.shields.io/pypi/v/mulankit?logo=pypi" height=22px></a>)
|
35 |
+
|
36 |
+
<br>
|
37 |
+
<p align="center">
|
38 |
+
“ Living out everyone’s imagination on creating and manipulating 3D assets.”
|
39 |
+
</p>
|
40 |
+
|
41 |
+
## 🔥 News
|
42 |
+
|
43 |
+
- Jan 21, 2025: 💬 Release [Hunyuan3D 2.0](https://huggingface.co/spaces/tencent/Hunyuan3D-2). Please give it a try!
|
44 |
+
|
45 |
+
## **Abstract**
|
46 |
+
|
47 |
+
We present Hunyuan3D 2.0, an advanced large-scale 3D synthesis system for generating high-resolution textured 3D assets.
|
48 |
+
This system includes two foundation components: a large-scale shape generation model - Hunyuan3D-DiT, and a large-scale
|
49 |
+
texture synthesis model - Hunyuan3D-Paint.
|
50 |
+
The shape generative model, built on a scalable flow-based diffusion transformer, aims to create geometry that properly
|
51 |
+
aligns with a given condition image, laying a solid foundation for downstream applications.
|
52 |
+
The texture synthesis model, benefiting from strong geometric and diffusion priors, produces high-resolution and vibrant
|
53 |
+
texture maps for either generated or hand-crafted meshes.
|
54 |
+
Furthermore, we build Hunyuan3D-Studio - a versatile, user-friendly production platform that simplifies the re-creation
|
55 |
+
process of 3D assets. It allows both professional and amateur users to manipulate or even animate their meshes
|
56 |
+
efficiently.
|
57 |
+
We systematically evaluate our models, showing that Hunyuan3D 2.0 outperforms previous state-of-the-art models,
|
58 |
+
including the open-source models and closed-source models in geometry details, condition alignment, texture quality, and
|
59 |
+
e.t.c.
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
+
<p align="center">
|
64 |
+
<img src="assets/images/system.jpg">
|
65 |
+
</p>
|
66 |
+
|
67 |
+
## ☯️ **Hunyuan3D 2.0**
|
68 |
+
|
69 |
+
### Architecture
|
70 |
+
|
71 |
+
Hunyuan3D 2.0 features a two-stage generation pipeline, starting with the creation of a bare mesh, followed by the
|
72 |
+
synthesis of a texture map for that mesh. This strategy is effective for decoupling the difficulties of shape and
|
73 |
+
texture generation and also provides flexibility for texturing either generated or handcrafted meshes.
|
74 |
+
|
75 |
+
<p align="left">
|
76 |
+
<img src="assets/images/arch.jpg">
|
77 |
+
</p>
|
78 |
+
|
79 |
+
### Performance
|
80 |
+
|
81 |
+
We have evaluated Hunyuan3D 2.0 with other open-source as well as close-source 3d-generation methods.
|
82 |
+
The numerical results indicate that Hunyuan3D 2.0 surpasses all baselines in the quality of generated textured 3D assets
|
83 |
+
and the condition following ability.
|
84 |
+
|
85 |
+
| Model | CMMD(⬇) | FID_CLIP(⬇) | FID(⬇) | CLIP-score(⬆) |
|
86 |
+
|-------------------------|-----------|-------------|-------------|---------------|
|
87 |
+
| Top Open-source Model1 | 3.591 | 54.639 | 289.287 | 0.787 |
|
88 |
+
| Top Close-source Model1 | 3.600 | 55.866 | 305.922 | 0.779 |
|
89 |
+
| Top Close-source Model2 | 3.368 | 49.744 | 294.628 | 0.806 |
|
90 |
+
| Top Close-source Model3 | 3.218 | 51.574 | 295.691 | 0.799 |
|
91 |
+
| Hunyuan3D 2.0 | **3.193** | **49.165** | **282.429** | **0.809** |
|
92 |
+
|
93 |
+
Generation results of Hunyuan3D 2.0:
|
94 |
+
<p align="left">
|
95 |
+
<img src="assets/images/e2e-1.gif" height=300>
|
96 |
+
<img src="assets/images/e2e-2.gif" height=300>
|
97 |
+
</p>
|
98 |
+
|
99 |
+
### Pretrained Models
|
100 |
+
|
101 |
+
| Model | Date | Huggingface |
|
102 |
+
|----------------------|------------|--------------------------------------------------------|
|
103 |
+
| Hunyuan3D-DiT-v2-0 | 2025-01-21 | [Download](https://huggingface.co/tencent/Hunyuan3D-2) |
|
104 |
+
| Hunyuan3D-Paint-v2-0 | 2025-01-21 | [Download](https://huggingface.co/tencent/Hunyuan3D-2) |
|
105 |
+
|
106 |
+
## 🤗 Get Started with Hunyuan3D 2.0
|
107 |
+
|
108 |
+
You may follow the next steps to use Hunyuan3D 2.0 via code or the Gradio App.
|
109 |
+
|
110 |
+
### Install Requirements
|
111 |
+
|
112 |
+
Please install Pytorch via the [official](https://pytorch.org/) site. Then install the other requirements via
|
113 |
+
|
114 |
+
```bash
|
115 |
+
pip install -r requirements.txt
|
116 |
+
# for texture
|
117 |
+
cd hy3dgen/texgen/custom_rasterizer
|
118 |
+
python3 setup.py install
|
119 |
+
cd hy3dgen/texgen/differentiable_renderer
|
120 |
+
bash compile_mesh_painter.sh
|
121 |
+
```
|
122 |
+
|
123 |
+
### API Usage
|
124 |
+
|
125 |
+
We designed a diffusers-like API to use our shape generation model - Hunyuan3D-DiT and texture synthesis model -
|
126 |
+
Hunyuan3D-Paint.
|
127 |
+
|
128 |
+
You could assess **Hunyuan3D-DiT** via:
|
129 |
+
|
130 |
+
```python
|
131 |
+
from hy3dgen.shapegen import Hunyuan3DDiTFlowMatchingPipeline
|
132 |
+
|
133 |
+
pipeline = Hunyuan3DDiTFlowMatchingPipeline.from_pretrained('tencent/Hunyuan3D-2')
|
134 |
+
mesh = pipeline(image='assets/demo.png')[0]
|
135 |
+
```
|
136 |
+
|
137 |
+
The output mesh is a [trimesh object](https://trimesh.org/trimesh.html), which you could save to glb/obj (or other
|
138 |
+
format) file.
|
139 |
+
|
140 |
+
For **Hunyuan3D-Paint**, do the following:
|
141 |
+
|
142 |
+
```python
|
143 |
+
from hy3dgen.texgen import Hunyuan3DPaintPipeline
|
144 |
+
from hy3dgen.shapegen import Hunyuan3DDiTFlowMatchingPipeline
|
145 |
+
|
146 |
+
# let's generate a mesh first
|
147 |
+
pipeline = Hunyuan3DDiTFlowMatchingPipeline.from_pretrained('tencent/Hunyuan3D-2')
|
148 |
+
mesh = pipeline(image='assets/demo.png')[0]
|
149 |
+
|
150 |
+
pipeline = Hunyuan3DPaintPipeline.from_pretrained('tencent/Hunyuan3D-2')
|
151 |
+
mesh = pipeline(mesh, image='assets/demo.png')
|
152 |
+
```
|
153 |
+
|
154 |
+
Please visit [minimal_demo.py](minimal_demo.py) for more advanced usage, such as **text to 3D** and **texture generation
|
155 |
+
for handcrafted mesh**.
|
156 |
+
|
157 |
+
### Gradio App
|
158 |
+
|
159 |
+
You could also host a [Gradio](https://www.gradio.app/) App in your own computer via:
|
160 |
+
|
161 |
+
```bash
|
162 |
+
pip3 install gradio==3.39.0
|
163 |
+
python3 gradio_app.py
|
164 |
+
```
|
165 |
+
|
166 |
+
Don't forget to visit [Hunyuan3D](https://3d.hunyuan.tencent.com) for quick use, if you don't want to host yourself.
|
167 |
+
|
168 |
+
## 📑 Open-Source Plan
|
169 |
+
|
170 |
+
- [x] Inference Code
|
171 |
+
- [x] Model Checkpoints
|
172 |
+
- [ ] ComfyUI
|
173 |
+
- [ ] TensorRT Version
|
174 |
+
|
175 |
+
## 🔗 BibTeX
|
176 |
+
|
177 |
+
If you found this repository helpful, please cite our report:
|
178 |
+
|
179 |
+
```bibtex
|
180 |
+
@misc{hunyuan3d22025tencent,
|
181 |
+
title={Hunyuan3D 2.0: Scaling Diffusion Models for High Resolution Textured 3D Assets Generation},
|
182 |
+
author={Tencent Hunyuan3D Team},
|
183 |
+
year={2025},
|
184 |
+
}
|
185 |
+
```
|
186 |
+
|
187 |
+
## Acknowledgements
|
188 |
+
|
189 |
+
We would like to thank the contributors to
|
190 |
+
the [DINOv2](https://github.com/facebookresearch/dinov2), [Stable Diffusion](https://github.com/Stability-AI/stablediffusion), [FLUX](https://github.com/black-forest-labs/flux), [diffusers](https://github.com/huggingface/diffusers)
|
191 |
+
and [HuggingFace](https://huggingface.co) repositories, for their open research and exploration.
|
192 |
+
|
193 |
+
## Star History
|
194 |
+
|
195 |
+
<a href="https://star-history.com/#Tencent/Hunyuan3D-2&Date">
|
196 |
+
<picture>
|
197 |
+
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=Tencent/Hunyuan3D-2&type=Date&theme=dark" />
|
198 |
+
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=Tencent/Hunyuan3D-2&type=Date" />
|
199 |
+
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=Tencent/Hunyuan3D-2&type=Date" />
|
200 |
+
</picture>
|
201 |
+
</a>
|
.ipynb_checkpoints/gradio_app-checkpoint.py
ADDED
@@ -0,0 +1,392 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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'):
|
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 not _.startswith("."))
|
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 |
+
if textured:
|
51 |
+
related_path = f"./textured_mesh.glb"
|
52 |
+
template_name = './assets/modelviewer-textured-template.html'
|
53 |
+
output_html_path = os.path.join(save_folder, f'textured_mesh.html')
|
54 |
+
else:
|
55 |
+
related_path = f"./white_mesh.glb"
|
56 |
+
template_name = './assets/modelviewer-template.html'
|
57 |
+
output_html_path = os.path.join(save_folder, f'white_mesh.html')
|
58 |
+
|
59 |
+
with open(os.path.join(CURRENT_DIR, template_name), 'r') as f:
|
60 |
+
template_html = f.read()
|
61 |
+
obj_html = f"""
|
62 |
+
<div class="column is-mobile is-centered">
|
63 |
+
<model-viewer style="height: {height - 10}px; width: {width}px;" rotation-per-second="10deg" id="modelViewer"
|
64 |
+
src="{related_path}/" disable-tap
|
65 |
+
environment-image="neutral" auto-rotate camera-target="0m 0m 0m" orientation="0deg 0deg 170deg" shadow-intensity=".9"
|
66 |
+
ar auto-rotate camera-controls>
|
67 |
+
</model-viewer>
|
68 |
+
</div>
|
69 |
+
"""
|
70 |
+
|
71 |
+
with open(output_html_path, 'w') as f:
|
72 |
+
f.write(template_html.replace('<model-viewer>', obj_html))
|
73 |
+
|
74 |
+
output_html_path = output_html_path.replace(SAVE_DIR + '/', '')
|
75 |
+
iframe_tag = f'<iframe src="/static/{output_html_path}" height="{height}" width="100%" frameborder="0"></iframe>'
|
76 |
+
print(f'Find html {output_html_path}, {os.path.exists(output_html_path)}')
|
77 |
+
|
78 |
+
return f"""
|
79 |
+
<div style='height: {height}; width: 100%;'>
|
80 |
+
{iframe_tag}
|
81 |
+
</div>
|
82 |
+
"""
|
83 |
+
|
84 |
+
|
85 |
+
def _gen_shape(
|
86 |
+
caption,
|
87 |
+
image,
|
88 |
+
steps=50,
|
89 |
+
guidance_scale=7.5,
|
90 |
+
seed=1234,
|
91 |
+
octree_resolution=256,
|
92 |
+
check_box_rembg=False,
|
93 |
+
):
|
94 |
+
if caption: print('prompt is', caption)
|
95 |
+
save_folder = gen_save_folder()
|
96 |
+
stats = {}
|
97 |
+
time_meta = {}
|
98 |
+
start_time_0 = time.time()
|
99 |
+
|
100 |
+
if image is None:
|
101 |
+
start_time = time.time()
|
102 |
+
try:
|
103 |
+
image = t2i_worker(caption)
|
104 |
+
except Exception as e:
|
105 |
+
raise gr.Error(f"Text to 3D is disable. Please enable it by `python gradio_app.py --enable_t23d`.")
|
106 |
+
time_meta['text2image'] = time.time() - start_time
|
107 |
+
|
108 |
+
image.save(os.path.join(save_folder, 'input.png'))
|
109 |
+
|
110 |
+
print(image.mode)
|
111 |
+
if check_box_rembg or image.mode == "RGB":
|
112 |
+
start_time = time.time()
|
113 |
+
image = rmbg_worker(image.convert('RGB'))
|
114 |
+
time_meta['rembg'] = time.time() - start_time
|
115 |
+
|
116 |
+
image.save(os.path.join(save_folder, 'rembg.png'))
|
117 |
+
|
118 |
+
# image to white model
|
119 |
+
start_time = time.time()
|
120 |
+
|
121 |
+
generator = torch.Generator()
|
122 |
+
generator = generator.manual_seed(int(seed))
|
123 |
+
mesh = i23d_worker(
|
124 |
+
image=image,
|
125 |
+
num_inference_steps=steps,
|
126 |
+
guidance_scale=guidance_scale,
|
127 |
+
generator=generator,
|
128 |
+
octree_resolution=octree_resolution
|
129 |
+
)[0]
|
130 |
+
|
131 |
+
mesh = FloaterRemover()(mesh)
|
132 |
+
mesh = DegenerateFaceRemover()(mesh)
|
133 |
+
mesh = FaceReducer()(mesh)
|
134 |
+
|
135 |
+
stats['number_of_faces'] = mesh.faces.shape[0]
|
136 |
+
stats['number_of_vertices'] = mesh.vertices.shape[0]
|
137 |
+
|
138 |
+
time_meta['image_to_textured_3d'] = {'total': time.time() - start_time}
|
139 |
+
time_meta['total'] = time.time() - start_time_0
|
140 |
+
stats['time'] = time_meta
|
141 |
+
return mesh, save_folder
|
142 |
+
|
143 |
+
|
144 |
+
def generation_all(
|
145 |
+
caption,
|
146 |
+
image,
|
147 |
+
steps=50,
|
148 |
+
guidance_scale=7.5,
|
149 |
+
seed=1234,
|
150 |
+
octree_resolution=256,
|
151 |
+
check_box_rembg=False
|
152 |
+
):
|
153 |
+
mesh, save_folder = _gen_shape(
|
154 |
+
caption,
|
155 |
+
image,
|
156 |
+
steps=steps,
|
157 |
+
guidance_scale=guidance_scale,
|
158 |
+
seed=seed,
|
159 |
+
octree_resolution=octree_resolution,
|
160 |
+
check_box_rembg=check_box_rembg
|
161 |
+
)
|
162 |
+
path = export_mesh(mesh, save_folder, textured=False)
|
163 |
+
model_viewer_html = build_model_viewer_html(save_folder, height=596, width=700)
|
164 |
+
|
165 |
+
textured_mesh = texgen_worker(mesh, image)
|
166 |
+
path_textured = export_mesh(textured_mesh, save_folder, textured=True)
|
167 |
+
model_viewer_html_textured = build_model_viewer_html(save_folder, height=596, width=700, textured=True)
|
168 |
+
|
169 |
+
return (
|
170 |
+
gr.update(value=path, visible=True),
|
171 |
+
gr.update(value=path_textured, visible=True),
|
172 |
+
model_viewer_html,
|
173 |
+
model_viewer_html_textured,
|
174 |
+
)
|
175 |
+
|
176 |
+
|
177 |
+
def shape_generation(
|
178 |
+
caption,
|
179 |
+
image,
|
180 |
+
steps=50,
|
181 |
+
guidance_scale=7.5,
|
182 |
+
seed=1234,
|
183 |
+
octree_resolution=256,
|
184 |
+
check_box_rembg=False,
|
185 |
+
):
|
186 |
+
mesh, save_folder = _gen_shape(
|
187 |
+
caption,
|
188 |
+
image,
|
189 |
+
steps=steps,
|
190 |
+
guidance_scale=guidance_scale,
|
191 |
+
seed=seed,
|
192 |
+
octree_resolution=octree_resolution,
|
193 |
+
check_box_rembg=check_box_rembg
|
194 |
+
)
|
195 |
+
|
196 |
+
path = export_mesh(mesh, save_folder, textured=False)
|
197 |
+
model_viewer_html = build_model_viewer_html(save_folder, height=596, width=700)
|
198 |
+
|
199 |
+
return (
|
200 |
+
gr.update(value=path, visible=True),
|
201 |
+
model_viewer_html,
|
202 |
+
)
|
203 |
+
|
204 |
+
|
205 |
+
def build_app():
|
206 |
+
title_html = """
|
207 |
+
<div style="font-size: 2em; font-weight: bold; text-align: center; margin-bottom: 5px">
|
208 |
+
|
209 |
+
Hunyuan3D-2: Scaling Diffusion Models for High Resolution Textured 3D Assets Generation
|
210 |
+
</div>
|
211 |
+
<div align="center">
|
212 |
+
Tencent Hunyuan3D Team
|
213 |
+
</div>
|
214 |
+
<div align="center">
|
215 |
+
<a href="https://github.com/tencent/Hunyuan3D-2">Github Page</a>  
|
216 |
+
<a href="http://3d-models.hunyuan.tencent.com">Homepage</a>  
|
217 |
+
<a href="#">Technical Report</a>  
|
218 |
+
<a href="https://huggingface.co/Tencent/Hunyuan3D-2"> Models</a>  
|
219 |
+
</div>
|
220 |
+
"""
|
221 |
+
|
222 |
+
with gr.Blocks(theme=gr.themes.Base(), title='Hunyuan-3D-2.0') as demo:
|
223 |
+
gr.HTML(title_html)
|
224 |
+
|
225 |
+
with gr.Row():
|
226 |
+
with gr.Column(scale=2):
|
227 |
+
with gr.Tabs() as tabs_prompt:
|
228 |
+
with gr.Tab('Image Prompt', id='tab_img_prompt') as tab_ip:
|
229 |
+
image = gr.Image(label='Image', type='pil', image_mode='RGBA', height=290)
|
230 |
+
with gr.Row():
|
231 |
+
check_box_rembg = gr.Checkbox(value=True, label='Remove Background')
|
232 |
+
|
233 |
+
with gr.Tab('Text Prompt', id='tab_txt_prompt', visible=HAS_T2I) as tab_tp:
|
234 |
+
caption = gr.Textbox(label='Text Prompt',
|
235 |
+
placeholder='HunyuanDiT will be used to generate image.',
|
236 |
+
info='Example: A 3D model of a cute cat, white background')
|
237 |
+
|
238 |
+
with gr.Accordion('Advanced Options', open=False):
|
239 |
+
num_steps = gr.Slider(maximum=50, minimum=20, value=30, step=1, label='Inference Steps')
|
240 |
+
octree_resolution = gr.Dropdown([256, 384, 512], value=256, label='Octree Resolution')
|
241 |
+
cfg_scale = gr.Number(value=5.5, label='Guidance Scale')
|
242 |
+
seed = gr.Slider(maximum=1e7, minimum=0, value=1234, label='Seed')
|
243 |
+
|
244 |
+
with gr.Group():
|
245 |
+
btn = gr.Button(value='Generate Shape Only', variant='primary')
|
246 |
+
btn_all = gr.Button(value='Generate Shape and Texture', variant='primary', visible=HAS_TEXTUREGEN)
|
247 |
+
|
248 |
+
with gr.Group():
|
249 |
+
file_out = gr.File(label="File", visible=False)
|
250 |
+
file_out2 = gr.File(label="File", visible=False)
|
251 |
+
|
252 |
+
with gr.Column(scale=5):
|
253 |
+
with gr.Tabs():
|
254 |
+
with gr.Tab('Generated Mesh') as mesh1:
|
255 |
+
html_output1 = gr.HTML(HTML_OUTPUT_PLACEHOLDER, label='Output')
|
256 |
+
with gr.Tab('Generated Textured Mesh') as mesh2:
|
257 |
+
html_output2 = gr.HTML(HTML_OUTPUT_PLACEHOLDER, label='Output')
|
258 |
+
|
259 |
+
with gr.Column(scale=2):
|
260 |
+
with gr.Tabs() as gallery:
|
261 |
+
with gr.Tab('Image to 3D Gallery', id='tab_img_gallery') as tab_gi:
|
262 |
+
with gr.Row():
|
263 |
+
gr.Examples(examples=example_is, inputs=[image],
|
264 |
+
label="Image Prompts", examples_per_page=18)
|
265 |
+
|
266 |
+
with gr.Tab('Text to 3D Gallery', id='tab_txt_gallery', visible=HAS_T2I) as tab_gt:
|
267 |
+
with gr.Row():
|
268 |
+
gr.Examples(examples=example_ts, inputs=[caption],
|
269 |
+
label="Text Prompts", examples_per_page=18)
|
270 |
+
|
271 |
+
if not HAS_TEXTUREGEN:
|
272 |
+
gr.HTML(""")
|
273 |
+
<div style="margin-top: 20px;">
|
274 |
+
<b>Warning: </b>
|
275 |
+
Texture synthesis is disable due to missing requirements,
|
276 |
+
please install requirements following README.md to activate it.
|
277 |
+
</div>
|
278 |
+
""")
|
279 |
+
if not args.enable_t23d:
|
280 |
+
gr.HTML("""
|
281 |
+
<div style="margin-top: 20px;">
|
282 |
+
<b>Warning: </b>
|
283 |
+
Text to 3D is disable. To activate it, please run `python gradio_app.py --enable_t23d`.
|
284 |
+
</div>
|
285 |
+
""")
|
286 |
+
|
287 |
+
tab_gi.select(fn=lambda: gr.update(selected='tab_img_prompt'), outputs=tabs_prompt)
|
288 |
+
if HAS_T2I:
|
289 |
+
tab_gt.select(fn=lambda: gr.update(selected='tab_txt_prompt'), outputs=tabs_prompt)
|
290 |
+
|
291 |
+
btn.click(
|
292 |
+
shape_generation,
|
293 |
+
inputs=[
|
294 |
+
caption,
|
295 |
+
image,
|
296 |
+
num_steps,
|
297 |
+
cfg_scale,
|
298 |
+
seed,
|
299 |
+
octree_resolution,
|
300 |
+
check_box_rembg,
|
301 |
+
],
|
302 |
+
outputs=[file_out, html_output1]
|
303 |
+
).then(
|
304 |
+
lambda: gr.update(visible=True),
|
305 |
+
outputs=[file_out],
|
306 |
+
)
|
307 |
+
|
308 |
+
btn_all.click(
|
309 |
+
generation_all,
|
310 |
+
inputs=[
|
311 |
+
caption,
|
312 |
+
image,
|
313 |
+
num_steps,
|
314 |
+
cfg_scale,
|
315 |
+
seed,
|
316 |
+
octree_resolution,
|
317 |
+
check_box_rembg,
|
318 |
+
],
|
319 |
+
outputs=[file_out, file_out2, html_output1, html_output2]
|
320 |
+
).then(
|
321 |
+
lambda: (gr.update(visible=True), gr.update(visible=True)),
|
322 |
+
outputs=[file_out, file_out2],
|
323 |
+
)
|
324 |
+
|
325 |
+
return demo
|
326 |
+
|
327 |
+
|
328 |
+
if __name__ == '__main__':
|
329 |
+
import argparse
|
330 |
+
|
331 |
+
parser = argparse.ArgumentParser()
|
332 |
+
parser.add_argument('--port', type=int, default=8080)
|
333 |
+
parser.add_argument('--cache-path', type=str, default='gradio_cache')
|
334 |
+
parser.add_argument('--enable_t23d', action='store_true')
|
335 |
+
args = parser.parse_args()
|
336 |
+
|
337 |
+
SAVE_DIR = args.cache_path
|
338 |
+
os.makedirs(SAVE_DIR, exist_ok=True)
|
339 |
+
|
340 |
+
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
341 |
+
|
342 |
+
HTML_OUTPUT_PLACEHOLDER = """
|
343 |
+
<div style='height: 596px; width: 100%; border-radius: 8px; border-color: #e5e7eb; order-style: solid; border-width: 1px;'></div>
|
344 |
+
"""
|
345 |
+
|
346 |
+
INPUT_MESH_HTML = """
|
347 |
+
<div style='height: 490px; width: 100%; border-radius: 8px;
|
348 |
+
border-color: #e5e7eb; order-style: solid; border-width: 1px;'>
|
349 |
+
</div>
|
350 |
+
"""
|
351 |
+
example_is = get_example_img_list()
|
352 |
+
example_ts = get_example_txt_list()
|
353 |
+
|
354 |
+
try:
|
355 |
+
from hy3dgen.texgen import Hunyuan3DPaintPipeline
|
356 |
+
|
357 |
+
texgen_worker = Hunyuan3DPaintPipeline.from_pretrained('tencent/Hunyuan3D-2')
|
358 |
+
HAS_TEXTUREGEN = True
|
359 |
+
except Exception as e:
|
360 |
+
print(e)
|
361 |
+
print("Failed to load texture generator.")
|
362 |
+
print('Please try to install requirements by following README.md')
|
363 |
+
HAS_TEXTUREGEN = False
|
364 |
+
|
365 |
+
HAS_T2I = False
|
366 |
+
if args.enable_t23d:
|
367 |
+
from hy3dgen.text2image import HunyuanDiTPipeline
|
368 |
+
|
369 |
+
t2i_worker = HunyuanDiTPipeline('Tencent-Hunyuan/HunyuanDiT-v1.1-Diffusers-Distilled')
|
370 |
+
HAS_T2I = True
|
371 |
+
|
372 |
+
from hy3dgen.shapegen import FaceReducer, FloaterRemover, DegenerateFaceRemover, \
|
373 |
+
Hunyuan3DDiTFlowMatchingPipeline
|
374 |
+
from hy3dgen.rembg import BackgroundRemover
|
375 |
+
|
376 |
+
rmbg_worker = BackgroundRemover()
|
377 |
+
i23d_worker = Hunyuan3DDiTFlowMatchingPipeline.from_pretrained('tencent/Hunyuan3D-2')
|
378 |
+
floater_remove_worker = FloaterRemover()
|
379 |
+
degenerate_face_remove_worker = DegenerateFaceRemover()
|
380 |
+
face_reduce_worker = FaceReducer()
|
381 |
+
|
382 |
+
# https://discuss.huggingface.co/t/how-to-serve-an-html-file/33921/2
|
383 |
+
# create a FastAPI app
|
384 |
+
app = FastAPI()
|
385 |
+
# create a static directory to store the static files
|
386 |
+
static_dir = Path('./gradio_cache')
|
387 |
+
static_dir.mkdir(parents=True, exist_ok=True)
|
388 |
+
app.mount("/static", StaticFiles(directory=static_dir), name="static")
|
389 |
+
|
390 |
+
demo = build_app()
|
391 |
+
app = gr.mount_gradio_app(app, demo, path="/")
|
392 |
+
uvicorn.run(app, host="0.0.0.0", port=args.port)
|
.ipynb_checkpoints/hg_app-checkpoint.py
ADDED
@@ -0,0 +1,416 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import spaces
|
3 |
+
import subprocess
|
4 |
+
def install_cuda_toolkit():
|
5 |
+
# CUDA_TOOLKIT_URL = "https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run"
|
6 |
+
CUDA_TOOLKIT_URL = "https://developer.download.nvidia.com/compute/cuda/12.2.0/local_installers/cuda_12.2.0_535.54.03_linux.run"
|
7 |
+
CUDA_TOOLKIT_FILE = "/tmp/%s" % os.path.basename(CUDA_TOOLKIT_URL)
|
8 |
+
subprocess.call(["wget", "-q", CUDA_TOOLKIT_URL, "-O", CUDA_TOOLKIT_FILE])
|
9 |
+
subprocess.call(["chmod", "+x", CUDA_TOOLKIT_FILE])
|
10 |
+
subprocess.call([CUDA_TOOLKIT_FILE, "--silent", "--toolkit"])
|
11 |
+
|
12 |
+
os.environ["CUDA_HOME"] = "/usr/local/cuda"
|
13 |
+
os.environ["PATH"] = "%s/bin:%s" % (os.environ["CUDA_HOME"], os.environ["PATH"])
|
14 |
+
os.environ["LD_LIBRARY_PATH"] = "%s/lib:%s" % (
|
15 |
+
os.environ["CUDA_HOME"],
|
16 |
+
"" if "LD_LIBRARY_PATH" not in os.environ else os.environ["LD_LIBRARY_PATH"],
|
17 |
+
)
|
18 |
+
# Fix: arch_list[-1] += '+PTX'; IndexError: list index out of range
|
19 |
+
os.environ["TORCH_CUDA_ARCH_LIST"] = "8.0;8.6"
|
20 |
+
|
21 |
+
install_cuda_toolkit()
|
22 |
+
os.system("cd /home/user/app/hy3dgen/texgen/differentiable_renderer/ && bash compile_mesh_painter.sh")
|
23 |
+
os.system("cd /home/user/app/hy3dgen/texgen/custom_rasterizer && pip install .")
|
24 |
+
|
25 |
+
import os
|
26 |
+
import shutil
|
27 |
+
import time
|
28 |
+
from glob import glob
|
29 |
+
from pathlib import Path
|
30 |
+
|
31 |
+
import gradio as gr
|
32 |
+
import torch
|
33 |
+
import uvicorn
|
34 |
+
from fastapi import FastAPI
|
35 |
+
from fastapi.staticfiles import StaticFiles
|
36 |
+
|
37 |
+
|
38 |
+
def get_example_img_list():
|
39 |
+
print('Loading example img list ...')
|
40 |
+
return sorted(glob('./assets/example_images/*.png'))
|
41 |
+
|
42 |
+
|
43 |
+
def get_example_txt_list():
|
44 |
+
print('Loading example txt list ...')
|
45 |
+
txt_list = list()
|
46 |
+
for line in open('./assets/example_prompts.txt'):
|
47 |
+
txt_list.append(line.strip())
|
48 |
+
return txt_list
|
49 |
+
|
50 |
+
|
51 |
+
def gen_save_folder(max_size=60):
|
52 |
+
os.makedirs(SAVE_DIR, exist_ok=True)
|
53 |
+
exists = set(int(_) for _ in os.listdir(SAVE_DIR) if not _.startswith("."))
|
54 |
+
cur_id = min(set(range(max_size)) - exists) if len(exists) < max_size else -1
|
55 |
+
if os.path.exists(f"{SAVE_DIR}/{(cur_id + 1) % max_size}"):
|
56 |
+
shutil.rmtree(f"{SAVE_DIR}/{(cur_id + 1) % max_size}")
|
57 |
+
print(f"remove {SAVE_DIR}/{(cur_id + 1) % max_size} success !!!")
|
58 |
+
save_folder = f"{SAVE_DIR}/{max(0, cur_id)}"
|
59 |
+
os.makedirs(save_folder, exist_ok=True)
|
60 |
+
print(f"mkdir {save_folder} suceess !!!")
|
61 |
+
return save_folder
|
62 |
+
|
63 |
+
|
64 |
+
def export_mesh(mesh, save_folder, textured=False):
|
65 |
+
if textured:
|
66 |
+
path = os.path.join(save_folder, f'textured_mesh.glb')
|
67 |
+
else:
|
68 |
+
path = os.path.join(save_folder, f'white_mesh.glb')
|
69 |
+
mesh.export(path, include_normals=textured)
|
70 |
+
return path
|
71 |
+
|
72 |
+
|
73 |
+
def build_model_viewer_html(save_folder, height=660, width=790, textured=False):
|
74 |
+
if textured:
|
75 |
+
related_path = f"./textured_mesh.glb"
|
76 |
+
template_name = './assets/modelviewer-textured-template.html'
|
77 |
+
output_html_path = os.path.join(save_folder, f'textured_mesh.html')
|
78 |
+
else:
|
79 |
+
related_path = f"./white_mesh.glb"
|
80 |
+
template_name = './assets/modelviewer-template.html'
|
81 |
+
output_html_path = os.path.join(save_folder, f'white_mesh.html')
|
82 |
+
|
83 |
+
with open(os.path.join(CURRENT_DIR, template_name), 'r') as f:
|
84 |
+
template_html = f.read()
|
85 |
+
obj_html = f"""
|
86 |
+
<div class="column is-mobile is-centered">
|
87 |
+
<model-viewer style="height: {height - 10}px; width: {width}px;" rotation-per-second="10deg" id="modelViewer"
|
88 |
+
src="{related_path}/" disable-tap
|
89 |
+
environment-image="neutral" auto-rotate camera-target="0m 0m 0m" orientation="0deg 0deg 170deg" shadow-intensity=".9"
|
90 |
+
ar auto-rotate camera-controls>
|
91 |
+
</model-viewer>
|
92 |
+
</div>
|
93 |
+
"""
|
94 |
+
|
95 |
+
with open(output_html_path, 'w') as f:
|
96 |
+
f.write(template_html.replace('<model-viewer>', obj_html))
|
97 |
+
|
98 |
+
output_html_path = output_html_path.replace(SAVE_DIR + '/', '')
|
99 |
+
iframe_tag = f'<iframe src="/static/{output_html_path}" height="{height}" width="100%" frameborder="0"></iframe>'
|
100 |
+
print(f'Find html {output_html_path}, {os.path.exists(output_html_path)}')
|
101 |
+
|
102 |
+
return f"""
|
103 |
+
<div style='height: {height}; width: 100%;'>
|
104 |
+
{iframe_tag}
|
105 |
+
</div>
|
106 |
+
"""
|
107 |
+
|
108 |
+
@spaces.GPU(duration=40)
|
109 |
+
def _gen_shape(
|
110 |
+
caption,
|
111 |
+
image,
|
112 |
+
steps=50,
|
113 |
+
guidance_scale=7.5,
|
114 |
+
seed=1234,
|
115 |
+
octree_resolution=256,
|
116 |
+
check_box_rembg=False,
|
117 |
+
):
|
118 |
+
if caption: print('prompt is', caption)
|
119 |
+
save_folder = gen_save_folder()
|
120 |
+
stats = {}
|
121 |
+
time_meta = {}
|
122 |
+
start_time_0 = time.time()
|
123 |
+
|
124 |
+
if image is None:
|
125 |
+
start_time = time.time()
|
126 |
+
try:
|
127 |
+
image = t2i_worker(caption)
|
128 |
+
except Exception as e:
|
129 |
+
raise gr.Error(f"Text to 3D is disable. Please enable it by `python gradio_app.py --enable_t23d`.")
|
130 |
+
time_meta['text2image'] = time.time() - start_time
|
131 |
+
|
132 |
+
image.save(os.path.join(save_folder, 'input.png'))
|
133 |
+
|
134 |
+
print(image.mode)
|
135 |
+
if check_box_rembg or image.mode == "RGB":
|
136 |
+
start_time = time.time()
|
137 |
+
image = rmbg_worker(image.convert('RGB'))
|
138 |
+
time_meta['rembg'] = time.time() - start_time
|
139 |
+
|
140 |
+
image.save(os.path.join(save_folder, 'rembg.png'))
|
141 |
+
|
142 |
+
# image to white model
|
143 |
+
start_time = time.time()
|
144 |
+
|
145 |
+
generator = torch.Generator()
|
146 |
+
generator = generator.manual_seed(int(seed))
|
147 |
+
mesh = i23d_worker(
|
148 |
+
image=image,
|
149 |
+
num_inference_steps=steps,
|
150 |
+
guidance_scale=guidance_scale,
|
151 |
+
generator=generator,
|
152 |
+
octree_resolution=octree_resolution
|
153 |
+
)[0]
|
154 |
+
|
155 |
+
mesh = FloaterRemover()(mesh)
|
156 |
+
mesh = DegenerateFaceRemover()(mesh)
|
157 |
+
mesh = FaceReducer()(mesh)
|
158 |
+
|
159 |
+
stats['number_of_faces'] = mesh.faces.shape[0]
|
160 |
+
stats['number_of_vertices'] = mesh.vertices.shape[0]
|
161 |
+
|
162 |
+
time_meta['image_to_textured_3d'] = {'total': time.time() - start_time}
|
163 |
+
time_meta['total'] = time.time() - start_time_0
|
164 |
+
stats['time'] = time_meta
|
165 |
+
return mesh, save_folder
|
166 |
+
|
167 |
+
@spaces.GPU(duration=60)
|
168 |
+
def generation_all(
|
169 |
+
caption,
|
170 |
+
image,
|
171 |
+
steps=50,
|
172 |
+
guidance_scale=7.5,
|
173 |
+
seed=1234,
|
174 |
+
octree_resolution=256,
|
175 |
+
check_box_rembg=False
|
176 |
+
):
|
177 |
+
mesh, save_folder = _gen_shape(
|
178 |
+
caption,
|
179 |
+
image,
|
180 |
+
steps=steps,
|
181 |
+
guidance_scale=guidance_scale,
|
182 |
+
seed=seed,
|
183 |
+
octree_resolution=octree_resolution,
|
184 |
+
check_box_rembg=check_box_rembg
|
185 |
+
)
|
186 |
+
path = export_mesh(mesh, save_folder, textured=False)
|
187 |
+
model_viewer_html = build_model_viewer_html(save_folder, height=596, width=700)
|
188 |
+
|
189 |
+
textured_mesh = texgen_worker(mesh, image)
|
190 |
+
path_textured = export_mesh(textured_mesh, save_folder, textured=True)
|
191 |
+
model_viewer_html_textured = build_model_viewer_html(save_folder, height=596, width=700, textured=True)
|
192 |
+
|
193 |
+
return (
|
194 |
+
gr.update(value=path, visible=True),
|
195 |
+
gr.update(value=path_textured, visible=True),
|
196 |
+
model_viewer_html,
|
197 |
+
model_viewer_html_textured,
|
198 |
+
)
|
199 |
+
|
200 |
+
@spaces.GPU(duration=40)
|
201 |
+
def shape_generation(
|
202 |
+
caption,
|
203 |
+
image,
|
204 |
+
steps=50,
|
205 |
+
guidance_scale=7.5,
|
206 |
+
seed=1234,
|
207 |
+
octree_resolution=256,
|
208 |
+
check_box_rembg=False,
|
209 |
+
):
|
210 |
+
mesh, save_folder = _gen_shape(
|
211 |
+
caption,
|
212 |
+
image,
|
213 |
+
steps=steps,
|
214 |
+
guidance_scale=guidance_scale,
|
215 |
+
seed=seed,
|
216 |
+
octree_resolution=octree_resolution,
|
217 |
+
check_box_rembg=check_box_rembg
|
218 |
+
)
|
219 |
+
|
220 |
+
path = export_mesh(mesh, save_folder, textured=False)
|
221 |
+
model_viewer_html = build_model_viewer_html(save_folder, height=596, width=700)
|
222 |
+
|
223 |
+
return (
|
224 |
+
gr.update(value=path, visible=True),
|
225 |
+
model_viewer_html,
|
226 |
+
)
|
227 |
+
|
228 |
+
|
229 |
+
def build_app():
|
230 |
+
title_html = """
|
231 |
+
<div style="font-size: 2em; font-weight: bold; text-align: center; margin-bottom: 5px">
|
232 |
+
|
233 |
+
Hunyuan3D-2: Scaling Diffusion Models for High Resolution Textured 3D Assets Generation
|
234 |
+
</div>
|
235 |
+
<div align="center">
|
236 |
+
Tencent Hunyuan3D Team
|
237 |
+
</div>
|
238 |
+
<div align="center">
|
239 |
+
<a href="https://github.com/tencent/Hunyuan3D-2">Github Page</a>  
|
240 |
+
<a href="http://3d-models.hunyuan.tencent.com">Homepage</a>  
|
241 |
+
<a href="#">Technical Report</a>  
|
242 |
+
<a href="https://huggingface.co/Tencent/Hunyuan3D-2"> Models</a>  
|
243 |
+
</div>
|
244 |
+
"""
|
245 |
+
|
246 |
+
with gr.Blocks(theme=gr.themes.Base(), title='Hunyuan-3D-2.0') as demo:
|
247 |
+
gr.HTML(title_html)
|
248 |
+
|
249 |
+
with gr.Row():
|
250 |
+
with gr.Column(scale=2):
|
251 |
+
with gr.Tabs() as tabs_prompt:
|
252 |
+
with gr.Tab('Image Prompt', id='tab_img_prompt') as tab_ip:
|
253 |
+
image = gr.Image(label='Image', type='pil', image_mode='RGBA', height=290)
|
254 |
+
with gr.Row():
|
255 |
+
check_box_rembg = gr.Checkbox(value=True, label='Remove Background')
|
256 |
+
|
257 |
+
with gr.Tab('Text Prompt', id='tab_txt_prompt', visible=HAS_T2I) as tab_tp:
|
258 |
+
caption = gr.Textbox(label='Text Prompt',
|
259 |
+
placeholder='HunyuanDiT will be used to generate image.',
|
260 |
+
info='Example: A 3D model of a cute cat, white background')
|
261 |
+
|
262 |
+
with gr.Accordion('Advanced Options', open=False):
|
263 |
+
num_steps = gr.Slider(maximum=50, minimum=20, value=30, step=1, label='Inference Steps')
|
264 |
+
octree_resolution = gr.Dropdown([256, 384, 512], value=256, label='Octree Resolution')
|
265 |
+
cfg_scale = gr.Number(value=5.5, label='Guidance Scale')
|
266 |
+
seed = gr.Slider(maximum=1e7, minimum=0, value=1234, label='Seed')
|
267 |
+
|
268 |
+
with gr.Group():
|
269 |
+
btn = gr.Button(value='Generate Shape Only', variant='primary')
|
270 |
+
btn_all = gr.Button(value='Generate Shape and Texture', variant='primary', visible=HAS_TEXTUREGEN)
|
271 |
+
|
272 |
+
with gr.Group():
|
273 |
+
file_out = gr.File(label="File", visible=False)
|
274 |
+
file_out2 = gr.File(label="File", visible=False)
|
275 |
+
|
276 |
+
with gr.Column(scale=5):
|
277 |
+
with gr.Tabs():
|
278 |
+
with gr.Tab('Generated Mesh') as mesh1:
|
279 |
+
html_output1 = gr.HTML(HTML_OUTPUT_PLACEHOLDER, label='Output')
|
280 |
+
with gr.Tab('Generated Textured Mesh') as mesh2:
|
281 |
+
html_output2 = gr.HTML(HTML_OUTPUT_PLACEHOLDER, label='Output')
|
282 |
+
|
283 |
+
with gr.Column(scale=2):
|
284 |
+
with gr.Tabs() as gallery:
|
285 |
+
with gr.Tab('Image to 3D Gallery', id='tab_img_gallery') as tab_gi:
|
286 |
+
with gr.Row():
|
287 |
+
gr.Examples(examples=example_is, inputs=[image],
|
288 |
+
label="Image Prompts", examples_per_page=18)
|
289 |
+
|
290 |
+
with gr.Tab('Text to 3D Gallery', id='tab_txt_gallery', visible=HAS_T2I) as tab_gt:
|
291 |
+
with gr.Row():
|
292 |
+
gr.Examples(examples=example_ts, inputs=[caption],
|
293 |
+
label="Text Prompts", examples_per_page=18)
|
294 |
+
|
295 |
+
if not HAS_TEXTUREGEN:
|
296 |
+
gr.HTML(""")
|
297 |
+
<div style="margin-top: 20px;">
|
298 |
+
<b>Warning: </b>
|
299 |
+
Texture synthesis is disable due to missing requirements,
|
300 |
+
please install requirements following README.md to activate it.
|
301 |
+
</div>
|
302 |
+
""")
|
303 |
+
if not args.enable_t23d:
|
304 |
+
gr.HTML("""
|
305 |
+
<div style="margin-top: 20px;">
|
306 |
+
<b>Warning: </b>
|
307 |
+
Text to 3D is disable. To activate it, please run `python gradio_app.py --enable_t23d`.
|
308 |
+
</div>
|
309 |
+
""")
|
310 |
+
|
311 |
+
tab_gi.select(fn=lambda: gr.update(selected='tab_img_prompt'), outputs=tabs_prompt)
|
312 |
+
if HAS_T2I:
|
313 |
+
tab_gt.select(fn=lambda: gr.update(selected='tab_txt_prompt'), outputs=tabs_prompt)
|
314 |
+
|
315 |
+
btn.click(
|
316 |
+
shape_generation,
|
317 |
+
inputs=[
|
318 |
+
caption,
|
319 |
+
image,
|
320 |
+
num_steps,
|
321 |
+
cfg_scale,
|
322 |
+
seed,
|
323 |
+
octree_resolution,
|
324 |
+
check_box_rembg,
|
325 |
+
],
|
326 |
+
outputs=[file_out, html_output1]
|
327 |
+
).then(
|
328 |
+
lambda: gr.update(visible=True),
|
329 |
+
outputs=[file_out],
|
330 |
+
)
|
331 |
+
|
332 |
+
btn_all.click(
|
333 |
+
generation_all,
|
334 |
+
inputs=[
|
335 |
+
caption,
|
336 |
+
image,
|
337 |
+
num_steps,
|
338 |
+
cfg_scale,
|
339 |
+
seed,
|
340 |
+
octree_resolution,
|
341 |
+
check_box_rembg,
|
342 |
+
],
|
343 |
+
outputs=[file_out, file_out2, html_output1, html_output2]
|
344 |
+
).then(
|
345 |
+
lambda: (gr.update(visible=True), gr.update(visible=True)),
|
346 |
+
outputs=[file_out, file_out2],
|
347 |
+
)
|
348 |
+
|
349 |
+
return demo
|
350 |
+
|
351 |
+
|
352 |
+
if __name__ == '__main__':
|
353 |
+
import argparse
|
354 |
+
|
355 |
+
parser = argparse.ArgumentParser()
|
356 |
+
parser.add_argument('--port', type=int, default=8080)
|
357 |
+
parser.add_argument('--cache-path', type=str, default='gradio_cache')
|
358 |
+
parser.add_argument('--enable_t23d', default=True)
|
359 |
+
args = parser.parse_args()
|
360 |
+
|
361 |
+
SAVE_DIR = args.cache_path
|
362 |
+
os.makedirs(SAVE_DIR, exist_ok=True)
|
363 |
+
|
364 |
+
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
365 |
+
|
366 |
+
HTML_OUTPUT_PLACEHOLDER = """
|
367 |
+
<div style='height: 596px; width: 100%; border-radius: 8px; border-color: #e5e7eb; order-style: solid; border-width: 1px;'></div>
|
368 |
+
"""
|
369 |
+
|
370 |
+
INPUT_MESH_HTML = """
|
371 |
+
<div style='height: 490px; width: 100%; border-radius: 8px;
|
372 |
+
border-color: #e5e7eb; order-style: solid; border-width: 1px;'>
|
373 |
+
</div>
|
374 |
+
"""
|
375 |
+
example_is = get_example_img_list()
|
376 |
+
example_ts = get_example_txt_list()
|
377 |
+
|
378 |
+
try:
|
379 |
+
from hy3dgen.texgen import Hunyuan3DPaintPipeline
|
380 |
+
|
381 |
+
texgen_worker = Hunyuan3DPaintPipeline.from_pretrained('tencent/Hunyuan3D-2')
|
382 |
+
HAS_TEXTUREGEN = True
|
383 |
+
except Exception as e:
|
384 |
+
print(e)
|
385 |
+
print("Failed to load texture generator.")
|
386 |
+
print('Please try to install requirements by following README.md')
|
387 |
+
HAS_TEXTUREGEN = False
|
388 |
+
|
389 |
+
HAS_T2I = False
|
390 |
+
if args.enable_t23d:
|
391 |
+
from hy3dgen.text2image import HunyuanDiTPipeline
|
392 |
+
|
393 |
+
t2i_worker = HunyuanDiTPipeline('Tencent-Hunyuan/HunyuanDiT-v1.1-Diffusers-Distilled')
|
394 |
+
HAS_T2I = True
|
395 |
+
|
396 |
+
from hy3dgen.shapegen import FaceReducer, FloaterRemover, DegenerateFaceRemover, \
|
397 |
+
Hunyuan3DDiTFlowMatchingPipeline
|
398 |
+
from hy3dgen.rembg import BackgroundRemover
|
399 |
+
|
400 |
+
rmbg_worker = BackgroundRemover()
|
401 |
+
i23d_worker = Hunyuan3DDiTFlowMatchingPipeline.from_pretrained('tencent/Hunyuan3D-2')
|
402 |
+
floater_remove_worker = FloaterRemover()
|
403 |
+
degenerate_face_remove_worker = DegenerateFaceRemover()
|
404 |
+
face_reduce_worker = FaceReducer()
|
405 |
+
|
406 |
+
# https://discuss.huggingface.co/t/how-to-serve-an-html-file/33921/2
|
407 |
+
# create a FastAPI app
|
408 |
+
app = FastAPI()
|
409 |
+
# create a static directory to store the static files
|
410 |
+
static_dir = Path('./gradio_cache')
|
411 |
+
static_dir.mkdir(parents=True, exist_ok=True)
|
412 |
+
app.mount("/static", StaticFiles(directory=static_dir), name="static")
|
413 |
+
|
414 |
+
demo = build_app()
|
415 |
+
app = gr.mount_gradio_app(app, demo, path="/")
|
416 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
.ipynb_checkpoints/requirements-checkpoint.txt
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio_litmodel3d
|
2 |
+
ninja
|
3 |
+
pybind11
|
4 |
+
trimesh
|
5 |
+
diffusers
|
6 |
+
tqdm
|
7 |
+
einops
|
8 |
+
opencv-python
|
9 |
+
numpy
|
10 |
+
torch
|
11 |
+
transformers
|
12 |
+
torchvision
|
13 |
+
torchaudio
|
14 |
+
ConfigArgParse
|
15 |
+
xatlas
|
16 |
+
scikit-learn
|
17 |
+
scikit-image
|
18 |
+
tritonclient
|
19 |
+
gevent
|
20 |
+
geventhttpclient
|
21 |
+
facexlib
|
22 |
+
accelerate
|
23 |
+
ipdb
|
24 |
+
omegaconf
|
25 |
+
pymeshlab
|
26 |
+
pytorch_lightning
|
27 |
+
taming-transformers-rom1504
|
28 |
+
kornia
|
29 |
+
rembg
|
30 |
+
onnxruntime
|
31 |
+
pygltflib
|
32 |
+
sentencepiece
|
33 |
+
gradio
|
34 |
+
uvicorn
|
35 |
+
fastapi
|
assets/modelviewer-template.html
CHANGED
@@ -3,7 +3,8 @@
|
|
3 |
|
4 |
<head>
|
5 |
<!-- Import the component -->
|
6 |
-
|
|
|
7 |
|
8 |
<script>
|
9 |
document.addEventListener('DOMContentLoaded', () => {
|
@@ -46,4 +47,4 @@
|
|
46 |
</div>
|
47 |
</body>
|
48 |
|
49 |
-
</html>
|
|
|
3 |
|
4 |
<head>
|
5 |
<!-- Import the component -->
|
6 |
+
<!--<script src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.1.1/model-viewer.min.js" type="module"></script> -->
|
7 |
+
<script src="https://cdn.jsdelivr.net/npm/@google/[email protected]/dist/model-viewer.min.js" type="module"></script>
|
8 |
|
9 |
<script>
|
10 |
document.addEventListener('DOMContentLoaded', () => {
|
|
|
47 |
</div>
|
48 |
</body>
|
49 |
|
50 |
+
</html>
|
assets/modelviewer-textured-template.html
CHANGED
@@ -3,7 +3,8 @@
|
|
3 |
|
4 |
<head>
|
5 |
<!-- Import the component -->
|
6 |
-
|
|
|
7 |
|
8 |
<style>
|
9 |
body {
|
@@ -29,4 +30,4 @@
|
|
29 |
</div>
|
30 |
</body>
|
31 |
|
32 |
-
</html>
|
|
|
3 |
|
4 |
<head>
|
5 |
<!-- Import the component -->
|
6 |
+
<!--<script src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.1.1/model-viewer.min.js" type="module"></script> -->
|
7 |
+
<script src="https://cdn.jsdelivr.net/npm/@google/[email protected]/dist/model-viewer.min.js" type="module"></script>
|
8 |
|
9 |
<style>
|
10 |
body {
|
|
|
30 |
</div>
|
31 |
</body>
|
32 |
|
33 |
+
</html>
|
gradio_cache/0/input.png
ADDED
gradio_cache/0/rembg.png
ADDED
gradio_cache/0/textured_mesh.glb
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:82c8286bce9c760b166e9f8a57b3c701b913f9e6592f2c4bc08d66ae89c7ea34
|
3 |
+
size 2464072
|
gradio_cache/0/textured_mesh.html
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
|
4 |
+
<head>
|
5 |
+
<!-- Import the component -->
|
6 |
+
<script src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.1.1/model-viewer.min.js" type="module"></script>
|
7 |
+
|
8 |
+
<style>
|
9 |
+
body {
|
10 |
+
margin: 0;
|
11 |
+
font-family: Arial, sans-serif;
|
12 |
+
}
|
13 |
+
|
14 |
+
.centered-container {
|
15 |
+
display: flex;
|
16 |
+
justify-content: center;
|
17 |
+
align-items: center;
|
18 |
+
border-radius: 8px;
|
19 |
+
border-color: #e5e7eb;
|
20 |
+
border-style: solid;
|
21 |
+
border-width: 1px;
|
22 |
+
}
|
23 |
+
</style>
|
24 |
+
</head>
|
25 |
+
|
26 |
+
<body>
|
27 |
+
<div class="centered-container">
|
28 |
+
|
29 |
+
<div class="column is-mobile is-centered">
|
30 |
+
<model-viewer style="height: 586px; width: 700px;" rotation-per-second="10deg" id="modelViewer"
|
31 |
+
src="./textured_mesh.glb/" disable-tap
|
32 |
+
environment-image="neutral" auto-rotate camera-target="0m 0m 0m" orientation="0deg 0deg 170deg" shadow-intensity=".9"
|
33 |
+
ar auto-rotate camera-controls>
|
34 |
+
</model-viewer>
|
35 |
+
</div>
|
36 |
+
|
37 |
+
</div>
|
38 |
+
</body>
|
39 |
+
|
40 |
+
</html>
|
gradio_cache/0/white_mesh.glb
ADDED
Binary file (721 kB). View file
|
|
gradio_cache/0/white_mesh.html
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
|
4 |
+
<head>
|
5 |
+
<!-- Import the component -->
|
6 |
+
<script src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.1.1/model-viewer.min.js" type="module"></script>
|
7 |
+
|
8 |
+
<script>
|
9 |
+
document.addEventListener('DOMContentLoaded', () => {
|
10 |
+
const modelViewers = document.querySelectorAll('model-viewer');
|
11 |
+
|
12 |
+
modelViewers.forEach(modelViewer => {
|
13 |
+
modelViewer.addEventListener('load', (event) => {
|
14 |
+
const [material] = modelViewer.model.materials;
|
15 |
+
let color = [43, 44, 46, 255];
|
16 |
+
color = color.map(x => x / 255);
|
17 |
+
material.pbrMetallicRoughness.setMetallicFactor(0.1); // 完全金属
|
18 |
+
material.pbrMetallicRoughness.setRoughnessFactor(0.7); // 低粗糙度
|
19 |
+
material.pbrMetallicRoughness.setBaseColorFactor(color); // CornflowerBlue in RGB
|
20 |
+
});
|
21 |
+
});
|
22 |
+
});
|
23 |
+
</script>
|
24 |
+
|
25 |
+
<style>
|
26 |
+
body {
|
27 |
+
margin: 0;
|
28 |
+
font-family: Arial, sans-serif;
|
29 |
+
}
|
30 |
+
|
31 |
+
.centered-container {
|
32 |
+
display: flex;
|
33 |
+
justify-content: center;
|
34 |
+
align-items: center;
|
35 |
+
border-radius: 8px;
|
36 |
+
border-color: #e5e7eb;
|
37 |
+
border-style: solid;
|
38 |
+
border-width: 1px;
|
39 |
+
}
|
40 |
+
</style>
|
41 |
+
</head>
|
42 |
+
|
43 |
+
<body>
|
44 |
+
<div class="centered-container">
|
45 |
+
|
46 |
+
<div class="column is-mobile is-centered">
|
47 |
+
<model-viewer style="height: 586px; width: 700px;" rotation-per-second="10deg" id="modelViewer"
|
48 |
+
src="./white_mesh.glb/" disable-tap
|
49 |
+
environment-image="neutral" auto-rotate camera-target="0m 0m 0m" orientation="0deg 0deg 170deg" shadow-intensity=".9"
|
50 |
+
ar auto-rotate camera-controls>
|
51 |
+
</model-viewer>
|
52 |
+
</div>
|
53 |
+
|
54 |
+
</div>
|
55 |
+
</body>
|
56 |
+
|
57 |
+
</html>
|
gradio_cache/1/input.png
ADDED
gradio_cache/1/rembg.png
ADDED
gradio_cache/1/textured_mesh.glb
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:00f04ece070c997b2b25bc9ad7674e737b8f42f533d68b732ed6ae459709fef2
|
3 |
+
size 2464060
|
gradio_cache/1/textured_mesh.html
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
|
4 |
+
<head>
|
5 |
+
<!-- Import the component -->
|
6 |
+
<script src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.1.1/model-viewer.min.js" type="module"></script>
|
7 |
+
|
8 |
+
<style>
|
9 |
+
body {
|
10 |
+
margin: 0;
|
11 |
+
font-family: Arial, sans-serif;
|
12 |
+
}
|
13 |
+
|
14 |
+
.centered-container {
|
15 |
+
display: flex;
|
16 |
+
justify-content: center;
|
17 |
+
align-items: center;
|
18 |
+
border-radius: 8px;
|
19 |
+
border-color: #e5e7eb;
|
20 |
+
border-style: solid;
|
21 |
+
border-width: 1px;
|
22 |
+
}
|
23 |
+
</style>
|
24 |
+
</head>
|
25 |
+
|
26 |
+
<body>
|
27 |
+
<div class="centered-container">
|
28 |
+
|
29 |
+
<div class="column is-mobile is-centered">
|
30 |
+
<model-viewer style="height: 586px; width: 700px;" rotation-per-second="10deg" id="modelViewer"
|
31 |
+
src="./textured_mesh.glb/" disable-tap
|
32 |
+
environment-image="neutral" auto-rotate camera-target="0m 0m 0m" orientation="0deg 0deg 170deg" shadow-intensity=".9"
|
33 |
+
ar auto-rotate camera-controls>
|
34 |
+
</model-viewer>
|
35 |
+
</div>
|
36 |
+
|
37 |
+
</div>
|
38 |
+
</body>
|
39 |
+
|
40 |
+
</html>
|
gradio_cache/1/white_mesh.glb
ADDED
Binary file (721 kB). View file
|
|
gradio_cache/1/white_mesh.html
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
|
4 |
+
<head>
|
5 |
+
<!-- Import the component -->
|
6 |
+
<script src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.1.1/model-viewer.min.js" type="module"></script>
|
7 |
+
|
8 |
+
<script>
|
9 |
+
document.addEventListener('DOMContentLoaded', () => {
|
10 |
+
const modelViewers = document.querySelectorAll('model-viewer');
|
11 |
+
|
12 |
+
modelViewers.forEach(modelViewer => {
|
13 |
+
modelViewer.addEventListener('load', (event) => {
|
14 |
+
const [material] = modelViewer.model.materials;
|
15 |
+
let color = [43, 44, 46, 255];
|
16 |
+
color = color.map(x => x / 255);
|
17 |
+
material.pbrMetallicRoughness.setMetallicFactor(0.1); // 完全金属
|
18 |
+
material.pbrMetallicRoughness.setRoughnessFactor(0.7); // 低粗糙度
|
19 |
+
material.pbrMetallicRoughness.setBaseColorFactor(color); // CornflowerBlue in RGB
|
20 |
+
});
|
21 |
+
});
|
22 |
+
});
|
23 |
+
</script>
|
24 |
+
|
25 |
+
<style>
|
26 |
+
body {
|
27 |
+
margin: 0;
|
28 |
+
font-family: Arial, sans-serif;
|
29 |
+
}
|
30 |
+
|
31 |
+
.centered-container {
|
32 |
+
display: flex;
|
33 |
+
justify-content: center;
|
34 |
+
align-items: center;
|
35 |
+
border-radius: 8px;
|
36 |
+
border-color: #e5e7eb;
|
37 |
+
border-style: solid;
|
38 |
+
border-width: 1px;
|
39 |
+
}
|
40 |
+
</style>
|
41 |
+
</head>
|
42 |
+
|
43 |
+
<body>
|
44 |
+
<div class="centered-container">
|
45 |
+
|
46 |
+
<div class="column is-mobile is-centered">
|
47 |
+
<model-viewer style="height: 586px; width: 700px;" rotation-per-second="10deg" id="modelViewer"
|
48 |
+
src="./white_mesh.glb/" disable-tap
|
49 |
+
environment-image="neutral" auto-rotate camera-target="0m 0m 0m" orientation="0deg 0deg 170deg" shadow-intensity=".9"
|
50 |
+
ar auto-rotate camera-controls>
|
51 |
+
</model-viewer>
|
52 |
+
</div>
|
53 |
+
|
54 |
+
</div>
|
55 |
+
</body>
|
56 |
+
|
57 |
+
</html>
|
gradio_cache/2/input.png
ADDED
gradio_cache/2/rembg.png
ADDED
gradio_cache/2/white_mesh.glb
ADDED
Binary file (721 kB). View file
|
|
gradio_cache/2/white_mesh.html
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
|
4 |
+
<head>
|
5 |
+
<!-- Import the component -->
|
6 |
+
<script src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.1.1/model-viewer.min.js" type="module"></script>
|
7 |
+
|
8 |
+
<script>
|
9 |
+
document.addEventListener('DOMContentLoaded', () => {
|
10 |
+
const modelViewers = document.querySelectorAll('model-viewer');
|
11 |
+
|
12 |
+
modelViewers.forEach(modelViewer => {
|
13 |
+
modelViewer.addEventListener('load', (event) => {
|
14 |
+
const [material] = modelViewer.model.materials;
|
15 |
+
let color = [43, 44, 46, 255];
|
16 |
+
color = color.map(x => x / 255);
|
17 |
+
material.pbrMetallicRoughness.setMetallicFactor(0.1); // 完全金属
|
18 |
+
material.pbrMetallicRoughness.setRoughnessFactor(0.7); // 低粗糙度
|
19 |
+
material.pbrMetallicRoughness.setBaseColorFactor(color); // CornflowerBlue in RGB
|
20 |
+
});
|
21 |
+
});
|
22 |
+
});
|
23 |
+
</script>
|
24 |
+
|
25 |
+
<style>
|
26 |
+
body {
|
27 |
+
margin: 0;
|
28 |
+
font-family: Arial, sans-serif;
|
29 |
+
}
|
30 |
+
|
31 |
+
.centered-container {
|
32 |
+
display: flex;
|
33 |
+
justify-content: center;
|
34 |
+
align-items: center;
|
35 |
+
border-radius: 8px;
|
36 |
+
border-color: #e5e7eb;
|
37 |
+
border-style: solid;
|
38 |
+
border-width: 1px;
|
39 |
+
}
|
40 |
+
</style>
|
41 |
+
</head>
|
42 |
+
|
43 |
+
<body>
|
44 |
+
<div class="centered-container">
|
45 |
+
|
46 |
+
<div class="column is-mobile is-centered">
|
47 |
+
<model-viewer style="height: 586px; width: 700px;" rotation-per-second="10deg" id="modelViewer"
|
48 |
+
src="./white_mesh.glb/" disable-tap
|
49 |
+
environment-image="neutral" auto-rotate camera-target="0m 0m 0m" orientation="0deg 0deg 170deg" shadow-intensity=".9"
|
50 |
+
ar auto-rotate camera-controls>
|
51 |
+
</model-viewer>
|
52 |
+
</div>
|
53 |
+
|
54 |
+
</div>
|
55 |
+
</body>
|
56 |
+
|
57 |
+
</html>
|
gradio_cache/3/input.png
ADDED
gradio_cache/3/rembg.png
ADDED
gradio_cache/3/textured_mesh.glb
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c93b387fb95e04b19f37be60d7b334702406f0e672df73fd5803cbd29d41af8b
|
3 |
+
size 2183696
|
gradio_cache/3/textured_mesh.html
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
|
4 |
+
<head>
|
5 |
+
<!-- Import the component -->
|
6 |
+
<script src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.1.1/model-viewer.min.js" type="module"></script>
|
7 |
+
|
8 |
+
<style>
|
9 |
+
body {
|
10 |
+
margin: 0;
|
11 |
+
font-family: Arial, sans-serif;
|
12 |
+
}
|
13 |
+
|
14 |
+
.centered-container {
|
15 |
+
display: flex;
|
16 |
+
justify-content: center;
|
17 |
+
align-items: center;
|
18 |
+
border-radius: 8px;
|
19 |
+
border-color: #e5e7eb;
|
20 |
+
border-style: solid;
|
21 |
+
border-width: 1px;
|
22 |
+
}
|
23 |
+
</style>
|
24 |
+
</head>
|
25 |
+
|
26 |
+
<body>
|
27 |
+
<div class="centered-container">
|
28 |
+
|
29 |
+
<div class="column is-mobile is-centered">
|
30 |
+
<model-viewer style="height: 586px; width: 700px;" rotation-per-second="10deg" id="modelViewer"
|
31 |
+
src="./textured_mesh.glb/" disable-tap
|
32 |
+
environment-image="neutral" auto-rotate camera-target="0m 0m 0m" orientation="0deg 0deg 170deg" shadow-intensity=".9"
|
33 |
+
ar auto-rotate camera-controls>
|
34 |
+
</model-viewer>
|
35 |
+
</div>
|
36 |
+
|
37 |
+
</div>
|
38 |
+
</body>
|
39 |
+
|
40 |
+
</html>
|
gradio_cache/3/white_mesh.glb
ADDED
Binary file (721 kB). View file
|
|
gradio_cache/3/white_mesh.html
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
|
4 |
+
<head>
|
5 |
+
<!-- Import the component -->
|
6 |
+
<script src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.1.1/model-viewer.min.js" type="module"></script>
|
7 |
+
|
8 |
+
<script>
|
9 |
+
document.addEventListener('DOMContentLoaded', () => {
|
10 |
+
const modelViewers = document.querySelectorAll('model-viewer');
|
11 |
+
|
12 |
+
modelViewers.forEach(modelViewer => {
|
13 |
+
modelViewer.addEventListener('load', (event) => {
|
14 |
+
const [material] = modelViewer.model.materials;
|
15 |
+
let color = [43, 44, 46, 255];
|
16 |
+
color = color.map(x => x / 255);
|
17 |
+
material.pbrMetallicRoughness.setMetallicFactor(0.1); // 完全金属
|
18 |
+
material.pbrMetallicRoughness.setRoughnessFactor(0.7); // 低粗糙度
|
19 |
+
material.pbrMetallicRoughness.setBaseColorFactor(color); // CornflowerBlue in RGB
|
20 |
+
});
|
21 |
+
});
|
22 |
+
});
|
23 |
+
</script>
|
24 |
+
|
25 |
+
<style>
|
26 |
+
body {
|
27 |
+
margin: 0;
|
28 |
+
font-family: Arial, sans-serif;
|
29 |
+
}
|
30 |
+
|
31 |
+
.centered-container {
|
32 |
+
display: flex;
|
33 |
+
justify-content: center;
|
34 |
+
align-items: center;
|
35 |
+
border-radius: 8px;
|
36 |
+
border-color: #e5e7eb;
|
37 |
+
border-style: solid;
|
38 |
+
border-width: 1px;
|
39 |
+
}
|
40 |
+
</style>
|
41 |
+
</head>
|
42 |
+
|
43 |
+
<body>
|
44 |
+
<div class="centered-container">
|
45 |
+
|
46 |
+
<div class="column is-mobile is-centered">
|
47 |
+
<model-viewer style="height: 586px; width: 700px;" rotation-per-second="10deg" id="modelViewer"
|
48 |
+
src="./white_mesh.glb/" disable-tap
|
49 |
+
environment-image="neutral" auto-rotate camera-target="0m 0m 0m" orientation="0deg 0deg 170deg" shadow-intensity=".9"
|
50 |
+
ar auto-rotate camera-controls>
|
51 |
+
</model-viewer>
|
52 |
+
</div>
|
53 |
+
|
54 |
+
</div>
|
55 |
+
</body>
|
56 |
+
|
57 |
+
</html>
|
gradio_cache/4/input.png
ADDED
gradio_cache/4/rembg.png
ADDED
gradio_cache/4/textured_mesh.glb
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9a3572334508a5661c1ff75f4ad228c6d1b40b5e46b7eded9fc00759d738ec13
|
3 |
+
size 2472736
|
gradio_cache/4/textured_mesh.html
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
|
4 |
+
<head>
|
5 |
+
<!-- Import the component -->
|
6 |
+
<script src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.1.1/model-viewer.min.js" type="module"></script>
|
7 |
+
|
8 |
+
<style>
|
9 |
+
body {
|
10 |
+
margin: 0;
|
11 |
+
font-family: Arial, sans-serif;
|
12 |
+
}
|
13 |
+
|
14 |
+
.centered-container {
|
15 |
+
display: flex;
|
16 |
+
justify-content: center;
|
17 |
+
align-items: center;
|
18 |
+
border-radius: 8px;
|
19 |
+
border-color: #e5e7eb;
|
20 |
+
border-style: solid;
|
21 |
+
border-width: 1px;
|
22 |
+
}
|
23 |
+
</style>
|
24 |
+
</head>
|
25 |
+
|
26 |
+
<body>
|
27 |
+
<div class="centered-container">
|
28 |
+
|
29 |
+
<div class="column is-mobile is-centered">
|
30 |
+
<model-viewer style="height: 586px; width: 700px;" rotation-per-second="10deg" id="modelViewer"
|
31 |
+
src="./textured_mesh.glb/" disable-tap
|
32 |
+
environment-image="neutral" auto-rotate camera-target="0m 0m 0m" orientation="0deg 0deg 170deg" shadow-intensity=".9"
|
33 |
+
ar auto-rotate camera-controls>
|
34 |
+
</model-viewer>
|
35 |
+
</div>
|
36 |
+
|
37 |
+
</div>
|
38 |
+
</body>
|
39 |
+
|
40 |
+
</html>
|
gradio_cache/4/white_mesh.glb
ADDED
Binary file (716 kB). View file
|
|
gradio_cache/4/white_mesh.html
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
|
4 |
+
<head>
|
5 |
+
<!-- Import the component -->
|
6 |
+
<script src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.1.1/model-viewer.min.js" type="module"></script>
|
7 |
+
|
8 |
+
<script>
|
9 |
+
document.addEventListener('DOMContentLoaded', () => {
|
10 |
+
const modelViewers = document.querySelectorAll('model-viewer');
|
11 |
+
|
12 |
+
modelViewers.forEach(modelViewer => {
|
13 |
+
modelViewer.addEventListener('load', (event) => {
|
14 |
+
const [material] = modelViewer.model.materials;
|
15 |
+
let color = [43, 44, 46, 255];
|
16 |
+
color = color.map(x => x / 255);
|
17 |
+
material.pbrMetallicRoughness.setMetallicFactor(0.1); // 完全金属
|
18 |
+
material.pbrMetallicRoughness.setRoughnessFactor(0.7); // 低粗糙度
|
19 |
+
material.pbrMetallicRoughness.setBaseColorFactor(color); // CornflowerBlue in RGB
|
20 |
+
});
|
21 |
+
});
|
22 |
+
});
|
23 |
+
</script>
|
24 |
+
|
25 |
+
<style>
|
26 |
+
body {
|
27 |
+
margin: 0;
|
28 |
+
font-family: Arial, sans-serif;
|
29 |
+
}
|
30 |
+
|
31 |
+
.centered-container {
|
32 |
+
display: flex;
|
33 |
+
justify-content: center;
|
34 |
+
align-items: center;
|
35 |
+
border-radius: 8px;
|
36 |
+
border-color: #e5e7eb;
|
37 |
+
border-style: solid;
|
38 |
+
border-width: 1px;
|
39 |
+
}
|
40 |
+
</style>
|
41 |
+
</head>
|
42 |
+
|
43 |
+
<body>
|
44 |
+
<div class="centered-container">
|
45 |
+
|
46 |
+
<div class="column is-mobile is-centered">
|
47 |
+
<model-viewer style="height: 586px; width: 700px;" rotation-per-second="10deg" id="modelViewer"
|
48 |
+
src="./white_mesh.glb/" disable-tap
|
49 |
+
environment-image="neutral" auto-rotate camera-target="0m 0m 0m" orientation="0deg 0deg 170deg" shadow-intensity=".9"
|
50 |
+
ar auto-rotate camera-controls>
|
51 |
+
</model-viewer>
|
52 |
+
</div>
|
53 |
+
|
54 |
+
</div>
|
55 |
+
</body>
|
56 |
+
|
57 |
+
</html>
|
hg_app.py
CHANGED
@@ -431,6 +431,6 @@ if __name__ == '__main__':
|
|
431 |
app.mount("/static", StaticFiles(directory=static_dir), name="static")
|
432 |
|
433 |
demo = build_app()
|
434 |
-
demo.queue(max_size=
|
435 |
app = gr.mount_gradio_app(app, demo, path="/")
|
436 |
uvicorn.run(app, host=IP, port=PORT)
|
|
|
431 |
app.mount("/static", StaticFiles(directory=static_dir), name="static")
|
432 |
|
433 |
demo = build_app()
|
434 |
+
demo.queue(max_size=10)
|
435 |
app = gr.mount_gradio_app(app, demo, path="/")
|
436 |
uvicorn.run(app, host=IP, port=PORT)
|
hy3dgen/.ipynb_checkpoints/text2image-checkpoint.py
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Open Source Model Licensed under the Apache License Version 2.0
|
2 |
+
# and Other Licenses of the Third-Party Components therein:
|
3 |
+
# The below Model in this distribution may have been modified by THL A29 Limited
|
4 |
+
# ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
|
5 |
+
|
6 |
+
# Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
|
7 |
+
# The below software and/or models in this distribution may have been
|
8 |
+
# modified by THL A29 Limited ("Tencent Modifications").
|
9 |
+
# All Tencent Modifications are Copyright (C) THL A29 Limited.
|
10 |
+
|
11 |
+
# Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
|
12 |
+
# except for the third-party components listed below.
|
13 |
+
# Hunyuan 3D does not impose any additional limitations beyond what is outlined
|
14 |
+
# in the repsective licenses of these third-party components.
|
15 |
+
# Users must comply with all terms and conditions of original licenses of these third-party
|
16 |
+
# components and must ensure that the usage of the third party components adheres to
|
17 |
+
# all relevant laws and regulations.
|
18 |
+
|
19 |
+
# For avoidance of doubts, Hunyuan 3D means the large language models and
|
20 |
+
# their software and algorithms, including trained model weights, parameters (including
|
21 |
+
# optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
|
22 |
+
# fine-tuning enabling code and other elements of the foregoing made publicly available
|
23 |
+
# by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
|
24 |
+
|
25 |
+
|
26 |
+
import os
|
27 |
+
import random
|
28 |
+
|
29 |
+
import numpy as np
|
30 |
+
import torch
|
31 |
+
from diffusers import AutoPipelineForText2Image
|
32 |
+
|
33 |
+
|
34 |
+
def seed_everything(seed):
|
35 |
+
random.seed(seed)
|
36 |
+
np.random.seed(seed)
|
37 |
+
torch.manual_seed(seed)
|
38 |
+
os.environ["PL_GLOBAL_SEED"] = str(seed)
|
39 |
+
|
40 |
+
|
41 |
+
class HunyuanDiTPipeline:
|
42 |
+
def __init__(
|
43 |
+
self,
|
44 |
+
model_path="Tencent-Hunyuan/HunyuanDiT-v1.1-Diffusers-Distilled",
|
45 |
+
device='cuda'
|
46 |
+
):
|
47 |
+
self.device = device
|
48 |
+
self.pipe = AutoPipelineForText2Image.from_pretrained(
|
49 |
+
model_path,
|
50 |
+
torch_dtype=torch.float16,
|
51 |
+
enable_pag=True,
|
52 |
+
pag_applied_layers=["blocks.(16|17|18|19)"]
|
53 |
+
).to(device)
|
54 |
+
self.pos_txt = ",白色背景,3D风格,最佳质量"
|
55 |
+
self.neg_txt = "文本,特写,裁剪,出框,最差质量,低质量,JPEG伪影,PGLY,重复,病态," \
|
56 |
+
"残缺,多余的手指,变异的手,画得不好的手,画得不好的脸,变异,畸形,模糊,脱水,糟糕的解剖学," \
|
57 |
+
"糟糕的比例,多余的肢体,克隆的脸,毁容,恶心的比例,畸形的肢体,缺失的手臂,缺失的腿," \
|
58 |
+
"额外的手臂,额外的腿,融合的手指,手指太多,长脖子"
|
59 |
+
|
60 |
+
def compile(self):
|
61 |
+
# accelarate hunyuan-dit transformer,first inference will cost long time
|
62 |
+
torch.set_float32_matmul_precision('high')
|
63 |
+
self.pipe.transformer = torch.compile(self.pipe.transformer, fullgraph=True)
|
64 |
+
# self.pipe.vae.decode = torch.compile(self.pipe.vae.decode, fullgraph=True)
|
65 |
+
generator = torch.Generator(device=self.pipe.device) # infer once for hot-start
|
66 |
+
out_img = self.pipe(
|
67 |
+
prompt='美少女战士',
|
68 |
+
negative_prompt='模糊',
|
69 |
+
num_inference_steps=25,
|
70 |
+
pag_scale=1.3,
|
71 |
+
width=1024,
|
72 |
+
height=1024,
|
73 |
+
generator=generator,
|
74 |
+
return_dict=False
|
75 |
+
)[0][0]
|
76 |
+
|
77 |
+
@torch.no_grad()
|
78 |
+
def __call__(self, prompt, seed=0):
|
79 |
+
seed_everything(seed)
|
80 |
+
generator = torch.Generator(device=self.pipe.device)
|
81 |
+
generator = generator.manual_seed(int(seed))
|
82 |
+
out_img = self.pipe(
|
83 |
+
prompt=self.pos_txt+prompt,
|
84 |
+
negative_prompt=self.neg_txt,
|
85 |
+
num_inference_steps=25,
|
86 |
+
pag_scale=1.3,
|
87 |
+
width=1024,
|
88 |
+
height=1024,
|
89 |
+
generator=generator,
|
90 |
+
return_dict=False
|
91 |
+
)[0][0]
|
92 |
+
return out_img
|
hy3dgen/__pycache__/__init__.cpython-311.pyc
ADDED
Binary file (192 Bytes). View file
|
|
hy3dgen/__pycache__/rembg.cpython-311.pyc
ADDED
Binary file (1.08 kB). View file
|
|
hy3dgen/__pycache__/text2image.cpython-311.pyc
ADDED
Binary file (3.7 kB). View file
|
|
hy3dgen/shapegen/__pycache__/__init__.cpython-311.pyc
ADDED
Binary file (598 Bytes). View file
|
|
hy3dgen/shapegen/__pycache__/pipelines.cpython-311.pyc
ADDED
Binary file (27.1 kB). View file
|
|
hy3dgen/shapegen/__pycache__/postprocessors.cpython-311.pyc
ADDED
Binary file (8.04 kB). View file
|
|
hy3dgen/shapegen/__pycache__/preprocessors.cpython-311.pyc
ADDED
Binary file (6.08 kB). View file
|
|
hy3dgen/shapegen/__pycache__/schedulers.cpython-311.pyc
ADDED
Binary file (14.6 kB). View file
|
|
hy3dgen/shapegen/models/__pycache__/__init__.cpython-311.pyc
ADDED
Binary file (495 Bytes). View file
|
|
hy3dgen/shapegen/models/__pycache__/conditioner.cpython-311.pyc
ADDED
Binary file (7.28 kB). View file
|
|
hy3dgen/shapegen/models/__pycache__/hunyuan3ddit.cpython-311.pyc
ADDED
Binary file (24.3 kB). View file
|
|
hy3dgen/shapegen/models/__pycache__/vae.cpython-311.pyc
ADDED
Binary file (33.1 kB). View file
|
|
hy3dgen/texgen/__pycache__/__init__.cpython-311.pyc
ADDED
Binary file (310 Bytes). View file
|
|