Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,12 +39,13 @@ for p in (MODELS, LORA, UPSCALE): p.mkdir(parents=True, exist_ok=True)
|
|
| 39 |
# 3. モデル ID / ファイル
|
| 40 |
##############################################################################
|
| 41 |
# --- BRA v7 (公開) ---
|
| 42 |
-
BRA_REPO = "AIGaming/beautiful_realistic_asians"
|
| 43 |
BRA_FILE = "beautifulRealistic_v7.safetensors"
|
| 44 |
BRA_REV = "801a9b1999dd7018e58a1e2b432fdccd3d1d723d" # 固定 revision
|
| 45 |
|
| 46 |
# --- IP-Adapter 本体 & LoRA ---
|
| 47 |
-
|
|
|
|
| 48 |
LORA_REPO,IP_LORA = "h94/IP-Adapter-FaceID", "ip-adapter-faceid-plusv2_sd15_lora.safetensors"
|
| 49 |
|
| 50 |
# --- ControlNet (MediaPipe Face) ---
|
|
@@ -93,9 +94,10 @@ def init():
|
|
| 93 |
pipe_.scheduler = DPMSolverMultistepScheduler.from_config(pipe_.scheduler.config)
|
| 94 |
|
| 95 |
# 6-4 IP-Adapter
|
| 96 |
-
|
|
|
|
| 97 |
ip_lora = dl(LORA_REPO, IP_LORA)
|
| 98 |
-
pipe_.load_ip_adapter(str(ip_bin.parent),
|
| 99 |
AttnProcsLayers(pipe_.unet.attn_processors).load_lora_weights(
|
| 100 |
ip_lora, adapter_name="ip_faceid", safe_load=True
|
| 101 |
)
|
|
@@ -135,7 +137,8 @@ def generate(face: Image.Image, subj: str, add: str, neg: str,
|
|
| 135 |
num_inference_steps=steps, guidance_scale=cfg,
|
| 136 |
image=face, width=w, height=h).images[0]
|
| 137 |
if up:
|
| 138 |
-
upsampler.scale = 4 if upf==4 else 8
|
|
|
|
| 139 |
img, _ = upsampler.enhance(np.array(img)); img = Image.fromarray(img)
|
| 140 |
return img
|
| 141 |
|
|
@@ -152,7 +155,8 @@ with gr.Blocks(title="BRA v7 × InstantID (ZeroGPU)") as demo:
|
|
| 152 |
with gr.Row():
|
| 153 |
st = gr.Slider(10,50,30,1,"Steps"); W = gr.Slider(512,1024,768,64,"W"); H = gr.Slider(512,1024,768,64,"H")
|
| 154 |
with gr.Row():
|
| 155 |
-
|
|
|
|
| 156 |
btn = gr.Button("Generate"); out = gr.Image(type="pil", label="Result")
|
| 157 |
btn.click(generate, [f,s,ap,ng,cf,ip,st,W,H,up,upf], out, show_progress=True)
|
| 158 |
|
|
@@ -173,4 +177,4 @@ async def api_gen(subj: str=Form(...), cfg: float=Form(7.5), stp: int=Form(30),
|
|
| 173 |
##############################################################################
|
| 174 |
# 11. Launch
|
| 175 |
##############################################################################
|
| 176 |
-
demo.queue(default_concurrency_limit=2).launch(share=False)
|
|
|
|
| 39 |
# 3. モデル ID / ファイル
|
| 40 |
##############################################################################
|
| 41 |
# --- BRA v7 (公開) ---
|
| 42 |
+
BRA_REPO = "AIGaming/beautiful_realistic_asians"
|
| 43 |
BRA_FILE = "beautifulRealistic_v7.safetensors"
|
| 44 |
BRA_REV = "801a9b1999dd7018e58a1e2b432fdccd3d1d723d" # 固定 revision
|
| 45 |
|
| 46 |
# --- IP-Adapter 本体 & LoRA ---
|
| 47 |
+
### 修正 ### IP-Adapterのファイルは 'models' サブフォルダにあります
|
| 48 |
+
IP_REPO, IP_SUBF, IP_BIN = "h94/IP-Adapter", "models", "ip-adapter-plus-face_sd15.bin"
|
| 49 |
LORA_REPO,IP_LORA = "h94/IP-Adapter-FaceID", "ip-adapter-faceid-plusv2_sd15_lora.safetensors"
|
| 50 |
|
| 51 |
# --- ControlNet (MediaPipe Face) ---
|
|
|
|
| 94 |
pipe_.scheduler = DPMSolverMultistepScheduler.from_config(pipe_.scheduler.config)
|
| 95 |
|
| 96 |
# 6-4 IP-Adapter
|
| 97 |
+
### 修正 ### dl関数にサブフォルダ(IP_SUBF)を渡します
|
| 98 |
+
ip_bin = dl(IP_REPO, IP_BIN, sub=IP_SUBF)
|
| 99 |
ip_lora = dl(LORA_REPO, IP_LORA)
|
| 100 |
+
pipe_.load_ip_adapter(str(ip_bin.parent.parent), IP_SUBF, ip_bin.name) # load_ip_adapterはサブフォルダを要求します
|
| 101 |
AttnProcsLayers(pipe_.unet.attn_processors).load_lora_weights(
|
| 102 |
ip_lora, adapter_name="ip_faceid", safe_load=True
|
| 103 |
)
|
|
|
|
| 137 |
num_inference_steps=steps, guidance_scale=cfg,
|
| 138 |
image=face, width=w, height=h).images[0]
|
| 139 |
if up:
|
| 140 |
+
# upsampler.scale = 4 if upf==4 else 8 <- This is also a bug, radio button gives string value
|
| 141 |
+
upsampler.scale = int(upf)
|
| 142 |
img, _ = upsampler.enhance(np.array(img)); img = Image.fromarray(img)
|
| 143 |
return img
|
| 144 |
|
|
|
|
| 155 |
with gr.Row():
|
| 156 |
st = gr.Slider(10,50,30,1,"Steps"); W = gr.Slider(512,1024,768,64,"W"); H = gr.Slider(512,1024,768,64,"H")
|
| 157 |
with gr.Row():
|
| 158 |
+
# ### 修正 ### gr.Radioはデフォルトで文字列を返すため、infoを追加して型を明示します
|
| 159 |
+
up = gr.Checkbox(label="Real-ESRGAN"); upf = gr.Radio([4,8], value=4, label="アップスケール", info="Upscale factor")
|
| 160 |
btn = gr.Button("Generate"); out = gr.Image(type="pil", label="Result")
|
| 161 |
btn.click(generate, [f,s,ap,ng,cf,ip,st,W,H,up,upf], out, show_progress=True)
|
| 162 |
|
|
|
|
| 177 |
##############################################################################
|
| 178 |
# 11. Launch
|
| 179 |
##############################################################################
|
| 180 |
+
demo.queue(default_concurrency_limit=2).launch(share=False)
|