feat: add CoverCraft LoRA + dropdown preset (字体参考)
Browse files
app.py
CHANGED
|
@@ -140,11 +140,33 @@ try:
|
|
| 140 |
weight_name="FireRed-Image-Edit-1.0-Lightning-8steps-v1.1.safetensors",
|
| 141 |
adapter_name="lightning",
|
| 142 |
)
|
| 143 |
-
pipe.set_adapters(["lightning"], adapter_weights=[1.0])
|
| 144 |
print("Lightning LoRA (FireRed 8steps v1.1) loaded successfully.")
|
| 145 |
except Exception as e:
|
| 146 |
print(f"Warning: Could not load Lightning LoRA: {e}")
|
| 147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
# ── RMBG 2.0 抠图模型 ──
|
| 149 |
rmbg = AutoModelForImageSegmentation.from_pretrained(
|
| 150 |
"briaai/RMBG-2.0",
|
|
@@ -487,6 +509,7 @@ def infer(
|
|
| 487 |
guidance_scale,
|
| 488 |
steps,
|
| 489 |
color_match,
|
|
|
|
| 490 |
out_width=0,
|
| 491 |
out_height=0,
|
| 492 |
progress=gr.Progress(track_tqdm=True),
|
|
@@ -500,6 +523,13 @@ def infer(
|
|
| 500 |
if not prompt or not prompt.strip():
|
| 501 |
raise gr.Error("⚠️ Please enter an edit prompt.")
|
| 502 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 503 |
# 提取原图(兼容 ImageEditor dict 和普通路径)
|
| 504 |
try:
|
| 505 |
src_pil = extract_pil_from_source(source_image)
|
|
@@ -715,6 +745,12 @@ with gr.Blocks(
|
|
| 715 |
|
| 716 |
color_match_input = gr.Checkbox(label="Color Match — 色彩对齐原图", value=True)
|
| 717 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 718 |
with gr.Accordion("Advanced Settings", open=False):
|
| 719 |
seed_input = gr.Slider(
|
| 720 |
label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0,
|
|
@@ -745,7 +781,7 @@ with gr.Blocks(
|
|
| 745 |
inputs=[
|
| 746 |
source_input, ref_input, prompt_input, negative_prompt_input,
|
| 747 |
seed_input, randomize_seed_input, guidance_scale_input, steps_input,
|
| 748 |
-
color_match_input,
|
| 749 |
],
|
| 750 |
outputs=[output_image, seed_input],
|
| 751 |
).then(
|
|
|
|
| 140 |
weight_name="FireRed-Image-Edit-1.0-Lightning-8steps-v1.1.safetensors",
|
| 141 |
adapter_name="lightning",
|
| 142 |
)
|
|
|
|
| 143 |
print("Lightning LoRA (FireRed 8steps v1.1) loaded successfully.")
|
| 144 |
except Exception as e:
|
| 145 |
print(f"Warning: Could not load Lightning LoRA: {e}")
|
| 146 |
|
| 147 |
+
# ── CoverCraft LoRA(FireRed 官方字体参考 LoRA)──
|
| 148 |
+
try:
|
| 149 |
+
pipe.load_lora_weights(
|
| 150 |
+
"FireRedTeam/FireRed-Image-Edit-LoRA-Zoo",
|
| 151 |
+
weight_name="FireRed-Image-Edit-Covercraft.safetensors",
|
| 152 |
+
adapter_name="covercraft",
|
| 153 |
+
)
|
| 154 |
+
print("CoverCraft LoRA (字体参考) loaded successfully.")
|
| 155 |
+
except Exception as e:
|
| 156 |
+
print(f"Warning: Could not load CoverCraft LoRA: {e}")
|
| 157 |
+
|
| 158 |
+
# 默认仅启用 Lightning
|
| 159 |
+
try:
|
| 160 |
+
pipe.set_adapters(["lightning"], adapter_weights=[1.0])
|
| 161 |
+
except Exception as e:
|
| 162 |
+
print(f"Warning: Could not set default adapters: {e}")
|
| 163 |
+
|
| 164 |
+
# LoRA 预设映射(UI 下拉选项 → adapter 配置)
|
| 165 |
+
LORA_PRESETS = {
|
| 166 |
+
"无": (["lightning"], [1.0]),
|
| 167 |
+
"字体参考": (["lightning", "covercraft"], [1.0, 1.0]),
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
# ── RMBG 2.0 抠图模型 ──
|
| 171 |
rmbg = AutoModelForImageSegmentation.from_pretrained(
|
| 172 |
"briaai/RMBG-2.0",
|
|
|
|
| 509 |
guidance_scale,
|
| 510 |
steps,
|
| 511 |
color_match,
|
| 512 |
+
lora_preset="无",
|
| 513 |
out_width=0,
|
| 514 |
out_height=0,
|
| 515 |
progress=gr.Progress(track_tqdm=True),
|
|
|
|
| 523 |
if not prompt or not prompt.strip():
|
| 524 |
raise gr.Error("⚠️ Please enter an edit prompt.")
|
| 525 |
|
| 526 |
+
# 切换 LoRA 预设
|
| 527 |
+
preset_cfg = LORA_PRESETS.get(lora_preset, LORA_PRESETS["无"])
|
| 528 |
+
try:
|
| 529 |
+
pipe.set_adapters(preset_cfg[0], adapter_weights=preset_cfg[1])
|
| 530 |
+
except Exception as e:
|
| 531 |
+
print(f"Warning: could not switch LoRA preset '{lora_preset}': {e}")
|
| 532 |
+
|
| 533 |
# 提取原图(兼容 ImageEditor dict 和普通路径)
|
| 534 |
try:
|
| 535 |
src_pil = extract_pil_from_source(source_image)
|
|
|
|
| 745 |
|
| 746 |
color_match_input = gr.Checkbox(label="Color Match — 色彩对齐原图", value=True)
|
| 747 |
|
| 748 |
+
lora_preset_input = gr.Dropdown(
|
| 749 |
+
label="LoRA 预设",
|
| 750 |
+
choices=list(LORA_PRESETS.keys()),
|
| 751 |
+
value="无",
|
| 752 |
+
)
|
| 753 |
+
|
| 754 |
with gr.Accordion("Advanced Settings", open=False):
|
| 755 |
seed_input = gr.Slider(
|
| 756 |
label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0,
|
|
|
|
| 781 |
inputs=[
|
| 782 |
source_input, ref_input, prompt_input, negative_prompt_input,
|
| 783 |
seed_input, randomize_seed_input, guidance_scale_input, steps_input,
|
| 784 |
+
color_match_input, lora_preset_input,
|
| 785 |
],
|
| 786 |
outputs=[output_image, seed_input],
|
| 787 |
).then(
|