Nick088 commited on
Commit
eb56303
·
verified ·
1 Parent(s): 294f972
Files changed (1) hide show
  1. app.py +44 -43
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import torch
2
- from diffusers import StableDiffusion3Pipeline, StableDiffusionPipeline, StableDiffusionXLPipeline, DPMSolverSinglestepScheduler
3
  import gradio as gr
4
  import os
5
  import random
@@ -29,17 +29,57 @@ sd2_1_pipe = StableDiffusionPipeline.from_pretrained(
29
  )
30
  sd2_1_pipe.to(device)
31
 
32
- sdxl_pipe = StableDiffusionXLPipeline.from_pretrained(
33
  "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
34
  )
35
  sdxl_pipe.to(device)
36
 
37
- sdxl_flash_pipe = StableDiffusionXLPipeline.from_pretrained("sd-community/sdxl-flash", torch_dtype=torch.float16)
 
 
38
  sdxl_flash_pipe.to(device)
39
-
40
  # Ensure sampler uses "trailing" timesteps for sdxl flash.
41
  sdxl_flash_pipe.scheduler = DPMSolverSinglestepScheduler.from_config(sdxl_flash_pipe.scheduler.config, timestep_spacing="trailing")
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  # Define the image generation function for the Arena tab
44
  @spaces.GPU(duration=80)
45
  def generate_arena_images(
@@ -88,45 +128,6 @@ def generate_arena_images(
88
 
89
  return images_1, images_2
90
 
91
-
92
- # Helper function to generate images for a single model
93
- def generate_single_image(
94
- prompt,
95
- negative_prompt,
96
- num_inference_steps,
97
- height,
98
- width,
99
- guidance_scale,
100
- seed,
101
- num_images_per_prompt,
102
- model_choice,
103
- generator,
104
- ):
105
- # Select the correct pipeline based on the model choice
106
- if model_choice == "sd3 medium":
107
- pipe = sd3_medium_pipe
108
- elif model_choice == "sd2.1":
109
- pipe = sd2_1_pipe
110
- elif model_choice == "sdxl":
111
- pipe = sdxl_pipe
112
- elif model_choice == "sdxl flash":
113
- pipe = sdxl_flash_pipe
114
- else:
115
- raise ValueError(f"Invalid model choice: {model_choice}")
116
-
117
- output = pipe(
118
- prompt=prompt,
119
- negative_prompt=negative_prompt,
120
- num_inference_steps=num_inference_steps,
121
- height=height,
122
- width=width,
123
- guidance_scale=guidance_scale,
124
- generator=generator,
125
- num_images_per_prompt=num_images_per_prompt,
126
- ).images
127
-
128
- return output
129
-
130
  # Define the image generation function for the Individual tab
131
  @spaces.GPU(duration=80)
132
  def generate_individual_image(
 
1
  import torch
2
+ from diffusers import StableDiffusion3Pipeline, StableDiffusionPipeline, DiffusionPipeline, StableDiffusionXLPipeline, DPMSolverSinglestepScheduler
3
  import gradio as gr
4
  import os
5
  import random
 
29
  )
30
  sd2_1_pipe.to(device)
31
 
32
+ sdxl_pipe = DiffusionPipeline.from_pretrained(
33
  "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
34
  )
35
  sdxl_pipe.to(device)
36
 
37
+ sdxl_flash_pipe = StableDiffusionXLPipeline.from_pretrained(
38
+ "sd-community/sdxl-flash", torch_dtype=torch.float16
39
+ )
40
  sdxl_flash_pipe.to(device)
 
41
  # Ensure sampler uses "trailing" timesteps for sdxl flash.
42
  sdxl_flash_pipe.scheduler = DPMSolverSinglestepScheduler.from_config(sdxl_flash_pipe.scheduler.config, timestep_spacing="trailing")
43
 
44
+ # Helper function to generate images for a single model
45
+ @spaces.GPU(duration=80)
46
+ def generate_single_image(
47
+ prompt,
48
+ negative_prompt,
49
+ num_inference_steps,
50
+ height,
51
+ width,
52
+ guidance_scale,
53
+ seed,
54
+ num_images_per_prompt,
55
+ model_choice,
56
+ generator,
57
+ ):
58
+ # Select the correct pipeline based on the model choice
59
+ if model_choice == "sd3 medium":
60
+ pipe = sd3_medium_pipe
61
+ elif model_choice == "sd2.1":
62
+ pipe = sd2_1_pipe
63
+ elif model_choice == "sdxl":
64
+ pipe = sdxl_pipe
65
+ elif model_choice == "sdxl flash":
66
+ pipe = sdxl_flash_pipe
67
+ else:
68
+ raise ValueError(f"Invalid model choice: {model_choice}")
69
+
70
+ output = pipe(
71
+ prompt=prompt,
72
+ negative_prompt=negative_prompt,
73
+ num_inference_steps=num_inference_steps,
74
+ height=height,
75
+ width=width,
76
+ guidance_scale=guidance_scale,
77
+ generator=generator,
78
+ num_images_per_prompt=num_images_per_prompt,
79
+ ).images
80
+
81
+ return output
82
+
83
  # Define the image generation function for the Arena tab
84
  @spaces.GPU(duration=80)
85
  def generate_arena_images(
 
128
 
129
  return images_1, images_2
130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  # Define the image generation function for the Individual tab
132
  @spaces.GPU(duration=80)
133
  def generate_individual_image(