Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -20,6 +20,8 @@ from diffusers import (
|
|
20 |
StableDiffusionPipeline, ControlNetModel,
|
21 |
DPMSolverMultistepScheduler, AutoencoderKL,
|
22 |
)
|
|
|
|
|
23 |
from insightface.app import FaceAnalysis
|
24 |
|
25 |
##############################################################################
|
@@ -161,6 +163,13 @@ for emb in EMB_DIR.glob("*.*"):
|
|
161 |
except Exception:
|
162 |
print("emb skip →", emb.name)
|
163 |
pipe.to(device)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
print("pipeline ready ✔")
|
165 |
|
166 |
##############################################################################
|
@@ -183,10 +192,11 @@ except Exception as e:
|
|
183 |
##############################################################################
|
184 |
# 4. プロンプト & 生成関数
|
185 |
##############################################################################
|
|
|
186 |
BASE_PROMPT = (
|
187 |
"masterpiece, ultra-realistic photo of {subject}, "
|
188 |
"cinematic lighting, shallow depth of field, textured skin, "
|
189 |
-
"Canon EOS R5 85 mm f/1.4
|
190 |
)
|
191 |
NEG_PROMPT = (
|
192 |
"ng_deepnegative_v1_75t, CyberRealistic_Negative-neg, UnrealisticDream, "
|
@@ -197,6 +207,7 @@ NEG_PROMPT = (
|
|
197 |
"missing arms, missing legs, (badhandv4:0.7), BadNegAnatomyV1-neg, skin blemishes, acnes, age spot, glans"
|
198 |
)
|
199 |
|
|
|
200 |
@spaces.GPU(duration=90)
|
201 |
def generate(
|
202 |
face_np, subject, add_prompt, add_neg, cfg, ip_scale, steps, w, h, upscale, up_factor,
|
@@ -213,9 +224,13 @@ def generate(
|
|
213 |
pipe.set_ip_adapter_scale(ip_scale)
|
214 |
img_in = Image.fromarray(face_np)
|
215 |
|
|
|
|
|
|
|
|
|
216 |
result = pipe(
|
217 |
-
|
218 |
-
|
219 |
ip_adapter_image=img_in,
|
220 |
#image=img_in,
|
221 |
#controlnet_conditioning_scale=0.9,
|
|
|
20 |
StableDiffusionPipeline, ControlNetModel,
|
21 |
DPMSolverMultistepScheduler, AutoencoderKL,
|
22 |
)
|
23 |
+
# +++ 修正点A: compel ライブラリをインポート +++
|
24 |
+
from compel import Compel
|
25 |
from insightface.app import FaceAnalysis
|
26 |
|
27 |
##############################################################################
|
|
|
163 |
except Exception:
|
164 |
print("emb skip →", emb.name)
|
165 |
pipe.to(device)
|
166 |
+
|
167 |
+
# +++ 修正点B: compel プロセッサを初期化 +++
|
168 |
+
compel_proc = Compel(
|
169 |
+
tokenizer=pipe.tokenizer,
|
170 |
+
text_encoder=pipe.text_encoder,
|
171 |
+
truncate_long_prompts=False # 長いプロンプトを切り捨てない
|
172 |
+
)
|
173 |
print("pipeline ready ✔")
|
174 |
|
175 |
##############################################################################
|
|
|
192 |
##############################################################################
|
193 |
# 4. プロンプト & 生成関数
|
194 |
##############################################################################
|
195 |
+
# +++ 修正点C: 不要な <lora:...> 記述を削除 +++
|
196 |
BASE_PROMPT = (
|
197 |
"masterpiece, ultra-realistic photo of {subject}, "
|
198 |
"cinematic lighting, shallow depth of field, textured skin, "
|
199 |
+
"Canon EOS R5 85 mm f/1.4"
|
200 |
)
|
201 |
NEG_PROMPT = (
|
202 |
"ng_deepnegative_v1_75t, CyberRealistic_Negative-neg, UnrealisticDream, "
|
|
|
207 |
"missing arms, missing legs, (badhandv4:0.7), BadNegAnatomyV1-neg, skin blemishes, acnes, age spot, glans"
|
208 |
)
|
209 |
|
210 |
+
# +++ 修正点D: generate関数全体をcompel対応版に書き換え +++
|
211 |
@spaces.GPU(duration=90)
|
212 |
def generate(
|
213 |
face_np, subject, add_prompt, add_neg, cfg, ip_scale, steps, w, h, upscale, up_factor,
|
|
|
224 |
pipe.set_ip_adapter_scale(ip_scale)
|
225 |
img_in = Image.fromarray(face_np)
|
226 |
|
227 |
+
# compel を使ってプロンプトをエンベディングに変換
|
228 |
+
prompt_embeds = compel_proc(prompt)
|
229 |
+
negative_prompt_embeds = compel_proc(neg)
|
230 |
+
|
231 |
result = pipe(
|
232 |
+
prompt_embeds=prompt_embeds,
|
233 |
+
negative_prompt_embeds=negative_prompt_embeds,
|
234 |
ip_adapter_image=img_in,
|
235 |
#image=img_in,
|
236 |
#controlnet_conditioning_scale=0.9,
|