SanskarModi commited on
Commit
73b6fa7
·
1 Parent(s): 1d603ac

updated scheduler for turbo model

Browse files
.gradio/certificate.pem ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
3
+ TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
4
+ cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
5
+ WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
6
+ ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
7
+ MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
8
+ h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
9
+ 0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
10
+ A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
11
+ T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH
12
+ B5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+UC
13
+ B5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJBdiB3QW0KtZB6awBdpUKD9jf1b0SHzUv
14
+ KBds0pjBqAlkd25HN7rOrFleaJ1/ctaJxQZBKT5ZPt0m9STJ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xgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
31
+ -----END CERTIFICATE-----
src/sdgen/sd/pipeline.py CHANGED
@@ -8,7 +8,7 @@ from typing import Optional
8
  import torch
9
  from diffusers import (
10
  DPMSolverMultistepScheduler,
11
- EulerAncestralDiscreteScheduler,
12
  StableDiffusionPipeline,
13
  )
14
 
@@ -54,7 +54,7 @@ def load_pipeline(
54
  if scheduler is None:
55
  try:
56
  if "turbo" in model_id.lower():
57
- scheduler = EulerAncestralDiscreteScheduler.from_pretrained(
58
  model_id,
59
  subfolder="scheduler",
60
  )
@@ -127,7 +127,7 @@ def warmup_pipeline(
127
  pipe(
128
  prompt=prompt,
129
  num_inference_steps=1,
130
- guidance_scale=1.0,
131
  height=height,
132
  width=width,
133
  generator=generator,
 
8
  import torch
9
  from diffusers import (
10
  DPMSolverMultistepScheduler,
11
+ LCMScheduler,
12
  StableDiffusionPipeline,
13
  )
14
 
 
54
  if scheduler is None:
55
  try:
56
  if "turbo" in model_id.lower():
57
+ scheduler = LCMScheduler.from_pretrained(
58
  model_id,
59
  subfolder="scheduler",
60
  )
 
127
  pipe(
128
  prompt=prompt,
129
  num_inference_steps=1,
130
+ guidance_scale=0.0,
131
  height=height,
132
  width=width,
133
  generator=generator,
src/sdgen/ui/layout.py CHANGED
@@ -40,11 +40,11 @@ def _resolve_seed(value: Any) -> int | None:
40
  return None
41
 
42
 
43
- def _update_steps(model):
44
  """Upate steps based on the model."""
45
  if model == "Turbo":
46
- return gr.update(minimum=1, maximum=10, value=6, step=1)
47
- return gr.update(minimum=10, maximum=30, value=20, step=1)
48
 
49
 
50
  def _txt2img_handler(
@@ -195,8 +195,7 @@ def build_ui(txt2img_pipes: dict, img2img_pipes: dict) -> gr.Blocks:
195
  with gr.Blocks() as demo:
196
  gr.Markdown(
197
  "# Stable Diffusion Generator\n"
198
- "Clean, local Stable \
199
- Diffusion toolkit."
200
  )
201
 
202
  model_choice = gr.Dropdown(
@@ -207,6 +206,7 @@ def build_ui(txt2img_pipes: dict, img2img_pipes: dict) -> gr.Blocks:
207
  value="SD1.5",
208
  label="Model",
209
  )
 
210
 
211
  txt_controls = build_txt2img_tab(
212
  make_txt2img_handler(model_choice.value, txt2img_pipes),
@@ -228,14 +228,14 @@ def build_ui(txt2img_pipes: dict, img2img_pipes: dict) -> gr.Blocks:
228
  build_history_tab()
229
 
230
  model_choice.change(
231
- fn=_update_steps,
232
  inputs=[model_choice],
233
- outputs=[txt_controls.steps],
234
  )
235
  model_choice.change(
236
- fn=_update_steps,
237
  inputs=[model_choice],
238
- outputs=[img_controls.steps],
239
  )
240
 
241
  gr.Markdown(
@@ -243,9 +243,7 @@ def build_ui(txt2img_pipes: dict, img2img_pipes: dict) -> gr.Blocks:
243
  "- Use **History → Refresh** if new entries do not appear.\n"
244
  "- Presets apply to both **Text → Image** and \
245
  **Image → Image** tabs.\n"
246
- "- Inference speed will be much faster on GPU \
247
- (This app is hosted on CPU based HF Spaces).\n"
248
- "- Use Turbo model if you prefer speed over performance."
249
  )
250
 
251
  return demo
 
40
  return None
41
 
42
 
43
+ def _update_steps_and_cfg(model):
44
  """Upate steps based on the model."""
45
  if model == "Turbo":
46
+ return (gr.update(minimum=1, maximum=5, value=2, step=1), gr.update(minimum=0, maximum=0, value=0, step=0))
47
+ return (gr.update(minimum=10, maximum=30, value=20, step=1), 7.5)
48
 
49
 
50
  def _txt2img_handler(
 
195
  with gr.Blocks() as demo:
196
  gr.Markdown(
197
  "# Stable Diffusion Generator\n"
198
+ "Generation can take from few seconds to several minutes based on the Model selceted and applied settings."
 
199
  )
200
 
201
  model_choice = gr.Dropdown(
 
206
  value="SD1.5",
207
  label="Model",
208
  )
209
+ gr.Markdown("Use Turbo model if you prefer speed over quality.")
210
 
211
  txt_controls = build_txt2img_tab(
212
  make_txt2img_handler(model_choice.value, txt2img_pipes),
 
228
  build_history_tab()
229
 
230
  model_choice.change(
231
+ fn=_update_steps_and_cfg,
232
  inputs=[model_choice],
233
+ outputs=[txt_controls.steps, txt_controls.guidance],
234
  )
235
  model_choice.change(
236
+ fn=_update_steps_and_cfg,
237
  inputs=[model_choice],
238
+ outputs=[img_controls.steps, img_controls.guidance],
239
  )
240
 
241
  gr.Markdown(
 
243
  "- Use **History → Refresh** if new entries do not appear.\n"
244
  "- Presets apply to both **Text → Image** and \
245
  **Image → Image** tabs.\n"
246
+ "- This app is hosted on CPU based HF Spaces, so generation may take some time, please be patient.\n"
 
 
247
  )
248
 
249
  return demo
src/sdgen/ui/tabs/img2img_tab.py CHANGED
@@ -52,7 +52,7 @@ def build_img2img_tab(handler: Callable[..., Tuple[Any, dict]]) -> Img2ImgContro
52
  strength = gr.Slider(
53
  minimum=0.1,
54
  maximum=1.0,
55
- value=0.6,
56
  step=0.05,
57
  label="Strength",
58
  )
@@ -88,7 +88,7 @@ the prompt more strictly. "
88
  value="",
89
  placeholder="Leave empty for random",
90
  )
91
-
92
  generate_button = gr.Button("Generate")
93
 
94
  with gr.Column():
 
52
  strength = gr.Slider(
53
  minimum=0.1,
54
  maximum=1.0,
55
+ value=0.5,
56
  step=0.05,
57
  label="Strength",
58
  )
 
88
  value="",
89
  placeholder="Leave empty for random",
90
  )
91
+ gr.Markdown("If using Turbo model, ensure steps*strength >=1")
92
  generate_button = gr.Button("Generate")
93
 
94
  with gr.Column():