Yjiggfghhjnjj commited on
Commit
2b4fa1a
1 Parent(s): 7e8b99c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -98
app.py CHANGED
@@ -40,54 +40,6 @@ RealVisXLv4_pipe = DiffusionPipeline.from_pretrained(
40
  variant="fp16"
41
  )
42
  RealVisXLv4_pipe.to("cuda")
43
- ### SDXL Turbo ####
44
- pipe_turbo = StableDiffusionXLPipeline.from_pretrained("stabilityai/sdxl-turbo",
45
- vae=vae,
46
- torch_dtype=torch.float16,
47
- variant="fp16"
48
- )
49
- pipe_turbo.to("cuda")
50
-
51
- ### SDXL Lightning ###
52
- base = "stabilityai/stable-diffusion-xl-base-1.0"
53
- repo = "ByteDance/SDXL-Lightning"
54
- ckpt = "sdxl_lightning_1step_unet_x0.safetensors"
55
-
56
- unet = UNet2DConditionModel.from_config(base, subfolder="unet").to(torch.float16)
57
- unet.load_state_dict(load_file(hf_hub_download(repo, ckpt)))
58
- pipe_lightning = StableDiffusionXLPipeline.from_pretrained(base,
59
- unet=unet,
60
- vae=vae,
61
- text_encoder=pipe_turbo.text_encoder,
62
- text_encoder_2=pipe_turbo.text_encoder_2,
63
- tokenizer=pipe_turbo.tokenizer,
64
- tokenizer_2=pipe_turbo.tokenizer_2,
65
- torch_dtype=torch.float16,
66
- variant="fp16"
67
- )#.to("cuda")
68
- del unet
69
- pipe_lightning.scheduler = EulerDiscreteScheduler.from_config(pipe_lightning.scheduler.config, timestep_spacing="trailing", prediction_type="sample")
70
- pipe_lightning.to("cuda")
71
-
72
- ### Hyper SDXL ###
73
- repo_name = "ByteDance/Hyper-SD"
74
- ckpt_name = "Hyper-SDXL-1step-Unet.safetensors"
75
-
76
- unet = UNet2DConditionModel.from_config(base, subfolder="unet").to(torch.float16)
77
- unet.load_state_dict(load_file(hf_hub_download(repo_name, ckpt_name)))
78
- pipe_hyper = StableDiffusionXLPipeline.from_pretrained(base,
79
- unet=unet,
80
- vae=vae,
81
- text_encoder=pipe_turbo.text_encoder,
82
- text_encoder_2=pipe_turbo.text_encoder_2,
83
- tokenizer=pipe_turbo.tokenizer,
84
- tokenizer_2=pipe_turbo.tokenizer_2,
85
- torch_dtype=torch.float16,
86
- variant="fp16"
87
- )#.to("cuda")
88
- pipe_hyper.scheduler = LCMScheduler.from_config(pipe_hyper.scheduler.config)
89
- pipe_hyper.to("cuda")
90
- del unet
91
 
92
  @spaces.GPU
93
  def run_comparison(prompt: str,
@@ -105,45 +57,6 @@ def run_comparison(prompt: str,
105
  seed = int(randomize_seed_fn(seed, randomize_seed))
106
  if not use_negative_prompt:
107
  negative_prompt = ""
108
- image_turbo=pipe_turbo(prompt=prompt,
109
- negative_prompt=negative_prompt,
110
- width=width,
111
- height=height,
112
- guidance_scale=guidance_scale,
113
- num_inference_steps=num_inference_steps,
114
- num_images_per_prompt=num_images_per_prompt,
115
- cross_attention_kwargs={"scale": 0.65},
116
- output_type="pil",
117
- ).images
118
- image_paths = [save_image(img) for img in images]
119
- return image_paths, seed
120
- yield image_turbo, None, None, None, None
121
- image_lightning=pipe_lightning(prompt=prompt,
122
- negative_prompt=negative_prompt,
123
- width=width,
124
- height=height,
125
- guidance_scale=guidance_scale,
126
- num_inference_steps=num_inference_steps,
127
- num_images_per_prompt=num_images_per_prompt,
128
- cross_attention_kwargs={"scale": 0.65},
129
- output_type="pil",
130
- ).images
131
- image_paths = [save_image(img) for img in images]
132
- return image_paths, seed
133
- yield image_turbo, image_lightning, None, None, None
134
- image_hyper=pipe_hyper(prompt=prompt,
135
- negative_prompt=negative_prompt,
136
- width=width,
137
- height=height,
138
- guidance_scale=guidance_scale,
139
- num_inference_steps=num_inference_steps,
140
- num_images_per_prompt=num_images_per_prompt,
141
- cross_attention_kwargs={"scale": 0.65},
142
- output_type="pil",
143
- ).images
144
- image_paths = [save_image(img) for img in images]
145
- return image_paths, seed
146
- yield image_turbo, image_lightning, image_hyper, None, None
147
  image_r3=RealVisXLv3_pipe(prompt=prompt,
148
  negative_prompt=negative_prompt,
149
  width=width,
@@ -156,7 +69,7 @@ def run_comparison(prompt: str,
156
  ).images
157
  image_paths = [save_image(img) for img in images]
158
  return image_paths, seed
159
- yield image_turbo, image_lightning, image_hyper,image_r3, None
160
  image_r4=RealVisXLv4_pipe(prompt=prompt,
161
  negative_prompt=negative_prompt,
162
  width=width,
@@ -169,7 +82,7 @@ def run_comparison(prompt: str,
169
  ).images
170
  image_paths = [save_image(img) for img in images]
171
  return image_paths, seed
172
- yield image_turbo, image_lightning, image_hyper,image_r3, image_r4
173
 
174
  examples = ["A dignified beaver wearing glasses, a vest, and colorful neck tie.",
175
  "The spirit of a tamagotchi wandering in the city of Barcelona",
@@ -245,15 +158,6 @@ with gr.Blocks() as demo:
245
  )
246
 
247
  with gr.Row():
248
- with gr.Column():
249
- image_turbo = gr.Gallery(label="SDXL Turbo",columns=1, preview=True,)
250
- gr.Markdown("## [SDXL Turbo](https://huggingface.co/stabilityai/sdxl-turbo)")
251
- with gr.Column():
252
- image_lightning = gr.Gallery(label="SDXL Lightning",columns=1, preview=True,)
253
- gr.Markdown("## [SDXL Lightning](https://huggingface.co/ByteDance/SDXL-Lightning)")
254
- with gr.Column():
255
- image_hyper = gr.Gallery(label="Hyper SDXL",columns=1, preview=True,)
256
- gr.Markdown("## [Hyper SDXL](https://huggingface.co/ByteDance/Hyper-SD)")
257
  with gr.Column():
258
  image_r3 = gr.Gallery(label="RealVisXL V3",columns=1, preview=True,)
259
  gr.Markdown("## [RealVisXL V3](https://huggingface.co)")
 
40
  variant="fp16"
41
  )
42
  RealVisXLv4_pipe.to("cuda")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
  @spaces.GPU
45
  def run_comparison(prompt: str,
 
57
  seed = int(randomize_seed_fn(seed, randomize_seed))
58
  if not use_negative_prompt:
59
  negative_prompt = ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  image_r3=RealVisXLv3_pipe(prompt=prompt,
61
  negative_prompt=negative_prompt,
62
  width=width,
 
69
  ).images
70
  image_paths = [save_image(img) for img in images]
71
  return image_paths, seed
72
+ yield image_r3, None
73
  image_r4=RealVisXLv4_pipe(prompt=prompt,
74
  negative_prompt=negative_prompt,
75
  width=width,
 
82
  ).images
83
  image_paths = [save_image(img) for img in images]
84
  return image_paths, seed
85
+ yield image_r3, image_r4
86
 
87
  examples = ["A dignified beaver wearing glasses, a vest, and colorful neck tie.",
88
  "The spirit of a tamagotchi wandering in the city of Barcelona",
 
158
  )
159
 
160
  with gr.Row():
 
 
 
 
 
 
 
 
 
161
  with gr.Column():
162
  image_r3 = gr.Gallery(label="RealVisXL V3",columns=1, preview=True,)
163
  gr.Markdown("## [RealVisXL V3](https://huggingface.co)")