i0switch commited on
Commit
10e5cc0
·
verified ·
1 Parent(s): 107a85b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -39,13 +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
- ### 修正 ### 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,10 +94,10 @@ def init():
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,7 +137,6 @@ def generate(face: Image.Image, subj: str, add: str, neg: str,
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
@@ -155,8 +154,7 @@ with gr.Blocks(title="BRA v7 × InstantID (ZeroGPU)") as demo:
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
 
 
39
  # 3. モデル ID / ファイル
40
  ##############################################################################
41
  # --- BRA v7 (公開) ---
42
+ BRA_REPO = "AIGaming/beautiful_realistic_asians" # :contentReference[oaicite:0]
43
  BRA_FILE = "beautifulRealistic_v7.safetensors"
44
  BRA_REV = "801a9b1999dd7018e58a1e2b432fdccd3d1d723d" # 固定 revision
45
 
46
  # --- IP-Adapter 本体 & LoRA ---
47
+ ### 修正 ### 重みファイルへのフルパスを指定し、サブフォルダ定義を削除
48
+ IP_REPO, 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
+ ### 修正 ### load_ip_adapter がダウンロードを処理するため、個別のdlは不要。
98
+ ### また、呼び出し方を修正し、リポジトリIDと重みのフルパスを渡す。
99
  ip_lora = dl(LORA_REPO, IP_LORA)
100
+ pipe_.load_ip_adapter(IP_REPO, weight_name=IP_BIN, cache_dir=str(MODELS))
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 = int(upf)
141
  img, _ = upsampler.enhance(np.array(img)); img = Image.fromarray(img)
142
  return img
 
154
  with gr.Row():
155
  st = gr.Slider(10,50,30,1,"Steps"); W = gr.Slider(512,1024,768,64,"W"); H = gr.Slider(512,1024,768,64,"H")
156
  with gr.Row():
157
+ up = gr.Checkbox(label="Real-ESRGAN"); upf = gr.Radio([4,8], value=4, label="アップスケール")
 
158
  btn = gr.Button("Generate"); out = gr.Image(type="pil", label="Result")
159
  btn.click(generate, [f,s,ap,ng,cf,ip,st,W,H,up,upf], out, show_progress=True)
160