Nekochu commited on
Commit
57b643a
·
1 Parent(s): d2ee310

fix: use ref_images + zero_cond_t for proper editing

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -111,6 +111,7 @@ def load_engine(model_name=None):
111
  vae_path=vae_path,
112
  offload_params_to_cpu=True,
113
  diffusion_flash_attn=True,
 
114
  n_threads=N_THREADS,
115
  verbose=True,
116
  )
@@ -174,7 +175,7 @@ def safe_load_image(path, max_px=MAX_INPUT_PX, crop_ratio=None):
174
  print(f"[gen] Center-cropped to {img.size[0]}x{img.size[1]} for {target_w}:{target_h} ratio", flush=True)
175
  return img
176
 
177
- def generate(prompt, negative_prompt, init_image, model_choice, aspect_ratio, steps, cfg_scale, guidance, strength, seed):
178
  gc.collect()
179
  print(f"\n{'='*60}", flush=True)
180
  print(f"[gen] START {time.strftime('%H:%M:%S')}", flush=True)
@@ -213,8 +214,7 @@ def generate(prompt, negative_prompt, init_image, model_choice, aspect_ratio, st
213
  )
214
 
215
  if pil_input is not None:
216
- kwargs["init_image"] = pil_input
217
- kwargs["strength"] = float(strength)
218
 
219
  mode = "edit" if pil_input else "txt2img"
220
  print(f"[gen] {mode} {w}x{h} steps={steps} cfg={cfg_scale} guidance={guidance} seed={seed}", flush=True)
@@ -294,11 +294,10 @@ def cli_main():
294
  parser.add_argument("--steps", type=int, default=4)
295
  parser.add_argument("--cfg", type=float, default=2.5)
296
  parser.add_argument("--guidance", type=float, default=3.0)
297
- parser.add_argument("--strength", type=float, default=0.3)
298
  parser.add_argument("--seed", type=int, default=-1)
299
  args = parser.parse_args()
300
 
301
- for img, status in generate(args.prompt, args.negative, args.init_image, args.model, args.aspect, args.steps, args.cfg, args.guidance, args.strength, args.seed):
302
  if img:
303
  img.save(args.output)
304
  print(f"Saved: {args.output} ({status})")
@@ -328,8 +327,6 @@ def gradio_main():
328
  steps = gr.Slider(1, 50, value=4, step=1, label="Steps", scale=1)
329
  cfg_scale = gr.Slider(1.0, 7.0, value=2.5, step=0.5, label="CFG", scale=1)
330
  guidance = gr.Slider(1.0, 10.0, value=3.0, step=0.5, label="Guidance", scale=1)
331
- with gr.Row():
332
- strength = gr.Slider(0.1, 1.0, value=0.3, step=0.05, label="Strength (edit)", scale=1)
333
  seed = gr.Number(value=-1, label="Seed", precision=0, scale=1)
334
  with gr.Column(variant="panel", scale=1, min_width=280):
335
  output_image = gr.Image(label="Output", type="pil", height=380)
@@ -343,7 +340,7 @@ def gradio_main():
343
 
344
  gen_btn.click(
345
  fn=generate,
346
- inputs=[prompt, negative_prompt, init_image, model_choice, aspect_ratio, steps, cfg_scale, guidance, strength, seed],
347
  outputs=[output_image, status_text],
348
  api_name="infer", concurrency_limit=1,
349
  )
 
111
  vae_path=vae_path,
112
  offload_params_to_cpu=True,
113
  diffusion_flash_attn=True,
114
+ qwen_image_zero_cond_t=True,
115
  n_threads=N_THREADS,
116
  verbose=True,
117
  )
 
175
  print(f"[gen] Center-cropped to {img.size[0]}x{img.size[1]} for {target_w}:{target_h} ratio", flush=True)
176
  return img
177
 
178
+ def generate(prompt, negative_prompt, init_image, model_choice, aspect_ratio, steps, cfg_scale, guidance, seed):
179
  gc.collect()
180
  print(f"\n{'='*60}", flush=True)
181
  print(f"[gen] START {time.strftime('%H:%M:%S')}", flush=True)
 
214
  )
215
 
216
  if pil_input is not None:
217
+ kwargs["ref_images"] = [pil_input]
 
218
 
219
  mode = "edit" if pil_input else "txt2img"
220
  print(f"[gen] {mode} {w}x{h} steps={steps} cfg={cfg_scale} guidance={guidance} seed={seed}", flush=True)
 
294
  parser.add_argument("--steps", type=int, default=4)
295
  parser.add_argument("--cfg", type=float, default=2.5)
296
  parser.add_argument("--guidance", type=float, default=3.0)
 
297
  parser.add_argument("--seed", type=int, default=-1)
298
  args = parser.parse_args()
299
 
300
+ for img, status in generate(args.prompt, args.negative, args.init_image, args.model, args.aspect, args.steps, args.cfg, args.guidance, args.seed):
301
  if img:
302
  img.save(args.output)
303
  print(f"Saved: {args.output} ({status})")
 
327
  steps = gr.Slider(1, 50, value=4, step=1, label="Steps", scale=1)
328
  cfg_scale = gr.Slider(1.0, 7.0, value=2.5, step=0.5, label="CFG", scale=1)
329
  guidance = gr.Slider(1.0, 10.0, value=3.0, step=0.5, label="Guidance", scale=1)
 
 
330
  seed = gr.Number(value=-1, label="Seed", precision=0, scale=1)
331
  with gr.Column(variant="panel", scale=1, min_width=280):
332
  output_image = gr.Image(label="Output", type="pil", height=380)
 
340
 
341
  gen_btn.click(
342
  fn=generate,
343
+ inputs=[prompt, negative_prompt, init_image, model_choice, aspect_ratio, steps, cfg_scale, guidance, seed],
344
  outputs=[output_image, status_text],
345
  api_name="infer", concurrency_limit=1,
346
  )