Spaces:
Running
on
Zero
Running
on
Zero
xinjie.wang
commited on
Commit
·
ee63191
1
Parent(s):
c1dc250
update
Browse files- common.py +0 -32
- embodied_gen/models/text_model.py +38 -1
- embodied_gen/models/texture_model.py +5 -0
common.py
CHANGED
@@ -136,32 +136,6 @@ def patched_setup_functions(self):
|
|
136 |
Gaussian.setup_functions = patched_setup_functions
|
137 |
|
138 |
|
139 |
-
def download_kolors_weights() -> None:
|
140 |
-
logger.info(f"Download kolors weights from huggingface...")
|
141 |
-
subprocess.run(
|
142 |
-
[
|
143 |
-
"huggingface-cli",
|
144 |
-
"download",
|
145 |
-
"--resume-download",
|
146 |
-
"Kwai-Kolors/Kolors",
|
147 |
-
"--local-dir",
|
148 |
-
"weights/Kolors",
|
149 |
-
],
|
150 |
-
check=True,
|
151 |
-
)
|
152 |
-
subprocess.run(
|
153 |
-
[
|
154 |
-
"huggingface-cli",
|
155 |
-
"download",
|
156 |
-
"--resume-download",
|
157 |
-
"Kwai-Kolors/Kolors-IP-Adapter-Plus",
|
158 |
-
"--local-dir",
|
159 |
-
"weights/Kolors-IP-Adapter-Plus",
|
160 |
-
],
|
161 |
-
check=True,
|
162 |
-
)
|
163 |
-
|
164 |
-
|
165 |
if os.getenv("GRADIO_APP") == "imageto3d":
|
166 |
RBG_REMOVER = RembgRemover()
|
167 |
RBG14_REMOVER = BMGG14Remover()
|
@@ -185,9 +159,6 @@ elif os.getenv("GRADIO_APP") == "textto3d":
|
|
185 |
)
|
186 |
# PIPELINE.cuda()
|
187 |
text_model_dir = "weights/Kolors"
|
188 |
-
if not os.path.exists(text_model_dir):
|
189 |
-
download_kolors_weights()
|
190 |
-
|
191 |
PIPELINE_IMG_IP = build_text2img_ip_pipeline(text_model_dir, ref_scale=0.3)
|
192 |
PIPELINE_IMG = build_text2img_pipeline(text_model_dir)
|
193 |
SEG_CHECKER = ImageSegChecker(GPT_CLIENT)
|
@@ -198,9 +169,6 @@ elif os.getenv("GRADIO_APP") == "textto3d":
|
|
198 |
os.path.dirname(os.path.abspath(__file__)), "sessions/textto3d"
|
199 |
)
|
200 |
elif os.getenv("GRADIO_APP") == "texture_edit":
|
201 |
-
if not os.path.exists("weights/Kolors"):
|
202 |
-
download_kolors_weights()
|
203 |
-
|
204 |
PIPELINE_IP = build_texture_gen_pipe(
|
205 |
base_ckpt_dir="./weights",
|
206 |
ip_adapt_scale=0.7,
|
|
|
136 |
Gaussian.setup_functions = patched_setup_functions
|
137 |
|
138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
if os.getenv("GRADIO_APP") == "imageto3d":
|
140 |
RBG_REMOVER = RembgRemover()
|
141 |
RBG14_REMOVER = BMGG14Remover()
|
|
|
159 |
)
|
160 |
# PIPELINE.cuda()
|
161 |
text_model_dir = "weights/Kolors"
|
|
|
|
|
|
|
162 |
PIPELINE_IMG_IP = build_text2img_ip_pipeline(text_model_dir, ref_scale=0.3)
|
163 |
PIPELINE_IMG = build_text2img_pipeline(text_model_dir)
|
164 |
SEG_CHECKER = ImageSegChecker(GPT_CLIENT)
|
|
|
169 |
os.path.dirname(os.path.abspath(__file__)), "sessions/textto3d"
|
170 |
)
|
171 |
elif os.getenv("GRADIO_APP") == "texture_edit":
|
|
|
|
|
|
|
172 |
PIPELINE_IP = build_texture_gen_pipe(
|
173 |
base_ckpt_dir="./weights",
|
174 |
ip_adapt_scale=0.7,
|
embodied_gen/models/text_model.py
CHANGED
@@ -16,8 +16,9 @@
|
|
16 |
|
17 |
|
18 |
import logging
|
|
|
19 |
import random
|
20 |
-
|
21 |
import numpy as np
|
22 |
import torch
|
23 |
from diffusers import (
|
@@ -47,14 +48,47 @@ __all__ = [
|
|
47 |
"build_text2img_ip_pipeline",
|
48 |
"build_text2img_pipeline",
|
49 |
"text2img_gen",
|
|
|
50 |
]
|
51 |
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
def build_text2img_ip_pipeline(
|
54 |
ckpt_dir: str,
|
55 |
ref_scale: float,
|
56 |
device: str = "cuda",
|
57 |
) -> StableDiffusionXLPipelineIP:
|
|
|
|
|
|
|
58 |
text_encoder = ChatGLMModel.from_pretrained(
|
59 |
f"{ckpt_dir}/text_encoder", torch_dtype=torch.float16
|
60 |
).half()
|
@@ -106,6 +140,9 @@ def build_text2img_pipeline(
|
|
106 |
ckpt_dir: str,
|
107 |
device: str = "cuda",
|
108 |
) -> StableDiffusionXLPipeline:
|
|
|
|
|
|
|
109 |
text_encoder = ChatGLMModel.from_pretrained(
|
110 |
f"{ckpt_dir}/text_encoder", torch_dtype=torch.float16
|
111 |
).half()
|
|
|
16 |
|
17 |
|
18 |
import logging
|
19 |
+
import os
|
20 |
import random
|
21 |
+
import subprocess
|
22 |
import numpy as np
|
23 |
import torch
|
24 |
from diffusers import (
|
|
|
48 |
"build_text2img_ip_pipeline",
|
49 |
"build_text2img_pipeline",
|
50 |
"text2img_gen",
|
51 |
+
"download_kolors_weights",
|
52 |
]
|
53 |
|
54 |
|
55 |
+
def download_kolors_weights(local_dir: str = "weights/Kolors") -> None:
|
56 |
+
logger.info(f"Download kolors weights from huggingface...")
|
57 |
+
os.makedirs(local_dir, exist_ok=True)
|
58 |
+
subprocess.run(
|
59 |
+
[
|
60 |
+
"huggingface-cli",
|
61 |
+
"download",
|
62 |
+
"--resume-download",
|
63 |
+
"Kwai-Kolors/Kolors",
|
64 |
+
"--local-dir",
|
65 |
+
local_dir,
|
66 |
+
],
|
67 |
+
check=True,
|
68 |
+
)
|
69 |
+
|
70 |
+
ip_adapter_path = f"{local_dir}/../Kolors-IP-Adapter-Plus"
|
71 |
+
subprocess.run(
|
72 |
+
[
|
73 |
+
"huggingface-cli",
|
74 |
+
"download",
|
75 |
+
"--resume-download",
|
76 |
+
"Kwai-Kolors/Kolors-IP-Adapter-Plus",
|
77 |
+
"--local-dir",
|
78 |
+
ip_adapter_path,
|
79 |
+
],
|
80 |
+
check=True,
|
81 |
+
)
|
82 |
+
|
83 |
+
|
84 |
def build_text2img_ip_pipeline(
|
85 |
ckpt_dir: str,
|
86 |
ref_scale: float,
|
87 |
device: str = "cuda",
|
88 |
) -> StableDiffusionXLPipelineIP:
|
89 |
+
if not os.path.exists(ckpt_dir):
|
90 |
+
download_kolors_weights(ckpt_dir)
|
91 |
+
|
92 |
text_encoder = ChatGLMModel.from_pretrained(
|
93 |
f"{ckpt_dir}/text_encoder", torch_dtype=torch.float16
|
94 |
).half()
|
|
|
140 |
ckpt_dir: str,
|
141 |
device: str = "cuda",
|
142 |
) -> StableDiffusionXLPipeline:
|
143 |
+
if not os.path.exists(ckpt_dir):
|
144 |
+
download_kolors_weights(ckpt_dir)
|
145 |
+
|
146 |
text_encoder = ChatGLMModel.from_pretrained(
|
147 |
f"{ckpt_dir}/text_encoder", torch_dtype=torch.float16
|
148 |
).half()
|
embodied_gen/models/texture_model.py
CHANGED
@@ -28,6 +28,8 @@ from kolors.pipelines.pipeline_controlnet_xl_kolors_img2img import (
|
|
28 |
StableDiffusionXLControlNetImg2ImgPipeline,
|
29 |
)
|
30 |
from transformers import CLIPImageProcessor, CLIPVisionModelWithProjection
|
|
|
|
|
31 |
|
32 |
__all__ = [
|
33 |
"build_texture_gen_pipe",
|
@@ -40,6 +42,9 @@ def build_texture_gen_pipe(
|
|
40 |
ip_adapt_scale: float = 0,
|
41 |
device: str = "cuda",
|
42 |
) -> DiffusionPipeline:
|
|
|
|
|
|
|
43 |
tokenizer = ChatGLMTokenizer.from_pretrained(
|
44 |
f"{base_ckpt_dir}/Kolors/text_encoder"
|
45 |
)
|
|
|
28 |
StableDiffusionXLControlNetImg2ImgPipeline,
|
29 |
)
|
30 |
from transformers import CLIPImageProcessor, CLIPVisionModelWithProjection
|
31 |
+
from embodied_gen.models.text_model import download_kolors_weights
|
32 |
+
|
33 |
|
34 |
__all__ = [
|
35 |
"build_texture_gen_pipe",
|
|
|
42 |
ip_adapt_scale: float = 0,
|
43 |
device: str = "cuda",
|
44 |
) -> DiffusionPipeline:
|
45 |
+
if not os.path.exists(f"{base_ckpt_dir}/Kolors"):
|
46 |
+
download_kolors_weights(f"{base_ckpt_dir}/Kolors")
|
47 |
+
|
48 |
tokenizer = ChatGLMTokenizer.from_pretrained(
|
49 |
f"{base_ckpt_dir}/Kolors/text_encoder"
|
50 |
)
|