Rentolly commited on
Commit
41b1f90
·
1 Parent(s): 81e61bf

移除推薦參數 Presets 的定義與相關函式,更新範例圖片至 .png 格式

Browse files
Files changed (2) hide show
  1. app.py +4 -49
  2. examples/miku.png +3 -0
app.py CHANGED
@@ -118,35 +118,6 @@ 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
- # 推薦參數 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
  # -----------------------------
@@ -154,7 +125,7 @@ with gr.Blocks(title="NoobAI-XL + BLIP", theme=gr.themes.Soft()) as demo:
154
  gr.Markdown(
155
  """
156
  # SDXL (Laxhar/noobai-XL-1.0) + BLIP
157
- 動漫風格的 Stable Diffusion XL 模型,搭配 BLIP 影像描述模型。
158
  每個 Step 大約需要 1 分鐘的 CPU 運算時間,請耐心等候。
159
  """
160
  )
@@ -177,11 +148,6 @@ with gr.Blocks(title="NoobAI-XL + BLIP", theme=gr.themes.Soft()) as demo:
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,16 +183,6 @@ with gr.Blocks(title="NoobAI-XL + BLIP", theme=gr.themes.Soft()) as demo:
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():
@@ -241,14 +197,13 @@ with gr.Blocks(title="NoobAI-XL + BLIP", theme=gr.themes.Soft()) as demo:
241
 
242
  gr.Examples(
243
  examples=[
244
- ["examples/gura.jpg", "masterpiece, best quality, amazing quality, highres, absurdres, 1girl, virtual youtuber, gawr gura, solo, blue hair, grey hair, medium hair, long hair, multicolored hair, streaked hair, bangs, blunt bangs, side ponytail, blue eyes, sharp teeth, teeth, fang, cat ears, hair ornament, blue nails, shark tail, nail polish, tail, fish tail, teeth, shark girl, sleeveless, dress, shirt, :d, blush, smile, paw pose, open mouth, full body, simple_background, looking_at_viewer, upper_body, front view, bubble, flat color, no lineart", "worst quality, old, early, low quality, lowres, signature, username, logo, bad hands, mutated hands, mammal, anthro, furry, ambiguous form, feral, semi-anthro, nsfw", 20, 7.0, 42, "DPM++ 2M (DPMSolverMultistep)", True, 768, 768],
245
- ["examples/cat_girl.jpg", "masterpiece, best quality, amazing quality, highres, absurdres, 1girl, clean lineart, usnr, :d, cat_pose, blush, kawaii, white hair, long hair, hair between eyes, bangs, pink eyes, fang, pink_nails, open mouth, white fake cat ears, simple_background, hugging a cat, light pink dress, hair ornament, long sleeves, puffy long sleeves, pink bow, puffy sleeves, black choker, upper body, looking_at_viewer, front view", "worst quality, old, early, low quality, lowres, signature, username, logo, bad hands, mutated hands, mammal, anthro, furry, ambiguous form, feral, semi-anthro, nsfw", 20, 8.0, 1234, "DPM++ 2M (DPMSolverMultistep)", True, 768, 768],
246
- # ["examples/miku.jpg", "masterpiece, best quality, amazing quality, highres, absurdres, 1girl, hatsune miku, white pupils, power elements, microphone, vibrant blue color palette, abstract,abstract background, dreamlike atmosphere, delicate linework, wind-swept hair, energy", "worst quality, old, early, low quality, lowres, signature, username, logo, bad hands, mutated hands, mammal, anthro, furry, ambiguous form, feral, semi-anthro, nsfw", 28, 7.0, 24, "DPM++ 2M (DPMSolverMultistep)", True, 768, 768],
247
  ],
248
  inputs=[in_img, prompt, neg_prompt, steps, guidance, seed, scheduler_name, use_karras, width, height],
249
  label="Prompt 範例(可直接點選)",
250
  )
251
 
252
  if __name__ == "__main__":
253
- # 在 HF Spaces 使用:不用 demo.launch(share=True)
254
  demo.launch()
 
118
  caption = BLIP_PROCESSOR.decode(out[0], skip_special_tokens=True)
119
  return caption
120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  # -----------------------------
122
  # Gradio 介面
123
  # -----------------------------
 
125
  gr.Markdown(
126
  """
127
  # SDXL (Laxhar/noobai-XL-1.0) + BLIP
128
+ 動漫風格的 Stable Diffusion XL 模型,搭配 BLIP 影像描述模型。\n
129
  每個 Step 大約需要 1 分鐘的 CPU 運算時間,請耐心等候。
130
  """
131
  )
 
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
  [out_img, status]
184
  )
185
 
 
 
 
 
 
 
 
 
 
 
186
  # Tab 2: Image -> Caption
187
  with gr.TabItem("Image → Caption"):
188
  with gr.Row():
 
197
 
198
  gr.Examples(
199
  examples=[
200
+ ["examples/miku.png", "masterpiece, best quality, amazing quality, highres, absurdres, 1girl, hatsune miku, white pupils, power elements, microphone, vibrant blue color palette, abstract,abstract background, dreamlike atmosphere, delicate linework, wind-swept hair, energy", "worst quality, old, early, low quality, lowres, signature, username, logo, bad hands, mutated hands, mammal, anthro, furry, ambiguous form, feral, semi-anthro, nsfw", 28, 7.0, 24, "DPM++ 2M (DPMSolverMultistep)", True, 768, 768],
201
+ ["examples/gura.png", "masterpiece, best quality, amazing quality, highres, absurdres, 1girl, virtual youtuber, gawr gura, solo, blue hair, grey hair, medium hair, long hair, multicolored hair, streaked hair, bangs, blunt bangs, side ponytail, blue eyes, sharp teeth, teeth, fang, cat ears, hair ornament, blue nails, shark tail, nail polish, tail, fish tail, teeth, shark girl, sleeveless, dress, shirt, :d, blush, smile, paw pose, open mouth, full body, simple_background, looking_at_viewer, upper_body, front view, bubble, flat color, no lineart", "worst quality, old, early, low quality, lowres, signature, username, logo, bad hands, mutated hands, mammal, anthro, furry, ambiguous form, feral, semi-anthro, nsfw", 20, 7.0, 42, "DPM++ 2M (DPMSolverMultistep)", True, 768, 768],
202
+ ["examples/cat_girl.png", "masterpiece, best quality, amazing quality, highres, absurdres, 1girl, clean lineart, usnr, :d, cat_pose, blush, kawaii, white hair, long hair, hair between eyes, bangs, pink eyes, fang, pink_nails, open mouth, white fake cat ears, simple_background, hugging a cat, light pink dress, hair ornament, long sleeves, puffy long sleeves, pink bow, puffy sleeves, black choker, upper body, looking_at_viewer, front view", "worst quality, old, early, low quality, lowres, signature, username, logo, bad hands, mutated hands, mammal, anthro, furry, ambiguous form, feral, semi-anthro, nsfw", 20, 8.0, 1234, "DPM++ 2M (DPMSolverMultistep)", True, 768, 768],
203
  ],
204
  inputs=[in_img, prompt, neg_prompt, steps, guidance, seed, scheduler_name, use_karras, width, height],
205
  label="Prompt 範例(可直接點選)",
206
  )
207
 
208
  if __name__ == "__main__":
 
209
  demo.launch()
examples/miku.png ADDED

Git LFS Details

  • SHA256: b8061a1143733f61c6491eb90d740a32a7a74715d32635569ec049ea1629baa2
  • Pointer size: 131 Bytes
  • Size of remote file: 822 kB