Spaces:
Running
on
Zero
Running
on
Zero
xinjie.wang
commited on
Commit
Β·
e1f4b2c
1
Parent(s):
6f5d0e5
update
Browse files- app.py +29 -12
- common.py +11 -1
- embodied_gen/models/text_model.py +4 -3
- embodied_gen/scripts/imageto3d.py +3 -1
app.py
CHANGED
@@ -23,6 +23,7 @@ from common import (
|
|
23 |
MAX_SEED,
|
24 |
VERSION,
|
25 |
backproject_texture_v2,
|
|
|
26 |
end_session,
|
27 |
generate_condition,
|
28 |
generate_texture_mvimages,
|
@@ -33,8 +34,6 @@ from common import (
|
|
33 |
render_result_video,
|
34 |
start_session,
|
35 |
)
|
36 |
-
from gradio.themes import Default
|
37 |
-
from gradio.themes.utils.colors import slate
|
38 |
|
39 |
|
40 |
def active_btn_by_content(mesh_content: gr.Model3D, text_content: gr.Textbox):
|
@@ -50,14 +49,32 @@ def active_btn_by_content(mesh_content: gr.Model3D, text_content: gr.Textbox):
|
|
50 |
return gr.Button(interactive=interactive)
|
51 |
|
52 |
|
53 |
-
with gr.Blocks(
|
54 |
-
delete_cache=(43200, 43200), theme=Default(primary_hue=slate)
|
55 |
-
) as demo:
|
56 |
gr.Markdown(
|
57 |
-
|
58 |
-
## ***EmbodiedGen***:
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
)
|
62 |
gr.HTML(image_css)
|
63 |
gr.HTML(lighting_css)
|
@@ -123,7 +140,7 @@ with gr.Blocks(
|
|
123 |
)
|
124 |
|
125 |
generate_mv_btn = gr.Button(
|
126 |
-
"Generate MV Images(~1min)",
|
127 |
variant="primary",
|
128 |
interactive=False,
|
129 |
)
|
@@ -206,12 +223,12 @@ with gr.Blocks(
|
|
206 |
|
207 |
with gr.Column(scale=1):
|
208 |
texture_bake_btn = gr.Button(
|
209 |
-
"Texture Baking(~2min)",
|
210 |
variant="primary",
|
211 |
interactive=False,
|
212 |
)
|
213 |
download_btn = gr.DownloadButton(
|
214 |
-
label="Download Mesh",
|
215 |
variant="primary",
|
216 |
interactive=False,
|
217 |
)
|
|
|
23 |
MAX_SEED,
|
24 |
VERSION,
|
25 |
backproject_texture_v2,
|
26 |
+
custom_theme,
|
27 |
end_session,
|
28 |
generate_condition,
|
29 |
generate_texture_mvimages,
|
|
|
34 |
render_result_video,
|
35 |
start_session,
|
36 |
)
|
|
|
|
|
37 |
|
38 |
|
39 |
def active_btn_by_content(mesh_content: gr.Model3D, text_content: gr.Textbox):
|
|
|
49 |
return gr.Button(interactive=interactive)
|
50 |
|
51 |
|
52 |
+
with gr.Blocks(delete_cache=(43200, 43200), theme=custom_theme) as demo:
|
|
|
|
|
53 |
gr.Markdown(
|
54 |
+
"""
|
55 |
+
## ***EmbodiedGen***: Text-to-3D Asset
|
56 |
+
**π Version**: {VERSION}
|
57 |
+
<p style="display: flex; gap: 10px; flex-wrap: nowrap;">
|
58 |
+
<a href="https://horizonrobotics.github.io/robot_lab/embodied_gen/index.html">
|
59 |
+
<img alt="π Project Page" src="https://img.shields.io/badge/π-Project_Page-blue">
|
60 |
+
</a>
|
61 |
+
<a href="https://arxiv.org/abs/xxxx.xxxxx">
|
62 |
+
<img alt="π arXiv" src="https://img.shields.io/badge/π-arXiv-b31b1b">
|
63 |
+
</a>
|
64 |
+
<a href="https://github.com/horizon-research/EmbodiedGen">
|
65 |
+
<img alt="π» GitHub" src="https://img.shields.io/badge/GitHub-000000?logo=github">
|
66 |
+
</a>
|
67 |
+
<a href="https://www.youtube.com/watch?v=SnHhzHeb_aI">
|
68 |
+
<img alt="π₯ Video" src="https://img.shields.io/badge/π₯-Video-red">
|
69 |
+
</a>
|
70 |
+
</p>
|
71 |
+
|
72 |
+
π¨ Generate visually rich textures for 3D mesh.
|
73 |
+
|
74 |
+
""".format(
|
75 |
+
VERSION=VERSION
|
76 |
+
),
|
77 |
+
elem_classes=["header"],
|
78 |
)
|
79 |
gr.HTML(image_css)
|
80 |
gr.HTML(lighting_css)
|
|
|
140 |
)
|
141 |
|
142 |
generate_mv_btn = gr.Button(
|
143 |
+
"π¨ 1. Generate MV Images(~1min)",
|
144 |
variant="primary",
|
145 |
interactive=False,
|
146 |
)
|
|
|
223 |
|
224 |
with gr.Column(scale=1):
|
225 |
texture_bake_btn = gr.Button(
|
226 |
+
"π οΈ 2. Texture Baking(~2min)",
|
227 |
variant="primary",
|
228 |
interactive=False,
|
229 |
)
|
230 |
download_btn = gr.DownloadButton(
|
231 |
+
label="β¬οΈ 3. Download Mesh",
|
232 |
variant="primary",
|
233 |
interactive=False,
|
234 |
)
|
common.py
CHANGED
@@ -30,6 +30,8 @@ import torch
|
|
30 |
import torch.nn.functional as F
|
31 |
import trimesh
|
32 |
from easydict import EasyDict as edict
|
|
|
|
|
33 |
from PIL import Image
|
34 |
from embodied_gen.data.backproject_v2 import entrypoint as backproject_api
|
35 |
from embodied_gen.data.differentiable_render import entrypoint as render_api
|
@@ -233,6 +235,14 @@ height: 100% !important;
|
|
233 |
</style>
|
234 |
"""
|
235 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
|
237 |
def start_session(req: gr.Request) -> None:
|
238 |
user_dir = os.path.join(TMP_DIR, str(req.session_hash))
|
@@ -670,8 +680,8 @@ def text2image_fn(
|
|
670 |
ip_adapt_scale: float = 0.3,
|
671 |
image_wh: int | tuple[int, int] = [1024, 1024],
|
672 |
rmbg_tag: str = "rembg",
|
673 |
-
n_sample: int = 3,
|
674 |
seed: int = None,
|
|
|
675 |
req: gr.Request = None,
|
676 |
):
|
677 |
if isinstance(image_wh, int):
|
|
|
30 |
import torch.nn.functional as F
|
31 |
import trimesh
|
32 |
from easydict import EasyDict as edict
|
33 |
+
from gradio.themes import Soft
|
34 |
+
from gradio.themes.utils.colors import gray, neutral, slate, stone, teal, zinc
|
35 |
from PIL import Image
|
36 |
from embodied_gen.data.backproject_v2 import entrypoint as backproject_api
|
37 |
from embodied_gen.data.differentiable_render import entrypoint as render_api
|
|
|
235 |
</style>
|
236 |
"""
|
237 |
|
238 |
+
custom_theme = Soft(
|
239 |
+
primary_hue=stone,
|
240 |
+
secondary_hue=gray,
|
241 |
+
radius_size="md",
|
242 |
+
text_size="sm",
|
243 |
+
spacing_size="sm",
|
244 |
+
)
|
245 |
+
|
246 |
|
247 |
def start_session(req: gr.Request) -> None:
|
248 |
user_dir = os.path.join(TMP_DIR, str(req.session_hash))
|
|
|
680 |
ip_adapt_scale: float = 0.3,
|
681 |
image_wh: int | tuple[int, int] = [1024, 1024],
|
682 |
rmbg_tag: str = "rembg",
|
|
|
683 |
seed: int = None,
|
684 |
+
n_sample: int = 3,
|
685 |
req: gr.Request = None,
|
686 |
):
|
687 |
if isinstance(image_wh, int):
|
embodied_gen/models/text_model.py
CHANGED
@@ -16,10 +16,10 @@
|
|
16 |
|
17 |
|
18 |
import logging
|
|
|
19 |
|
20 |
-
import torch
|
21 |
import numpy as np
|
22 |
-
import
|
23 |
from diffusers import (
|
24 |
AutoencoderKL,
|
25 |
EulerDiscreteScheduler,
|
@@ -143,9 +143,10 @@ def text2img_gen(
|
|
143 |
seed: int = None,
|
144 |
) -> list[Image.Image]:
|
145 |
prompt = "Single " + prompt + ", in the center of the image"
|
146 |
-
prompt += ", high quality, high resolution, best quality, white background, 3D style
|
147 |
logger.info(f"Processing prompt: {prompt}")
|
148 |
|
|
|
149 |
if seed is not None:
|
150 |
generator = torch.Generator(pipeline.device).manual_seed(seed)
|
151 |
torch.manual_seed(seed)
|
|
|
16 |
|
17 |
|
18 |
import logging
|
19 |
+
import random
|
20 |
|
|
|
21 |
import numpy as np
|
22 |
+
import torch
|
23 |
from diffusers import (
|
24 |
AutoencoderKL,
|
25 |
EulerDiscreteScheduler,
|
|
|
143 |
seed: int = None,
|
144 |
) -> list[Image.Image]:
|
145 |
prompt = "Single " + prompt + ", in the center of the image"
|
146 |
+
prompt += ", high quality, high resolution, best quality, white background, 3D style" # noqa
|
147 |
logger.info(f"Processing prompt: {prompt}")
|
148 |
|
149 |
+
generator = None
|
150 |
if seed is not None:
|
151 |
generator = torch.Generator(pipeline.device).manual_seed(seed)
|
152 |
torch.manual_seed(seed)
|
embodied_gen/scripts/imageto3d.py
CHANGED
@@ -70,7 +70,9 @@ IMAGESR_MODEL = ImageRealESRGAN(outscale=4)
|
|
70 |
RBG_REMOVER = RembgRemover()
|
71 |
RBG14_REMOVER = BMGG14Remover()
|
72 |
SAM_PREDICTOR = SAMPredictor(model_type="vit_h", device="cpu")
|
73 |
-
PIPELINE = TrellisImageTo3DPipeline.from_pretrained(
|
|
|
|
|
74 |
PIPELINE.cuda()
|
75 |
SEG_CHECKER = ImageSegChecker(GPT_CLIENT)
|
76 |
GEO_CHECKER = MeshGeoChecker(GPT_CLIENT)
|
|
|
70 |
RBG_REMOVER = RembgRemover()
|
71 |
RBG14_REMOVER = BMGG14Remover()
|
72 |
SAM_PREDICTOR = SAMPredictor(model_type="vit_h", device="cpu")
|
73 |
+
PIPELINE = TrellisImageTo3DPipeline.from_pretrained(
|
74 |
+
"microsoft/TRELLIS-image-large"
|
75 |
+
)
|
76 |
PIPELINE.cuda()
|
77 |
SEG_CHECKER = ImageSegChecker(GPT_CLIENT)
|
78 |
GEO_CHECKER = MeshGeoChecker(GPT_CLIENT)
|