Nekochu commited on
Commit
d2ee310
·
1 Parent(s): 575e392

add strength slider for edit, default 0.3

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -174,7 +174,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, seed):
178
  gc.collect()
179
  print(f"\n{'='*60}", flush=True)
180
  print(f"[gen] START {time.strftime('%H:%M:%S')}", flush=True)
@@ -214,6 +214,7 @@ def generate(prompt, negative_prompt, init_image, model_choice, aspect_ratio, st
214
 
215
  if pil_input is not None:
216
  kwargs["init_image"] = pil_input
 
217
 
218
  mode = "edit" if pil_input else "txt2img"
219
  print(f"[gen] {mode} {w}x{h} steps={steps} cfg={cfg_scale} guidance={guidance} seed={seed}", flush=True)
@@ -293,10 +294,11 @@ def cli_main():
293
  parser.add_argument("--steps", type=int, default=4)
294
  parser.add_argument("--cfg", type=float, default=2.5)
295
  parser.add_argument("--guidance", type=float, default=3.0)
 
296
  parser.add_argument("--seed", type=int, default=-1)
297
  args = parser.parse_args()
298
 
299
- for img, status in generate(args.prompt, args.negative, args.init_image, args.model, args.aspect, args.steps, args.cfg, args.guidance, args.seed):
300
  if img:
301
  img.save(args.output)
302
  print(f"Saved: {args.output} ({status})")
@@ -326,6 +328,8 @@ def gradio_main():
326
  steps = gr.Slider(1, 50, value=4, step=1, label="Steps", scale=1)
327
  cfg_scale = gr.Slider(1.0, 7.0, value=2.5, step=0.5, label="CFG", scale=1)
328
  guidance = gr.Slider(1.0, 10.0, value=3.0, step=0.5, label="Guidance", scale=1)
 
 
329
  seed = gr.Number(value=-1, label="Seed", precision=0, scale=1)
330
  with gr.Column(variant="panel", scale=1, min_width=280):
331
  output_image = gr.Image(label="Output", type="pil", height=380)
@@ -339,7 +343,7 @@ def gradio_main():
339
 
340
  gen_btn.click(
341
  fn=generate,
342
- inputs=[prompt, negative_prompt, init_image, model_choice, aspect_ratio, steps, cfg_scale, guidance, seed],
343
  outputs=[output_image, status_text],
344
  api_name="infer", concurrency_limit=1,
345
  )
 
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)
 
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
  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
  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
 
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
  )