Spaces:
Running on Zero
Running on Zero
revertinng the use same settings change till i find a fix
Browse files
app.py
CHANGED
|
@@ -84,70 +84,49 @@ def generate_single_image(
|
|
| 84 |
@spaces.GPU(duration=80)
|
| 85 |
def generate_arena_images(
|
| 86 |
prompt,
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
guidance_scale_B,
|
| 97 |
-
seed_A,
|
| 98 |
-
seed_B,
|
| 99 |
-
num_images_per_prompt_A,
|
| 100 |
-
num_images_per_prompt_B,
|
| 101 |
-
model_choice_A,
|
| 102 |
-
model_choice_B,
|
| 103 |
-
use_same_settings,
|
| 104 |
progress=gr.Progress(track_tqdm=True),
|
| 105 |
):
|
| 106 |
-
if
|
| 107 |
-
|
| 108 |
-
if seed_B == 0:
|
| 109 |
-
seed_B = random.randint(1, 2**32 - 1)
|
| 110 |
-
|
| 111 |
-
generator_A = torch.Generator().manual_seed(seed_A)
|
| 112 |
-
generator_B = torch.Generator().manual_seed(seed_B)
|
| 113 |
|
| 114 |
-
|
| 115 |
-
if use_same_settings:
|
| 116 |
-
num_inference_steps_B = num_inference_steps_A
|
| 117 |
-
height_B = height_A
|
| 118 |
-
width_B = width_A
|
| 119 |
-
guidance_scale_B = guidance_scale_A
|
| 120 |
-
negative_prompt_B = negative_prompt_A
|
| 121 |
-
seed_B = seed_A
|
| 122 |
-
num_images_per_prompt_B = num_images_per_prompt_A
|
| 123 |
|
| 124 |
# Generate images for both models
|
| 125 |
-
|
| 126 |
prompt,
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
)
|
| 137 |
-
|
| 138 |
prompt,
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
)
|
| 149 |
|
| 150 |
-
return
|
| 151 |
|
| 152 |
# Define the image generation function for the Individual tab
|
| 153 |
@spaces.GPU(duration=80)
|
|
@@ -220,31 +199,28 @@ with gr.Blocks(css=css) as demo:
|
|
| 220 |
info="Describe the image you want",
|
| 221 |
placeholder="A cat...",
|
| 222 |
)
|
| 223 |
-
|
| 224 |
-
label="Stable Diffusion Model
|
| 225 |
choices=["sd3 medium", "sd2.1", "sdxl", "sdxl flash"],
|
| 226 |
value="sd3 medium",
|
| 227 |
)
|
| 228 |
-
|
| 229 |
-
label="Stable Diffusion Model
|
| 230 |
choices=["sd3 medium", "sd2.1", "sdxl", "sdxl flash"],
|
| 231 |
value="sdxl",
|
| 232 |
)
|
| 233 |
run_button = gr.Button("Run")
|
| 234 |
-
|
| 235 |
-
|
| 236 |
with gr.Accordion("Advanced options", open=False):
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
# UI elements for shared settings
|
| 240 |
-
with gr.Row(visible=True):
|
| 241 |
negative_prompt = gr.Textbox(
|
| 242 |
label="Negative Prompt",
|
| 243 |
info="Describe what you don't want in the image",
|
| 244 |
value="deformed, distorted, disfigured, poorly drawn, bad anatomy, incorrect anatomy, extra limb, missing limb, floating limbs, mutated hands and fingers, disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation",
|
| 245 |
placeholder="Ugly, bad anatomy...",
|
| 246 |
)
|
| 247 |
-
with gr.Row(
|
| 248 |
num_inference_steps = gr.Slider(
|
| 249 |
label="Number of Inference Steps",
|
| 250 |
info="The number of denoising steps of the image. More denoising steps usually lead to a higher quality image at the cost of slower inference",
|
|
@@ -261,7 +237,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 261 |
value=7.5,
|
| 262 |
step=0.1,
|
| 263 |
)
|
| 264 |
-
with gr.Row(
|
| 265 |
width = gr.Slider(
|
| 266 |
label="Width",
|
| 267 |
info="Width of the Image",
|
|
@@ -278,7 +254,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 278 |
step=32,
|
| 279 |
value=1024,
|
| 280 |
)
|
| 281 |
-
with gr.Row(
|
| 282 |
seed = gr.Slider(
|
| 283 |
value=42,
|
| 284 |
minimum=0,
|
|
@@ -296,123 +272,10 @@ with gr.Blocks(css=css) as demo:
|
|
| 296 |
value=2,
|
| 297 |
)
|
| 298 |
|
| 299 |
-
# UI elements for separate settings (hidden by default)
|
| 300 |
-
with gr.Row(visible=False):
|
| 301 |
-
with gr.Column(scale=1):
|
| 302 |
-
negative_prompt_A = gr.Textbox(
|
| 303 |
-
label="Negative Prompt (Model A)",
|
| 304 |
-
info="Describe what you don't want in the image",
|
| 305 |
-
value="deformed, distorted, disfigured, poorly drawn, bad anatomy, incorrect anatomy, extra limb, missing limb, floating limbs, mutated hands and fingers, disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation",
|
| 306 |
-
placeholder="Ugly, bad anatomy...",
|
| 307 |
-
)
|
| 308 |
-
num_inference_steps_A = gr.Slider(
|
| 309 |
-
label="Number of Inference Steps (Model A)",
|
| 310 |
-
info="The number of denoising steps of the image. More denoising steps usually lead to a higher quality image at the cost of slower inference",
|
| 311 |
-
minimum=1,
|
| 312 |
-
maximum=50,
|
| 313 |
-
value=25,
|
| 314 |
-
step=1,
|
| 315 |
-
)
|
| 316 |
-
width_A = gr.Slider(
|
| 317 |
-
label="Width (Model A)",
|
| 318 |
-
info="Width of the Image",
|
| 319 |
-
minimum=256,
|
| 320 |
-
maximum=1344,
|
| 321 |
-
step=32,
|
| 322 |
-
value=1024,
|
| 323 |
-
)
|
| 324 |
-
height_A = gr.Slider(
|
| 325 |
-
label="Height (Model A)",
|
| 326 |
-
info="Height of the Image",
|
| 327 |
-
minimum=256,
|
| 328 |
-
maximum=1344,
|
| 329 |
-
step=32,
|
| 330 |
-
value=1024,
|
| 331 |
-
)
|
| 332 |
-
guidance_scale_A = gr.Slider(
|
| 333 |
-
label="Guidance Scale (Model A)",
|
| 334 |
-
info="Controls how much the image generation process follows the text prompt. Higher values make the image stick more closely to the input text.",
|
| 335 |
-
minimum=0.0,
|
| 336 |
-
maximum=10.0,
|
| 337 |
-
value=7.5,
|
| 338 |
-
step=0.1,
|
| 339 |
-
)
|
| 340 |
-
seed_A = gr.Slider(
|
| 341 |
-
value=42,
|
| 342 |
-
minimum=0,
|
| 343 |
-
maximum=MAX_SEED,
|
| 344 |
-
step=1,
|
| 345 |
-
label="Seed (Model A)",
|
| 346 |
-
info="A starting point to initiate the generation process, put 0 for a random one",
|
| 347 |
-
)
|
| 348 |
-
num_images_per_prompt_A = gr.Slider(
|
| 349 |
-
label="Images Per Prompt (Model A)",
|
| 350 |
-
info="Number of Images to generate with the settings",
|
| 351 |
-
minimum=1,
|
| 352 |
-
maximum=4,
|
| 353 |
-
step=1,
|
| 354 |
-
value=2,
|
| 355 |
-
)
|
| 356 |
-
with gr.Column(scale=1):
|
| 357 |
-
negative_prompt_B = gr.Textbox(
|
| 358 |
-
label="Negative Prompt (Model B)",
|
| 359 |
-
info="Describe what you don't want in the image",
|
| 360 |
-
value="deformed, distorted, disfigured, poorly drawn, bad anatomy, incorrect anatomy, extra limb, missing limb, floating limbs, mutated hands and fingers, disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation",
|
| 361 |
-
placeholder="Ugly, bad anatomy...",
|
| 362 |
-
)
|
| 363 |
-
num_inference_steps_B = gr.Slider(
|
| 364 |
-
label="Number of Inference Steps (Model B)",
|
| 365 |
-
info="The number of denoising steps of the image. More denoising steps usually lead to a higher quality image at the cost of slower inference",
|
| 366 |
-
minimum=1,
|
| 367 |
-
maximum=50,
|
| 368 |
-
value=25,
|
| 369 |
-
step=1,
|
| 370 |
-
)
|
| 371 |
-
width_B = gr.Slider(
|
| 372 |
-
label="Width (Model B)",
|
| 373 |
-
info="Width of the Image",
|
| 374 |
-
minimum=256,
|
| 375 |
-
maximum=1344,
|
| 376 |
-
step=32,
|
| 377 |
-
value=1024,
|
| 378 |
-
)
|
| 379 |
-
height_B = gr.Slider(
|
| 380 |
-
label="Height (Model B)",
|
| 381 |
-
info="Height of the Image",
|
| 382 |
-
minimum=256,
|
| 383 |
-
maximum=1344,
|
| 384 |
-
step=32,
|
| 385 |
-
value=1024,
|
| 386 |
-
)
|
| 387 |
-
guidance_scale_B = gr.Slider(
|
| 388 |
-
label="Guidance Scale (Model B)",
|
| 389 |
-
info="Controls how much the image generation process follows the text prompt. Higher values make the image stick more closely to the input text.",
|
| 390 |
-
minimum=0.0,
|
| 391 |
-
maximum=10.0,
|
| 392 |
-
value=7.5,
|
| 393 |
-
step=0.1,
|
| 394 |
-
)
|
| 395 |
-
seed_B = gr.Slider(
|
| 396 |
-
value=42,
|
| 397 |
-
minimum=0,
|
| 398 |
-
maximum=MAX_SEED,
|
| 399 |
-
step=1,
|
| 400 |
-
label="Seed (Model B)",
|
| 401 |
-
info="A starting point to initiate the generation process, put 0 for a random one",
|
| 402 |
-
)
|
| 403 |
-
num_images_per_prompt_B = gr.Slider(
|
| 404 |
-
label="Images Per Prompt (Model B)",
|
| 405 |
-
info="Number of Images to generate with the settings",
|
| 406 |
-
minimum=1,
|
| 407 |
-
maximum=4,
|
| 408 |
-
step=1,
|
| 409 |
-
value=2,
|
| 410 |
-
)
|
| 411 |
-
|
| 412 |
gr.Examples(
|
| 413 |
examples=examples,
|
| 414 |
inputs=[prompt],
|
| 415 |
-
outputs=[
|
| 416 |
fn=generate_arena_images,
|
| 417 |
)
|
| 418 |
|
|
@@ -424,25 +287,17 @@ with gr.Blocks(css=css) as demo:
|
|
| 424 |
fn=generate_arena_images,
|
| 425 |
inputs=[
|
| 426 |
prompt,
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
guidance_scale_B,
|
| 437 |
-
seed_A,
|
| 438 |
-
seed_B,
|
| 439 |
-
num_images_per_prompt_A,
|
| 440 |
-
num_images_per_prompt_B,
|
| 441 |
-
model_choice_A,
|
| 442 |
-
model_choice_B,
|
| 443 |
-
use_same_settings,
|
| 444 |
],
|
| 445 |
-
outputs=[
|
| 446 |
)
|
| 447 |
|
| 448 |
with gr.TabItem("Individual"):
|
|
|
|
| 84 |
@spaces.GPU(duration=80)
|
| 85 |
def generate_arena_images(
|
| 86 |
prompt,
|
| 87 |
+
negative_prompt,
|
| 88 |
+
num_inference_steps,
|
| 89 |
+
height,
|
| 90 |
+
width,
|
| 91 |
+
guidance_scale,
|
| 92 |
+
seed,
|
| 93 |
+
num_images_per_prompt,
|
| 94 |
+
model_choice_1,
|
| 95 |
+
model_choice_2,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
progress=gr.Progress(track_tqdm=True),
|
| 97 |
):
|
| 98 |
+
if seed == 0:
|
| 99 |
+
seed = random.randint(1, 2**32 - 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
+
generator = torch.Generator().manual_seed(seed)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
# Generate images for both models
|
| 104 |
+
images_1 = generate_single_image(
|
| 105 |
prompt,
|
| 106 |
+
negative_prompt,
|
| 107 |
+
num_inference_steps,
|
| 108 |
+
height,
|
| 109 |
+
width,
|
| 110 |
+
guidance_scale,
|
| 111 |
+
seed,
|
| 112 |
+
num_images_per_prompt,
|
| 113 |
+
model_choice_1,
|
| 114 |
+
generator,
|
| 115 |
)
|
| 116 |
+
images_2 = generate_single_image(
|
| 117 |
prompt,
|
| 118 |
+
negative_prompt,
|
| 119 |
+
num_inference_steps,
|
| 120 |
+
height,
|
| 121 |
+
width,
|
| 122 |
+
guidance_scale,
|
| 123 |
+
seed,
|
| 124 |
+
num_images_per_prompt,
|
| 125 |
+
model_choice_2,
|
| 126 |
+
generator,
|
| 127 |
)
|
| 128 |
|
| 129 |
+
return images_1, images_2
|
| 130 |
|
| 131 |
# Define the image generation function for the Individual tab
|
| 132 |
@spaces.GPU(duration=80)
|
|
|
|
| 199 |
info="Describe the image you want",
|
| 200 |
placeholder="A cat...",
|
| 201 |
)
|
| 202 |
+
model_choice_1 = gr.Dropdown(
|
| 203 |
+
label="Stable Diffusion Model 1",
|
| 204 |
choices=["sd3 medium", "sd2.1", "sdxl", "sdxl flash"],
|
| 205 |
value="sd3 medium",
|
| 206 |
)
|
| 207 |
+
model_choice_2 = gr.Dropdown(
|
| 208 |
+
label="Stable Diffusion Model 2",
|
| 209 |
choices=["sd3 medium", "sd2.1", "sdxl", "sdxl flash"],
|
| 210 |
value="sdxl",
|
| 211 |
)
|
| 212 |
run_button = gr.Button("Run")
|
| 213 |
+
result_1 = gr.Gallery(label="Generated Images (Model 1)", elem_id="gallery_1")
|
| 214 |
+
result_2 = gr.Gallery(label="Generated Images (Model 2)", elem_id="gallery_2")
|
| 215 |
with gr.Accordion("Advanced options", open=False):
|
| 216 |
+
with gr.Row():
|
|
|
|
|
|
|
|
|
|
| 217 |
negative_prompt = gr.Textbox(
|
| 218 |
label="Negative Prompt",
|
| 219 |
info="Describe what you don't want in the image",
|
| 220 |
value="deformed, distorted, disfigured, poorly drawn, bad anatomy, incorrect anatomy, extra limb, missing limb, floating limbs, mutated hands and fingers, disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation",
|
| 221 |
placeholder="Ugly, bad anatomy...",
|
| 222 |
)
|
| 223 |
+
with gr.Row():
|
| 224 |
num_inference_steps = gr.Slider(
|
| 225 |
label="Number of Inference Steps",
|
| 226 |
info="The number of denoising steps of the image. More denoising steps usually lead to a higher quality image at the cost of slower inference",
|
|
|
|
| 237 |
value=7.5,
|
| 238 |
step=0.1,
|
| 239 |
)
|
| 240 |
+
with gr.Row():
|
| 241 |
width = gr.Slider(
|
| 242 |
label="Width",
|
| 243 |
info="Width of the Image",
|
|
|
|
| 254 |
step=32,
|
| 255 |
value=1024,
|
| 256 |
)
|
| 257 |
+
with gr.Row():
|
| 258 |
seed = gr.Slider(
|
| 259 |
value=42,
|
| 260 |
minimum=0,
|
|
|
|
| 272 |
value=2,
|
| 273 |
)
|
| 274 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
gr.Examples(
|
| 276 |
examples=examples,
|
| 277 |
inputs=[prompt],
|
| 278 |
+
outputs=[result_1, result_2],
|
| 279 |
fn=generate_arena_images,
|
| 280 |
)
|
| 281 |
|
|
|
|
| 287 |
fn=generate_arena_images,
|
| 288 |
inputs=[
|
| 289 |
prompt,
|
| 290 |
+
negative_prompt,
|
| 291 |
+
num_inference_steps,
|
| 292 |
+
width,
|
| 293 |
+
height,
|
| 294 |
+
guidance_scale,
|
| 295 |
+
seed,
|
| 296 |
+
num_images_per_prompt,
|
| 297 |
+
model_choice_1,
|
| 298 |
+
model_choice_2,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
],
|
| 300 |
+
outputs=[result_1, result_2],
|
| 301 |
)
|
| 302 |
|
| 303 |
with gr.TabItem("Individual"):
|