RyanHangZhou commited on
Commit
dba7566
·
verified ·
1 Parent(s): dadfc60

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -6
app.py CHANGED
@@ -8,6 +8,7 @@ import numpy as np
8
  import spaces
9
  from omegaconf import OmegaConf
10
  from huggingface_hub import snapshot_download
 
11
 
12
  REPO_DIR = snapshot_download(repo_id="Hang2991/PICS")
13
  os.chdir(REPO_DIR)
@@ -87,6 +88,9 @@ def process_composition(item, obj_thr):
87
  item.update({'hint': collage_final.copy()})
88
  return item
89
 
 
 
 
90
 
91
  @spaces.GPU(duration=120)
92
  def pics_pairwise_inference(background, img_a, mask_a, img_b, mask_b):
@@ -189,18 +193,32 @@ with gr.Blocks(title="PICS: Pairwise Spatial Compositing with Spatial Interactio
189
 
190
  # --- 核心修改:把 Examples 放在这里 ---
191
  gr.Markdown("### 💡 Quick Examples")
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  gr.Examples(
193
  examples=[
194
  [
195
- "sample/bread_basket/image.jpg",
196
- "sample/bread_basket/object_0.png", "sample/bread_basket/object_0_mask.png",
197
- "sample/bread_basket/object_1.png", "sample/bread_basket/object_1_mask.png"
 
 
198
  ]
199
  ],
200
  inputs=[bg_input, obj_a_img, obj_a_mask, obj_b_img, obj_b_mask],
201
- outputs=output_img, # 现在它认识个变量
202
- fn=pics_pairwise_inference,
203
- cache_examples=True,
204
  )
205
 
206
  # 按钮绑定
 
8
  import spaces
9
  from omegaconf import OmegaConf
10
  from huggingface_hub import snapshot_download
11
+ from PIL import Image
12
 
13
  REPO_DIR = snapshot_download(repo_id="Hang2991/PICS")
14
  os.chdir(REPO_DIR)
 
88
  item.update({'hint': collage_final.copy()})
89
  return item
90
 
91
+ def load_example_pil(path):
92
+ # 因为你已经执行了 os.chdir(REPO_DIR),所以直接读取相对路径
93
+ return Image.open(path).convert("RGB")
94
 
95
  @spaces.GPU(duration=120)
96
  def pics_pairwise_inference(background, img_a, mask_a, img_b, mask_b):
 
193
 
194
  # --- 核心修改:把 Examples 放在这里 ---
195
  gr.Markdown("### 💡 Quick Examples")
196
+ # gr.Examples(
197
+ # examples=[
198
+ # [
199
+ # "sample/bread_basket/image.jpg",
200
+ # "sample/bread_basket/object_0.png", "sample/bread_basket/object_0_mask.png",
201
+ # "sample/bread_basket/object_1.png", "sample/bread_basket/object_1_mask.png"
202
+ # ]
203
+ # ],
204
+ # inputs=[bg_input, obj_a_img, obj_a_mask, obj_b_img, obj_b_mask],
205
+ # outputs=output_img, # 现在它认识这个变量了
206
+ # fn=pics_pairwise_inference,
207
+ # cache_examples=True,
208
+ # )
209
  gr.Examples(
210
  examples=[
211
  [
212
+ load_example_pil("sample/bread_basket/image.jpg"),
213
+ load_example_pil("sample/bread_basket/object_0.png"),
214
+ load_example_pil("sample/bread_basket/object_0_mask.png"),
215
+ load_example_pil("sample/bread_basket/object_1.png"),
216
+ load_example_pil("sample/bread_basket/object_1_mask.png")
217
  ]
218
  ],
219
  inputs=[bg_input, obj_a_img, obj_a_mask, obj_b_img, obj_b_mask],
220
+ # 注意:里去掉 outputs 和 fn,先只做“点一下填入图片”的功能
221
+ cache_examples=False,
 
222
  )
223
 
224
  # 按钮绑定