prithivMLmods commited on
Commit
6767b76
1 Parent(s): 33fb8d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -22
app.py CHANGED
@@ -10,7 +10,7 @@ from PIL import Image
10
  import spaces
11
  from typing import Tuple
12
  import torch
13
- from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
14
 
15
  DESCRIPTION = """ """
16
 
@@ -34,20 +34,6 @@ MAX_SEED = np.iinfo(np.int32).max
34
  USE_TORCH_COMPILE = 0
35
  ENABLE_CPU_OFFLOAD = 0
36
 
37
-
38
- if torch.cuda.is_available():
39
- pipe = StableDiffusionXLPipeline.from_pretrained(
40
- "stabilityai/stable-cascade",
41
- torch_dtype=torch.float16,
42
- use_safetensors=True,
43
- )
44
- pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
45
- pipe.load_lora_weights("dataautogpt3/OpenDalleV1.1", weight_name="OpenDalleV1.1.safetensors", adapter_name="dalle")
46
- pipe.set_adapters("dalle")
47
- pipe.to("cuda")
48
-
49
-
50
-
51
  style_list = [
52
  {
53
  "name": "(No style)",
@@ -148,24 +134,36 @@ def generate(
148
  progress=gr.Progress(track_tqdm=True),
149
  ):
150
 
151
-
152
  seed = int(randomize_seed_fn(seed, randomize_seed))
153
 
154
  if not use_negative_prompt:
155
  negative_prompt = "" # type: ignore
156
  prompt, negative_prompt = apply_style(style, prompt, negative_prompt)
157
 
158
- images = pipe(
 
 
 
 
159
  prompt=prompt,
160
- negative_prompt=negative_prompt,
161
- width=width,
162
  height=height,
 
 
163
  guidance_scale=guidance_scale,
164
- num_inference_steps=num_inference_steps,
165
  num_images_per_prompt=num_images_per_prompt,
166
- cross_attention_kwargs={"scale": 0.65},
 
 
 
 
 
 
 
 
167
  output_type="pil",
 
168
  ).images
 
169
  image_paths = [save_image(img) for img in images]
170
  print(image_paths)
171
  return image_paths, seed
@@ -313,4 +311,4 @@ with gr.Blocks(css=css, theme="xiaobaiyuan/theme_brief") as demo:
313
  )
314
 
315
  if __name__ == "__main__":
316
- demo.queue(max_size=20).launch(show_api=False, debug=False)
 
10
  import spaces
11
  from typing import Tuple
12
  import torch
13
+ from diffusers import StableCascadeDecoderPipeline, StableCascadePriorPipeline
14
 
15
  DESCRIPTION = """ """
16
 
 
34
  USE_TORCH_COMPILE = 0
35
  ENABLE_CPU_OFFLOAD = 0
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  style_list = [
38
  {
39
  "name": "(No style)",
 
134
  progress=gr.Progress(track_tqdm=True),
135
  ):
136
 
 
137
  seed = int(randomize_seed_fn(seed, randomize_seed))
138
 
139
  if not use_negative_prompt:
140
  negative_prompt = "" # type: ignore
141
  prompt, negative_prompt = apply_style(style, prompt, negative_prompt)
142
 
143
+ prior = StableCascadePriorPipeline.from_pretrained("stabilityai/stable-cascade-prior", variant="bf16", torch_dtype=torch.bfloat16)
144
+ decoder = StableCascadeDecoderPipeline.from_pretrained("stabilityai/stable-cascade", variant="bf16", torch_dtype=torch.float16)
145
+
146
+ prior.enable_model_cpu_offload()
147
+ prior_output = prior(
148
  prompt=prompt,
 
 
149
  height=height,
150
+ width=width,
151
+ negative_prompt=negative_prompt,
152
  guidance_scale=guidance_scale,
 
153
  num_images_per_prompt=num_images_per_prompt,
154
+ num_inference_steps=num_inference_steps
155
+ )
156
+
157
+ decoder.enable_model_cpu_offload()
158
+ images = decoder(
159
+ image_embeddings=prior_output.image_embeddings.to(torch.float16),
160
+ prompt=prompt,
161
+ negative_prompt=negative_prompt,
162
+ guidance_scale=0.0,
163
  output_type="pil",
164
+ num_inference_steps=10
165
  ).images
166
+
167
  image_paths = [save_image(img) for img in images]
168
  print(image_paths)
169
  return image_paths, seed
 
311
  )
312
 
313
  if __name__ == "__main__":
314
+ demo.queue(max_size=20).launch(show_api=False, debug=False)