Spaces:
Sleeping
Sleeping
新增推薦參數 Presets,提供多種預設設定以簡化用戶操作;新增對應的解析函式以支援選擇預設
Browse files
app.py
CHANGED
|
@@ -118,6 +118,35 @@ def caption_image(image: Image.Image, max_len: int = 50):
|
|
| 118 |
caption = BLIP_PROCESSOR.decode(out[0], skip_special_tokens=True)
|
| 119 |
return caption
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
# -----------------------------
|
| 122 |
# Gradio 介面
|
| 123 |
# -----------------------------
|
|
@@ -148,6 +177,11 @@ with gr.Blocks(title="NoobAI-XL + BLIP", theme=gr.themes.Soft()) as demo:
|
|
| 148 |
use_karras = gr.Checkbox(value=True, label="使用 Karras Sigmas")
|
| 149 |
width = gr.Slider(256, 1536, value=768, step=8, label="寬度 Width")
|
| 150 |
height = gr.Slider(256, 1536, value=768, step=8, label="高度 Height")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
run_btn = gr.Button("圖片生成", variant="primary")
|
| 152 |
|
| 153 |
with gr.Column(scale=1):
|
|
@@ -183,6 +217,16 @@ with gr.Blocks(title="NoobAI-XL + BLIP", theme=gr.themes.Soft()) as demo:
|
|
| 183 |
[out_img, status]
|
| 184 |
)
|
| 185 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
# Tab 2: Image -> Caption
|
| 187 |
with gr.TabItem("Image → Caption"):
|
| 188 |
with gr.Row():
|
|
|
|
| 118 |
caption = BLIP_PROCESSOR.decode(out[0], skip_special_tokens=True)
|
| 119 |
return caption
|
| 120 |
|
| 121 |
+
# -----------------------------
|
| 122 |
+
# 推薦參數 Presets(新增)
|
| 123 |
+
# -----------------------------
|
| 124 |
+
# 說明:
|
| 125 |
+
# - CPU_Quick:在 CPU 上較快出圖(較小解析度、較少步數)
|
| 126 |
+
# - Balanced:一般情境(SDXL sweet-spot)
|
| 127 |
+
# - HQ_GPU:偏重品質(建議 GPU),CPU 可能很慢
|
| 128 |
+
PRESETS = {
|
| 129 |
+
"CPU_Quick": {
|
| 130 |
+
"steps": 16, "guidance": 6.5, "scheduler": "Euler A",
|
| 131 |
+
"use_karras": True, "width": 640, "height": 896,
|
| 132 |
+
},
|
| 133 |
+
"Balanced": {
|
| 134 |
+
"steps": 20, "guidance": 7.0, "scheduler": "DPM++ 2M (DPMSolverMultistep)",
|
| 135 |
+
"use_karras": True, "width": 768, "height": 768,
|
| 136 |
+
},
|
| 137 |
+
"HQ_GPU": {
|
| 138 |
+
"steps": 28, "guidance": 7.5, "scheduler": "DPM++ 2M (DPMSolverMultistep)",
|
| 139 |
+
"use_karras": True, "width": 1024, "height": 1024,
|
| 140 |
+
},
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
def resolve_preset(name: str):
|
| 144 |
+
p = PRESETS.get(name, PRESETS["Balanced"])
|
| 145 |
+
return (
|
| 146 |
+
int(p["steps"]), float(p["guidance"]), p["scheduler"], bool(p["use_karras"]),
|
| 147 |
+
int(p["width"]), int(p["height"]), p["neg"]
|
| 148 |
+
)
|
| 149 |
+
|
| 150 |
# -----------------------------
|
| 151 |
# Gradio 介面
|
| 152 |
# -----------------------------
|
|
|
|
| 177 |
use_karras = gr.Checkbox(value=True, label="使用 Karras Sigmas")
|
| 178 |
width = gr.Slider(256, 1536, value=768, step=8, label="寬度 Width")
|
| 179 |
height = gr.Slider(256, 1536, value=768, step=8, label="高度 Height")
|
| 180 |
+
ti_preset = gr.Dropdown(
|
| 181 |
+
choices=list(PRESETS.keys()),
|
| 182 |
+
value="Balanced",
|
| 183 |
+
label="推薦參數 Preset"
|
| 184 |
+
)
|
| 185 |
run_btn = gr.Button("圖片生成", variant="primary")
|
| 186 |
|
| 187 |
with gr.Column(scale=1):
|
|
|
|
| 217 |
[out_img, status]
|
| 218 |
)
|
| 219 |
|
| 220 |
+
def _apply_ti_preset(name):
|
| 221 |
+
steps, guidance, sched, karras, w, h, neg = resolve_preset(name)
|
| 222 |
+
return steps, guidance, sched, karras, w, h, neg
|
| 223 |
+
|
| 224 |
+
ti_preset.change(
|
| 225 |
+
_apply_ti_preset,
|
| 226 |
+
inputs=[ti_preset],
|
| 227 |
+
outputs=[steps, guidance, scheduler_name, use_karras, width, height, neg_prompt]
|
| 228 |
+
)
|
| 229 |
+
|
| 230 |
# Tab 2: Image -> Caption
|
| 231 |
with gr.TabItem("Image → Caption"):
|
| 232 |
with gr.Row():
|