Update app.py
Browse files
app.py
CHANGED
|
@@ -274,12 +274,9 @@ def generate_30(
|
|
| 274 |
num_inference_steps: int = 125,
|
| 275 |
randomize_seed: bool = False,
|
| 276 |
use_resolution_binning: bool = True,
|
| 277 |
-
num_images: int = 1,
|
| 278 |
denoise: float = 0.3,
|
| 279 |
progress=gr.Progress(track_tqdm=True) # Add progress as a keyword argument
|
| 280 |
-
|
| 281 |
):
|
| 282 |
-
print(f'debug: num_images: {num_images} denoise: {denoise}')
|
| 283 |
torch.backends.cudnn.benchmark = False
|
| 284 |
torch.cuda.empty_cache()
|
| 285 |
gc.collect()
|
|
@@ -289,7 +286,7 @@ def generate_30(
|
|
| 289 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
| 290 |
#prompt, negative_prompt = apply_style(style_selection, prompt, negative_prompt)
|
| 291 |
options = {
|
| 292 |
-
"prompt": [prompt]
|
| 293 |
"negative_prompt": [negative_prompt],
|
| 294 |
"negative_prompt_2": [neg_prompt_2],
|
| 295 |
"strength": denoise,
|
|
@@ -307,25 +304,21 @@ def generate_30(
|
|
| 307 |
pipe.scheduler.set_timesteps(num_inference_steps,device)
|
| 308 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 309 |
uploadNote(prompt,num_inference_steps,guidance_scale,timestamp,denoise)
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
batch_options["negative_prompt"] = options["negative_prompt"][i:i+BATCH_SIZE]
|
| 315 |
-
images.extend(pipe(**batch_options).images)
|
| 316 |
-
sd_image_path = f"rv50_A_{timestamp}.png"
|
| 317 |
-
images[0].save(sd_image_path,optimize=False,compress_level=0)
|
| 318 |
upload_to_ftp(sd_image_path)
|
| 319 |
-
image_paths =
|
| 320 |
torch.cuda.empty_cache()
|
| 321 |
gc.collect()
|
| 322 |
torch.set_float32_matmul_precision("medium")
|
| 323 |
with torch.no_grad():
|
| 324 |
-
upscale = upscaler(
|
| 325 |
downscale1 = upscale.resize((upscale.width // 4, upscale.height // 4), Image.LANCZOS)
|
| 326 |
downscale_path = f"rv50_upscale_{timestamp}.png"
|
| 327 |
downscale1.save(downscale_path,optimize=False,compress_level=0)
|
| 328 |
-
upload_to_ftp(downscale_path)
|
| 329 |
image_paths = [save_image(downscale1)]
|
| 330 |
return image_paths, seed
|
| 331 |
|
|
@@ -343,7 +336,6 @@ def generate_60(
|
|
| 343 |
num_inference_steps: int = 250,
|
| 344 |
randomize_seed: bool = False,
|
| 345 |
use_resolution_binning: bool = True,
|
| 346 |
-
num_images: int = 1,
|
| 347 |
denoise: float = 0.3,
|
| 348 |
progress=gr.Progress(track_tqdm=True) # Add progress as a keyword argument
|
| 349 |
):
|
|
@@ -356,7 +348,7 @@ def generate_60(
|
|
| 356 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
| 357 |
#prompt, negative_prompt = apply_style(style_selection, prompt, negative_prompt)
|
| 358 |
options = {
|
| 359 |
-
"prompt": [prompt]
|
| 360 |
"negative_prompt": [negative_prompt],
|
| 361 |
"negative_prompt_2": [neg_prompt_2],
|
| 362 |
"strength": denoise,
|
|
@@ -374,25 +366,21 @@ def generate_60(
|
|
| 374 |
pipe.scheduler.set_timesteps(num_inference_steps,device)
|
| 375 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 376 |
uploadNote(prompt,num_inference_steps,guidance_scale,timestamp,denoise)
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
batch_options["negative_prompt"] = options["negative_prompt"][i:i+BATCH_SIZE]
|
| 382 |
-
images.extend(pipe(**batch_options).images)
|
| 383 |
-
sd_image_path = f"rv50_A_{timestamp}.png"
|
| 384 |
-
images[0].save(sd_image_path,optimize=False,compress_level=0)
|
| 385 |
upload_to_ftp(sd_image_path)
|
| 386 |
-
image_paths =
|
| 387 |
torch.cuda.empty_cache()
|
| 388 |
gc.collect()
|
| 389 |
torch.set_float32_matmul_precision("medium")
|
| 390 |
with torch.no_grad():
|
| 391 |
-
upscale = upscaler(
|
| 392 |
downscale1 = upscale.resize((upscale.width // 4, upscale.height // 4), Image.LANCZOS)
|
| 393 |
downscale_path = f"rv50_upscale_{timestamp}.png"
|
| 394 |
downscale1.save(downscale_path,optimize=False,compress_level=0)
|
| 395 |
-
upload_to_ftp(downscale_path)
|
| 396 |
image_paths = [save_image(downscale1)]
|
| 397 |
return image_paths, seed
|
| 398 |
|
|
@@ -410,7 +398,6 @@ def generate_90(
|
|
| 410 |
num_inference_steps: int = 250,
|
| 411 |
randomize_seed: bool = False,
|
| 412 |
use_resolution_binning: bool = True,
|
| 413 |
-
num_images: int = 1,
|
| 414 |
denoise: float = 0.3,
|
| 415 |
progress=gr.Progress(track_tqdm=True) # Add progress as a keyword argument
|
| 416 |
):
|
|
@@ -423,7 +410,7 @@ def generate_90(
|
|
| 423 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
| 424 |
#prompt, negative_prompt = apply_style(style_selection, prompt, negative_prompt)
|
| 425 |
options = {
|
| 426 |
-
"prompt": [prompt]
|
| 427 |
"negative_prompt": [negative_prompt],
|
| 428 |
"negative_prompt_2": [neg_prompt_2],
|
| 429 |
"strength": denoise,
|
|
@@ -441,21 +428,17 @@ def generate_90(
|
|
| 441 |
pipe.scheduler.set_timesteps(num_inference_steps,device)
|
| 442 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 443 |
uploadNote(prompt,num_inference_steps,guidance_scale,timestamp,denoise)
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
batch_options["prompt"] = options["prompt"][i:i+BATCH_SIZE]
|
| 447 |
-
if "negative_prompt" in batch_options:
|
| 448 |
-
batch_options["negative_prompt"] = options["negative_prompt"][i:i+BATCH_SIZE]
|
| 449 |
-
images.extend(pipe(**batch_options).images)
|
| 450 |
sd_image_path = f"rv50_A_{seed}.png"
|
| 451 |
-
|
| 452 |
upload_to_ftp(sd_image_path)
|
| 453 |
-
image_paths =
|
| 454 |
torch.cuda.empty_cache()
|
| 455 |
gc.collect()
|
| 456 |
torch.set_float32_matmul_precision("medium")
|
| 457 |
with torch.no_grad():
|
| 458 |
-
upscale = upscaler(
|
| 459 |
downscale1 = upscale.resize((upscale.width // 4, upscale.height // 4), Image.LANCZOS)
|
| 460 |
downscale_path = f"rv50_upscale_{timestamp}.png"
|
| 461 |
downscale1.save(downscale_path,optimize=False,compress_level=0)
|
|
@@ -521,13 +504,6 @@ with gr.Blocks(theme=gr.themes.Origin(),css=css) as demo:
|
|
| 521 |
value=DEFAULT_STYLE_NAME,
|
| 522 |
label="Quality Style",
|
| 523 |
)
|
| 524 |
-
num_images = gr.Slider(
|
| 525 |
-
label="Number of Images",
|
| 526 |
-
minimum=1,
|
| 527 |
-
maximum=5,
|
| 528 |
-
step=1,
|
| 529 |
-
value=1,
|
| 530 |
-
)
|
| 531 |
with gr.Row():
|
| 532 |
with gr.Column(scale=1):
|
| 533 |
use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True)
|
|
@@ -616,7 +592,6 @@ with gr.Blocks(theme=gr.themes.Origin(),css=css) as demo:
|
|
| 616 |
guidance_scale,
|
| 617 |
num_inference_steps,
|
| 618 |
randomize_seed,
|
| 619 |
-
num_images,
|
| 620 |
denoise
|
| 621 |
],
|
| 622 |
outputs=[result, seed],
|
|
@@ -640,7 +615,6 @@ with gr.Blocks(theme=gr.themes.Origin(),css=css) as demo:
|
|
| 640 |
guidance_scale,
|
| 641 |
num_inference_steps,
|
| 642 |
randomize_seed,
|
| 643 |
-
num_images,
|
| 644 |
denoise
|
| 645 |
],
|
| 646 |
outputs=[result, seed],
|
|
@@ -664,7 +638,6 @@ with gr.Blocks(theme=gr.themes.Origin(),css=css) as demo:
|
|
| 664 |
guidance_scale,
|
| 665 |
num_inference_steps,
|
| 666 |
randomize_seed,
|
| 667 |
-
num_images,
|
| 668 |
denoise
|
| 669 |
],
|
| 670 |
outputs=[result, seed],
|
|
|
|
| 274 |
num_inference_steps: int = 125,
|
| 275 |
randomize_seed: bool = False,
|
| 276 |
use_resolution_binning: bool = True,
|
|
|
|
| 277 |
denoise: float = 0.3,
|
| 278 |
progress=gr.Progress(track_tqdm=True) # Add progress as a keyword argument
|
|
|
|
| 279 |
):
|
|
|
|
| 280 |
torch.backends.cudnn.benchmark = False
|
| 281 |
torch.cuda.empty_cache()
|
| 282 |
gc.collect()
|
|
|
|
| 286 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
| 287 |
#prompt, negative_prompt = apply_style(style_selection, prompt, negative_prompt)
|
| 288 |
options = {
|
| 289 |
+
"prompt": [prompt],
|
| 290 |
"negative_prompt": [negative_prompt],
|
| 291 |
"negative_prompt_2": [neg_prompt_2],
|
| 292 |
"strength": denoise,
|
|
|
|
| 304 |
pipe.scheduler.set_timesteps(num_inference_steps,device)
|
| 305 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 306 |
uploadNote(prompt,num_inference_steps,guidance_scale,timestamp,denoise)
|
| 307 |
+
batch_options = options.copy()
|
| 308 |
+
rv_image = images.extend(pipe(**batch_options).images[0])
|
| 309 |
+
sd_image_path = f"rv50_A_{seed}.png"
|
| 310 |
+
rv_image.save(sd_image_path,optimize=False,compress_level=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
upload_to_ftp(sd_image_path)
|
| 312 |
+
image_paths = save_image(rv_image)
|
| 313 |
torch.cuda.empty_cache()
|
| 314 |
gc.collect()
|
| 315 |
torch.set_float32_matmul_precision("medium")
|
| 316 |
with torch.no_grad():
|
| 317 |
+
upscale = upscaler(rv_image, tiling=True, tile_width=256, tile_height=256)
|
| 318 |
downscale1 = upscale.resize((upscale.width // 4, upscale.height // 4), Image.LANCZOS)
|
| 319 |
downscale_path = f"rv50_upscale_{timestamp}.png"
|
| 320 |
downscale1.save(downscale_path,optimize=False,compress_level=0)
|
| 321 |
+
upload_to_ftp(downscale_path)
|
| 322 |
image_paths = [save_image(downscale1)]
|
| 323 |
return image_paths, seed
|
| 324 |
|
|
|
|
| 336 |
num_inference_steps: int = 250,
|
| 337 |
randomize_seed: bool = False,
|
| 338 |
use_resolution_binning: bool = True,
|
|
|
|
| 339 |
denoise: float = 0.3,
|
| 340 |
progress=gr.Progress(track_tqdm=True) # Add progress as a keyword argument
|
| 341 |
):
|
|
|
|
| 348 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
| 349 |
#prompt, negative_prompt = apply_style(style_selection, prompt, negative_prompt)
|
| 350 |
options = {
|
| 351 |
+
"prompt": [prompt],
|
| 352 |
"negative_prompt": [negative_prompt],
|
| 353 |
"negative_prompt_2": [neg_prompt_2],
|
| 354 |
"strength": denoise,
|
|
|
|
| 366 |
pipe.scheduler.set_timesteps(num_inference_steps,device)
|
| 367 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 368 |
uploadNote(prompt,num_inference_steps,guidance_scale,timestamp,denoise)
|
| 369 |
+
batch_options = options.copy()
|
| 370 |
+
rv_image = images.extend(pipe(**batch_options).images[0])
|
| 371 |
+
sd_image_path = f"rv50_A_{seed}.png"
|
| 372 |
+
rv_image.save(sd_image_path,optimize=False,compress_level=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
upload_to_ftp(sd_image_path)
|
| 374 |
+
image_paths = save_image(rv_image)
|
| 375 |
torch.cuda.empty_cache()
|
| 376 |
gc.collect()
|
| 377 |
torch.set_float32_matmul_precision("medium")
|
| 378 |
with torch.no_grad():
|
| 379 |
+
upscale = upscaler(rv_image, tiling=True, tile_width=256, tile_height=256)
|
| 380 |
downscale1 = upscale.resize((upscale.width // 4, upscale.height // 4), Image.LANCZOS)
|
| 381 |
downscale_path = f"rv50_upscale_{timestamp}.png"
|
| 382 |
downscale1.save(downscale_path,optimize=False,compress_level=0)
|
| 383 |
+
upload_to_ftp(downscale_path)
|
| 384 |
image_paths = [save_image(downscale1)]
|
| 385 |
return image_paths, seed
|
| 386 |
|
|
|
|
| 398 |
num_inference_steps: int = 250,
|
| 399 |
randomize_seed: bool = False,
|
| 400 |
use_resolution_binning: bool = True,
|
|
|
|
| 401 |
denoise: float = 0.3,
|
| 402 |
progress=gr.Progress(track_tqdm=True) # Add progress as a keyword argument
|
| 403 |
):
|
|
|
|
| 410 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
| 411 |
#prompt, negative_prompt = apply_style(style_selection, prompt, negative_prompt)
|
| 412 |
options = {
|
| 413 |
+
"prompt": [prompt],
|
| 414 |
"negative_prompt": [negative_prompt],
|
| 415 |
"negative_prompt_2": [neg_prompt_2],
|
| 416 |
"strength": denoise,
|
|
|
|
| 428 |
pipe.scheduler.set_timesteps(num_inference_steps,device)
|
| 429 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 430 |
uploadNote(prompt,num_inference_steps,guidance_scale,timestamp,denoise)
|
| 431 |
+
batch_options = options.copy()
|
| 432 |
+
rv_image = images.extend(pipe(**batch_options).images[0])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 433 |
sd_image_path = f"rv50_A_{seed}.png"
|
| 434 |
+
rv_image.save(sd_image_path,optimize=False,compress_level=0)
|
| 435 |
upload_to_ftp(sd_image_path)
|
| 436 |
+
image_paths = save_image(rv_image)
|
| 437 |
torch.cuda.empty_cache()
|
| 438 |
gc.collect()
|
| 439 |
torch.set_float32_matmul_precision("medium")
|
| 440 |
with torch.no_grad():
|
| 441 |
+
upscale = upscaler(rv_image, tiling=True, tile_width=256, tile_height=256)
|
| 442 |
downscale1 = upscale.resize((upscale.width // 4, upscale.height // 4), Image.LANCZOS)
|
| 443 |
downscale_path = f"rv50_upscale_{timestamp}.png"
|
| 444 |
downscale1.save(downscale_path,optimize=False,compress_level=0)
|
|
|
|
| 504 |
value=DEFAULT_STYLE_NAME,
|
| 505 |
label="Quality Style",
|
| 506 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 507 |
with gr.Row():
|
| 508 |
with gr.Column(scale=1):
|
| 509 |
use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True)
|
|
|
|
| 592 |
guidance_scale,
|
| 593 |
num_inference_steps,
|
| 594 |
randomize_seed,
|
|
|
|
| 595 |
denoise
|
| 596 |
],
|
| 597 |
outputs=[result, seed],
|
|
|
|
| 615 |
guidance_scale,
|
| 616 |
num_inference_steps,
|
| 617 |
randomize_seed,
|
|
|
|
| 618 |
denoise
|
| 619 |
],
|
| 620 |
outputs=[result, seed],
|
|
|
|
| 638 |
guidance_scale,
|
| 639 |
num_inference_steps,
|
| 640 |
randomize_seed,
|
|
|
|
| 641 |
denoise
|
| 642 |
],
|
| 643 |
outputs=[result, seed],
|