sfdhfdjfg commited on
Commit
0e10e07
·
verified ·
1 Parent(s): 055dc56

feat: add lora_strength slider (0-1) for style LoRA

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -522,6 +522,7 @@ def infer(
522
  steps,
523
  color_match,
524
  lora_preset="无",
 
525
  out_width=0,
526
  out_height=0,
527
  progress=gr.Progress(track_tqdm=True),
@@ -535,10 +536,13 @@ def infer(
535
  if not prompt or not prompt.strip():
536
  raise gr.Error("⚠️ Please enter an edit prompt.")
537
 
538
- # 切换 LoRA 预设
539
- preset_cfg = LORA_PRESETS.get(lora_preset, LORA_PRESETS["无"])
 
 
 
540
  try:
541
- pipe.set_adapters(preset_cfg[0], adapter_weights=preset_cfg[1])
542
  except Exception as e:
543
  print(f"Warning: could not switch LoRA preset '{lora_preset}': {e}")
544
 
@@ -762,6 +766,10 @@ with gr.Blocks(
762
  choices=list(LORA_PRESETS.keys()),
763
  value="无",
764
  )
 
 
 
 
765
 
766
  with gr.Accordion("Advanced Settings", open=False):
767
  seed_input = gr.Slider(
@@ -793,7 +801,7 @@ with gr.Blocks(
793
  inputs=[
794
  source_input, ref_input, prompt_input, negative_prompt_input,
795
  seed_input, randomize_seed_input, guidance_scale_input, steps_input,
796
- color_match_input, lora_preset_input,
797
  ],
798
  outputs=[output_image, seed_input],
799
  ).then(
 
522
  steps,
523
  color_match,
524
  lora_preset="无",
525
+ lora_strength=1.0,
526
  out_width=0,
527
  out_height=0,
528
  progress=gr.Progress(track_tqdm=True),
 
536
  if not prompt or not prompt.strip():
537
  raise gr.Error("⚠️ Please enter an edit prompt.")
538
 
539
+ # 切换 LoRA 预设(强度只作用于风格 LoRA,lightning 固定 1.0)
540
+ preset_names, preset_weights = LORA_PRESETS.get(lora_preset, LORA_PRESETS["无"])
541
+ weights = list(preset_weights)
542
+ if len(weights) > 1:
543
+ weights[1] = max(0.0, min(1.0, float(lora_strength)))
544
  try:
545
+ pipe.set_adapters(preset_names, adapter_weights=weights)
546
  except Exception as e:
547
  print(f"Warning: could not switch LoRA preset '{lora_preset}': {e}")
548
 
 
766
  choices=list(LORA_PRESETS.keys()),
767
  value="无",
768
  )
769
+ lora_strength_input = gr.Slider(
770
+ label="LoRA 强度(仅对风格 LoRA 生效)",
771
+ minimum=0.0, maximum=1.0, step=0.05, value=1.0,
772
+ )
773
 
774
  with gr.Accordion("Advanced Settings", open=False):
775
  seed_input = gr.Slider(
 
801
  inputs=[
802
  source_input, ref_input, prompt_input, negative_prompt_input,
803
  seed_input, randomize_seed_input, guidance_scale_input, steps_input,
804
+ color_match_input, lora_preset_input, lora_strength_input,
805
  ],
806
  outputs=[output_image, seed_input],
807
  ).then(