Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@
|
|
| 7 |
from huggingface_hub import hf_hub_download
|
| 8 |
import huggingface_hub as _hf_hub
|
| 9 |
|
| 10 |
-
# diffusers-0.27
|
| 11 |
if not hasattr(_hf_hub, "cached_download"):
|
| 12 |
_hf_hub.cached_download = hf_hub_download
|
| 13 |
|
|
@@ -110,8 +110,8 @@ def initialize_pipelines():
|
|
| 110 |
|
| 111 |
# 6-2 ControlNet(CrucibleAI / diffusion_sd15)
|
| 112 |
controlnet = ControlNetModel.from_pretrained(
|
| 113 |
-
"CrucibleAI/ControlNetMediaPipeFace", #
|
| 114 |
-
subfolder="diffusion_sd15", #
|
| 115 |
torch_dtype=torch.float16,
|
| 116 |
cache_dir=str(MODELS_DIR),
|
| 117 |
)
|
|
@@ -132,8 +132,17 @@ def initialize_pipelines():
|
|
| 132 |
subfolder="scheduler",
|
| 133 |
cache_dir=str(MODELS_DIR),
|
| 134 |
)
|
| 135 |
-
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
AttnProcsLayers(pipe_tmp.unet.attn_processors).load_lora_weights(
|
| 138 |
ip_lora, adapter_name="ip_faceid", safe_load=True
|
| 139 |
)
|
|
@@ -142,13 +151,13 @@ def initialize_pipelines():
|
|
| 142 |
|
| 143 |
pipe = pipe_tmp
|
| 144 |
|
| 145 |
-
# 6-
|
| 146 |
face_analyser = FaceAnalysis(
|
| 147 |
name="buffalo_l", root=str(MODELS_DIR), providers=["CUDAExecutionProvider"]
|
| 148 |
)
|
| 149 |
face_analyser.prepare(ctx_id=0, det_size=(640, 640))
|
| 150 |
|
| 151 |
-
# 6-
|
| 152 |
esrgan_ckpt = download(REALESRGAN_URL, UPSCALE_DIR / "realesrgan_x4plus.pth")
|
| 153 |
upsampler = RealESRGANer(
|
| 154 |
scale=4,
|
|
|
|
| 7 |
from huggingface_hub import hf_hub_download
|
| 8 |
import huggingface_hub as _hf_hub
|
| 9 |
|
| 10 |
+
# diffusers-0.27 は cached_download() を呼び出すため、v0.28+ でも使えるよう注入
|
| 11 |
if not hasattr(_hf_hub, "cached_download"):
|
| 12 |
_hf_hub.cached_download = hf_hub_download
|
| 13 |
|
|
|
|
| 110 |
|
| 111 |
# 6-2 ControlNet(CrucibleAI / diffusion_sd15)
|
| 112 |
controlnet = ControlNetModel.from_pretrained(
|
| 113 |
+
"CrucibleAI/ControlNetMediaPipeFace", # 公開リポジトリ :contentReference[oaicite:0]{index=0}
|
| 114 |
+
subfolder="diffusion_sd15", # SD-1.5 用フォルダ :contentReference[oaicite:1]{index=1}
|
| 115 |
torch_dtype=torch.float16,
|
| 116 |
cache_dir=str(MODELS_DIR),
|
| 117 |
)
|
|
|
|
| 132 |
subfolder="scheduler",
|
| 133 |
cache_dir=str(MODELS_DIR),
|
| 134 |
)
|
| 135 |
+
|
| 136 |
+
# 6-4 **IP-Adapter 読み込み(API 仕様は positional 三つ)**
|
| 137 |
+
# diffusers-0.27.2 では subfolder / weight_name が必須 :contentReference[oaicite:2]{index=2}
|
| 138 |
+
ip_dir = ip_bin.parent
|
| 139 |
+
pipe_tmp.load_ip_adapter(
|
| 140 |
+
str(ip_dir), # path or repo id
|
| 141 |
+
"", # subfolder(ファイル直下なので空文字列)
|
| 142 |
+
ip_bin.name # weight_name
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
# IP-Adapter の追加 LoRA を合流
|
| 146 |
AttnProcsLayers(pipe_tmp.unet.attn_processors).load_lora_weights(
|
| 147 |
ip_lora, adapter_name="ip_faceid", safe_load=True
|
| 148 |
)
|
|
|
|
| 151 |
|
| 152 |
pipe = pipe_tmp
|
| 153 |
|
| 154 |
+
# 6-5 InsightFace
|
| 155 |
face_analyser = FaceAnalysis(
|
| 156 |
name="buffalo_l", root=str(MODELS_DIR), providers=["CUDAExecutionProvider"]
|
| 157 |
)
|
| 158 |
face_analyser.prepare(ctx_id=0, det_size=(640, 640))
|
| 159 |
|
| 160 |
+
# 6-6 Real-ESRGAN
|
| 161 |
esrgan_ckpt = download(REALESRGAN_URL, UPSCALE_DIR / "realesrgan_x4plus.pth")
|
| 162 |
upsampler = RealESRGANer(
|
| 163 |
scale=4,
|