multimodalart HF staff commited on
Commit
7a8e3f2
1 Parent(s): 5e55cac

Small perf and overall changes

Browse files
Files changed (1) hide show
  1. app.py +12 -14
app.py CHANGED
@@ -22,7 +22,9 @@ from tqdm import tqdm
22
  from safetensors.torch import load_file
23
  from huggingface_hub import hf_hub_download
24
 
25
- DESCRIPTION = "# Latent Consistency Model"
 
 
26
  if not torch.cuda.is_available():
27
  DESCRIPTION += "\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>"
28
 
@@ -78,7 +80,6 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
78
  seed = random.randint(0, MAX_SEED)
79
  return seed
80
 
81
-
82
  def generate(
83
  prompt: str,
84
  seed: int = 0,
@@ -87,11 +88,11 @@ def generate(
87
  guidance_scale: float = 8.0,
88
  num_inference_steps: int = 4,
89
  num_images: int = 4,
 
 
90
  ) -> PIL.Image.Image:
 
91
  torch.manual_seed(seed)
92
-
93
- # if width > 512 or height > 512:
94
- # num_images = 2
95
  start_time = time.time()
96
  result = pipe(
97
  prompt=prompt,
@@ -103,8 +104,9 @@ def generate(
103
  lcm_origin_steps=50,
104
  output_type="pil",
105
  ).images
 
106
  print(time.time() - start_time)
107
- return result
108
 
109
  examples = [
110
  "portrait photo of a girl, photograph, highly detailed face, depth of field, moody light, golden hour, style by Dan Winters, Russell James, Steve McCurry, centered, extremely detailed, Nikon D850, award winning photography",
@@ -140,8 +142,9 @@ with gr.Blocks(css="style.css") as demo:
140
  maximum=MAX_SEED,
141
  step=1,
142
  value=0,
 
143
  )
144
- randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
145
  with gr.Row():
146
  width = gr.Slider(
147
  label="Width",
@@ -194,12 +197,6 @@ with gr.Blocks(css="style.css") as demo:
194
  prompt.submit,
195
  run_button.click,
196
  ],
197
- fn=randomize_seed_fn,
198
- inputs=[seed, randomize_seed],
199
- outputs=seed,
200
- queue=False,
201
- api_name=False,
202
- ).then(
203
  fn=generate,
204
  inputs=[
205
  prompt,
@@ -209,10 +206,11 @@ with gr.Blocks(css="style.css") as demo:
209
  guidance_scale,
210
  num_inference_steps,
211
  ],
212
- outputs=result,
213
  api_name="run",
214
  )
215
 
216
  if __name__ == "__main__":
 
217
  # demo.queue(max_size=20).launch()
218
  demo.launch()
 
22
  from safetensors.torch import load_file
23
  from huggingface_hub import hf_hub_download
24
 
25
+ DESCRIPTION = '''# Latent Consistency Model
26
+ #### Distilled from Dreamshaper v7 fine-tune of [Stable Diffusion v1-5](https://huggingface.co/runwayml/stable-diffusion-v1-5). [Project page](https://latent-consistency-models.github.io)
27
+ '''
28
  if not torch.cuda.is_available():
29
  DESCRIPTION += "\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>"
30
 
 
80
  seed = random.randint(0, MAX_SEED)
81
  return seed
82
 
 
83
  def generate(
84
  prompt: str,
85
  seed: int = 0,
 
88
  guidance_scale: float = 8.0,
89
  num_inference_steps: int = 4,
90
  num_images: int = 4,
91
+ randomize_seed: bool = False,
92
+ progress = gr.Progress(track_tqdm=True)
93
  ) -> PIL.Image.Image:
94
+ seed = randomize_seed_fn(seed, randomize_seed)
95
  torch.manual_seed(seed)
 
 
 
96
  start_time = time.time()
97
  result = pipe(
98
  prompt=prompt,
 
104
  lcm_origin_steps=50,
105
  output_type="pil",
106
  ).images
107
+
108
  print(time.time() - start_time)
109
+ return result, seed
110
 
111
  examples = [
112
  "portrait photo of a girl, photograph, highly detailed face, depth of field, moody light, golden hour, style by Dan Winters, Russell James, Steve McCurry, centered, extremely detailed, Nikon D850, award winning photography",
 
142
  maximum=MAX_SEED,
143
  step=1,
144
  value=0,
145
+ randomize=True
146
  )
147
+ randomize_seed = gr.Checkbox(label="Randomize seed across runs", value=True)
148
  with gr.Row():
149
  width = gr.Slider(
150
  label="Width",
 
197
  prompt.submit,
198
  run_button.click,
199
  ],
 
 
 
 
 
 
200
  fn=generate,
201
  inputs=[
202
  prompt,
 
206
  guidance_scale,
207
  num_inference_steps,
208
  ],
209
+ outputs=[result, seed],
210
  api_name="run",
211
  )
212
 
213
  if __name__ == "__main__":
214
+ demo.queue(api_open=False)
215
  # demo.queue(max_size=20).launch()
216
  demo.launch()