Update app.py
Browse files
app.py
CHANGED
|
@@ -28,6 +28,7 @@ from gradio import themes
|
|
| 28 |
from hidiffusion import apply_hidiffusion, remove_hidiffusion
|
| 29 |
|
| 30 |
import gc
|
|
|
|
| 31 |
|
| 32 |
torch.backends.cuda.matmul.allow_tf32 = False
|
| 33 |
torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = False
|
|
@@ -95,6 +96,7 @@ STYLE_NAMES = list(styles.keys())
|
|
| 95 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 96 |
|
| 97 |
#sampling_schedule = AysSchedules["StableDiffusionXLTimesteps"]
|
|
|
|
| 98 |
|
| 99 |
def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
|
| 100 |
if style_name in styles:
|
|
@@ -308,10 +310,17 @@ def generate_30(
|
|
| 308 |
images.extend(pipe(**batch_options).images)
|
| 309 |
sd_image_path = f"rv50_A_{timestamp}.png"
|
| 310 |
images[0].save(sd_image_path,optimize=False,compress_level=0)
|
| 311 |
-
upload_to_ftp(sd_image_path)
|
| 312 |
image_paths = [save_image(img) for img in images]
|
| 313 |
torch.cuda.empty_cache()
|
| 314 |
gc.collect()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
return image_paths, seed
|
| 316 |
|
| 317 |
@spaces.GPU(duration=60)
|
|
@@ -363,12 +372,19 @@ def generate_60(
|
|
| 363 |
if "negative_prompt" in batch_options:
|
| 364 |
batch_options["negative_prompt"] = options["negative_prompt"][i:i+BATCH_SIZE]
|
| 365 |
images.extend(pipe(**batch_options).images)
|
| 366 |
-
sd_image_path = f"rv50_A_{
|
| 367 |
images[0].save(sd_image_path,optimize=False,compress_level=0)
|
| 368 |
-
upload_to_ftp(sd_image_path)
|
| 369 |
image_paths = [save_image(img) for img in images]
|
| 370 |
torch.cuda.empty_cache()
|
| 371 |
gc.collect()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
return image_paths, seed
|
| 373 |
|
| 374 |
@spaces.GPU(duration=90)
|
|
@@ -422,10 +438,17 @@ def generate_90(
|
|
| 422 |
images.extend(pipe(**batch_options).images)
|
| 423 |
sd_image_path = f"rv50_A_{seed}.png"
|
| 424 |
images[0].save(sd_image_path,optimize=False,compress_level=0)
|
| 425 |
-
upload_to_ftp(sd_image_path)
|
| 426 |
image_paths = [save_image(img) for img in images]
|
| 427 |
torch.cuda.empty_cache()
|
| 428 |
gc.collect()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 429 |
return image_paths, seed
|
| 430 |
|
| 431 |
def load_predefined_images1():
|
|
|
|
| 28 |
from hidiffusion import apply_hidiffusion, remove_hidiffusion
|
| 29 |
|
| 30 |
import gc
|
| 31 |
+
from image_gen_aux import UpscaleWithModel
|
| 32 |
|
| 33 |
torch.backends.cuda.matmul.allow_tf32 = False
|
| 34 |
torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = False
|
|
|
|
| 96 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 97 |
|
| 98 |
#sampling_schedule = AysSchedules["StableDiffusionXLTimesteps"]
|
| 99 |
+
upscaler = UpscaleWithModel.from_pretrained("Kim2091/ClearRealityV1").to(torch.device("cuda:0"))
|
| 100 |
|
| 101 |
def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
|
| 102 |
if style_name in styles:
|
|
|
|
| 310 |
images.extend(pipe(**batch_options).images)
|
| 311 |
sd_image_path = f"rv50_A_{timestamp}.png"
|
| 312 |
images[0].save(sd_image_path,optimize=False,compress_level=0)
|
| 313 |
+
upload_to_ftp(sd_image_path)
|
| 314 |
image_paths = [save_image(img) for img in images]
|
| 315 |
torch.cuda.empty_cache()
|
| 316 |
gc.collect()
|
| 317 |
+
torch.set_float32_matmul_precision("medium")
|
| 318 |
+
with torch.no_grad():
|
| 319 |
+
upscale = upscaler(images[0], tiling=True, tile_width=256, tile_height=256)
|
| 320 |
+
downscale1 = upscale.resize((upscale.width // 4, upscale.height // 4), Image.LANCZOS)
|
| 321 |
+
downscale_path = f"rv50_upscale_{timestamp}.png"
|
| 322 |
+
downscale1.save(downscale_path,optimize=False,compress_level=0)
|
| 323 |
+
upload_to_ftp(downscale_path)
|
| 324 |
return image_paths, seed
|
| 325 |
|
| 326 |
@spaces.GPU(duration=60)
|
|
|
|
| 372 |
if "negative_prompt" in batch_options:
|
| 373 |
batch_options["negative_prompt"] = options["negative_prompt"][i:i+BATCH_SIZE]
|
| 374 |
images.extend(pipe(**batch_options).images)
|
| 375 |
+
sd_image_path = f"rv50_A_{timestamp}.png"
|
| 376 |
images[0].save(sd_image_path,optimize=False,compress_level=0)
|
| 377 |
+
upload_to_ftp(sd_image_path)
|
| 378 |
image_paths = [save_image(img) for img in images]
|
| 379 |
torch.cuda.empty_cache()
|
| 380 |
gc.collect()
|
| 381 |
+
torch.set_float32_matmul_precision("medium")
|
| 382 |
+
with torch.no_grad():
|
| 383 |
+
upscale = upscaler(images[0], tiling=True, tile_width=256, tile_height=256)
|
| 384 |
+
downscale1 = upscale.resize((upscale.width // 4, upscale.height // 4), Image.LANCZOS)
|
| 385 |
+
downscale_path = f"rv50_upscale_{timestamp}.png"
|
| 386 |
+
downscale1.save(downscale_path,optimize=False,compress_level=0)
|
| 387 |
+
upload_to_ftp(downscale_path)
|
| 388 |
return image_paths, seed
|
| 389 |
|
| 390 |
@spaces.GPU(duration=90)
|
|
|
|
| 438 |
images.extend(pipe(**batch_options).images)
|
| 439 |
sd_image_path = f"rv50_A_{seed}.png"
|
| 440 |
images[0].save(sd_image_path,optimize=False,compress_level=0)
|
| 441 |
+
upload_to_ftp(sd_image_path)
|
| 442 |
image_paths = [save_image(img) for img in images]
|
| 443 |
torch.cuda.empty_cache()
|
| 444 |
gc.collect()
|
| 445 |
+
torch.set_float32_matmul_precision("medium")
|
| 446 |
+
with torch.no_grad():
|
| 447 |
+
upscale = upscaler(images[0], tiling=True, tile_width=256, tile_height=256)
|
| 448 |
+
downscale1 = upscale.resize((upscale.width // 4, upscale.height // 4), Image.LANCZOS)
|
| 449 |
+
downscale_path = f"rv50_upscale_{timestamp}.png"
|
| 450 |
+
downscale1.save(downscale_path,optimize=False,compress_level=0)
|
| 451 |
+
upload_to_ftp(downscale_path)
|
| 452 |
return image_paths, seed
|
| 453 |
|
| 454 |
def load_predefined_images1():
|