salso commited on
Commit
f448ff5
·
verified ·
1 Parent(s): 5a9de69

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -16
app.py CHANGED
@@ -135,33 +135,38 @@ with gr.Blocks(css=css, title="ZenCtrl Inpainting") as demo:
135
  bg_img = gr.Image(label="Background", visible=True)
136
 
137
  # ---------- Example wrapper ---------------------------------
138
- def ex(subj, bg): # ← both string paths
 
 
 
 
139
  return [
140
- subj, # goes to subj_img (Image widget)
141
- {"image": bg, "mask": None}, # goes to ref_img (sketch widget)
142
- "prompt text here" # goes to promptbox (Textbox)
143
  ]
144
 
145
  examples = [
146
- ex("examples/sofa1.png", "examples/sofa1_bg.png")[:2] + ["add the sofa"],
147
- ex("examples/sofa2.png", "examples/sofa2_bg.png")[:2] + ["add this sofa"],
148
- ex("examples/chair1.png", "examples/chair1_bg.png")[:2] + ["add the chair"],
149
- ex("examples/console_table.png", "examples/console_table_bg.png")[:2] +
150
- ["Scandinavian console table against a gallery-style wall filled with abstract framed art"],
151
- ex("examples/office_chair.png", "examples/office_chair_bg.png")[:2] + ["office chair"],
152
- ex("examples/car.png", "examples/car_bg.png")[:2] + ["car on the road"],
 
153
  ]
154
 
155
- def identity(a, b, c): # just pass the filled widgets straight back
 
156
  return a, b, c
157
 
158
  gr.Examples(
159
  examples = examples,
160
  inputs = [subj_img, ref_img, promptbox],
161
- outputs = [subj_img, ref_img, promptbox], # <- MUST match `identity`
162
- fn = identity, # <- avoids missing table
163
- cache_examples = False, # fine now
164
- preprocess = False, # data already in widget form
165
  label = "Visual Presets – Subject · Background · Prompt",
166
  examples_per_page = "all",
167
  )
 
135
  bg_img = gr.Image(label="Background", visible=True)
136
 
137
  # ---------- Example wrapper ---------------------------------
138
+ from pathlib import Path
139
+ def pil(path): # open once, keep handles alive for the table
140
+ return Image.open(Path(path))
141
+
142
+ def row(subj_path, bg_path, prompt):
143
  return [
144
+ pil(subj_path), # goes to subj_img (Image widget)
145
+ {"image": pil(bg_path), "mask": None}, # ref_img (sketch widget)
146
+ prompt # promptbox (Textbox)
147
  ]
148
 
149
  examples = [
150
+ row("examples/sofa1.png", "examples/sofa1_bg.png", "add the sofa"),
151
+ row("examples/sofa2.png", "examples/sofa2_bg.png", "add this sofa"),
152
+ row("examples/chair1.png", "examples/chair1_bg.png", "add the chair"),
153
+ row("examples/console_table.png",
154
+ "examples/console_table_bg.png",
155
+ "Scandinavian console table against a gallery-style wall filled with abstract framed art"),
156
+ row("examples/office_chair.png", "examples/office_chair_bg.png", "office chair"),
157
+ row("examples/car.png", "examples/car_bg.png", "car on the road"),
158
  ]
159
 
160
+ # identity returns the filled-in widgets unchanged
161
+ def identity(a, b, c):
162
  return a, b, c
163
 
164
  gr.Examples(
165
  examples = examples,
166
  inputs = [subj_img, ref_img, promptbox],
167
+ outputs = [subj_img, ref_img, promptbox], # must match `identity`
168
+ fn = identity,
169
+ cache_examples = False, # fine – we’re not pre-computing anything
 
170
  label = "Visual Presets – Subject · Background · Prompt",
171
  examples_per_page = "all",
172
  )