salso commited on
Commit
f1e6a3a
·
verified ·
1 Parent(s): 238511a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -25
app.py CHANGED
@@ -135,34 +135,54 @@ 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 _load_and_show(subj_path, bg_path, prompt_text):
139
- out_path = subj_path.replace(".png", "_out.png")
140
- return (
141
- Image.open(subj_path),
142
- Image.open(bg_path),
143
- prompt_text,
144
- Image.open(out_path)
145
- )
146
-
147
- # ---------- Examples ----------------------------------------
148
- gr.Examples(
149
- examples=[
150
- ["examples/sofa1_1.png", "examples/sofa1_bg.png", "add the sofa"], #"examples/sofa1_out.png"],
151
- ["examples/sofa2.png", "examples/sofa2_bg.png", "add this sofa"],# "examples/sofa2_out.png"],
152
- ["examples/chair1.png", "examples/chair1_bg.png", "add the chair"], #"examples/chair1_out.png"],
153
- ["examples/console_table.png", "examples/console_table_bg.png", "Scandinavian console table against a gallery-style wall filled with abstract framed art,"], #"examples/console_table_out.png"],
154
- ["examples/office_chair.png", "examples/office_chair_bg.png", "office chair"], #"examples/office_chair_out.png"],
155
- ["examples/car.png", "examples/car_bg.png", "car on the road"], #"examples/car_out.png"],
 
 
 
 
 
 
 
156
  ],
157
- inputs=[subj_img, ref_img, promptbox], # three inputs
158
- outputs=[subj_img, ref_img, promptbox, output_img], #
159
- fn=_load_and_show,
160
- label="Visual Presets – Subject · Background · Prompt",
161
- examples_per_page="all",
162
- cache_examples=False,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  )
164
 
165
-
166
  # ---------- Buttons & interactions --------------------------
167
  # run_btn.click(
168
  # process_image_and_text,
 
135
  bg_img = gr.Image(label="Background", visible=True)
136
 
137
  # ---------- Example wrapper ---------------------------------
138
+ from pathlib import Path
139
+ def load_pil(path): # utility so code looks tidy
140
+ return Image.open(Path(path))
141
+
142
+ examples = [
143
+ [
144
+ load_pil("examples/sofa1.png"), # subject image (PIL)
145
+ {"image": load_pil("examples/sofa1_bg.png"), # sketch widget expects dict
146
+ "mask": None},
147
+ "add the sofa"
148
+ ],
149
+ [
150
+ load_pil("examples/sofa2.png"),
151
+ {"image": load_pil("examples/sofa2_bg.png"), "mask": None},
152
+ "add this sofa"
153
+ ],
154
+ [
155
+ load_pil("examples/chair1.png"),
156
+ {"image": load_pil("examples/chair1_bg.png"), "mask": None},
157
+ "add the chair"
158
+ ],
159
+ [
160
+ load_pil("examples/console_table.png"),
161
+ {"image": load_pil("examples/console_table_bg.png"), "mask": None},
162
+ "Scandinavian console table against a gallery-style wall filled with abstract framed art,"
163
  ],
164
+ [
165
+ load_pil("examples/office_chair.png"),
166
+ {"image": load_pil("examples/office_chair_bg.png"), "mask": None},
167
+ "office chair"
168
+ ],
169
+ [
170
+ load_pil("examples/car.png"),
171
+ {"image": load_pil("examples/car_bg.png"), "mask": None},
172
+ "car on the road"
173
+ ],
174
+ ]
175
+
176
+ # ---------- Examples block ------------------------
177
+ gr.Examples(
178
+ examples = examples,
179
+ inputs = [subj_img, ref_img, promptbox], # match the three widgets
180
+ label = "Visual Presets – Subject · Background · Prompt",
181
+ examples_per_page = "all",
182
+ cache_examples = False, # no need to cache; we’re only auto-filling widgets
183
+ preprocess = False # tell Gradio “the values are already in widget format”
184
  )
185
 
 
186
  # ---------- Buttons & interactions --------------------------
187
  # run_btn.click(
188
  # process_image_and_text,