Update app.py
Browse files
app.py
CHANGED
|
@@ -23,18 +23,9 @@ torch.backends.cudnn.benchmark = False
|
|
| 23 |
#torch.backends.cuda.preferred_linalg_library="cusolver"
|
| 24 |
torch.set_float32_matmul_precision("highest")
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
text_to_image = keras_hub.models.StableDiffusion3TextToImage.from_preset(
|
| 30 |
-
"stable_diffusion_3_medium", width=768, height=768, dtype="bfloat16"
|
| 31 |
-
)
|
| 32 |
-
else:
|
| 33 |
-
text_to_image = keras_hub.models.StableDiffusion3TextToImage.from_preset(
|
| 34 |
-
"stable_diffusion_3_medium", width=768, height=768, dtype="float32"
|
| 35 |
-
)
|
| 36 |
-
logging.warning("bfloat16 not supported, using float32")
|
| 37 |
-
|
| 38 |
|
| 39 |
code = r'''
|
| 40 |
import paramiko
|
|
@@ -57,6 +48,8 @@ def upload_to_ftp(filename):
|
|
| 57 |
print(f"FTP upload error: {e}")
|
| 58 |
'''
|
| 59 |
|
|
|
|
|
|
|
| 60 |
pyx = cyper.inline(code, fast_indexing=True, directives=dict(boundscheck=False, wraparound=False, language_level=3))
|
| 61 |
|
| 62 |
MAX_SEED = np.iinfo(np.int32).max
|
|
@@ -84,7 +77,7 @@ def infer_30(
|
|
| 84 |
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
| 85 |
pyx.upload_to_ftp(sd35_path)
|
| 86 |
with torch.no_grad():
|
| 87 |
-
upscale2 =
|
| 88 |
print('-- got upscaled image --')
|
| 89 |
downscale2 = upscale2.resize((upscale2.width // 4, upscale2.height // 4),Image.LANCZOS)
|
| 90 |
upscale_path = f"sd3keras_upscale_{timestamp}.png"
|
|
@@ -113,7 +106,7 @@ def infer_60(
|
|
| 113 |
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
| 114 |
pyx.upload_to_ftp(sd35_path)
|
| 115 |
with torch.no_grad():
|
| 116 |
-
upscale2 =
|
| 117 |
print('-- got upscaled image --')
|
| 118 |
downscale2 = upscale2.resize((upscale2.width // 4, upscale2.height // 4),Image.LANCZOS)
|
| 119 |
upscale_path = f"sd3keras_upscale_{timestamp}.png"
|
|
@@ -142,7 +135,7 @@ def infer_90(
|
|
| 142 |
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
| 143 |
pyx.upload_to_ftp(sd35_path)
|
| 144 |
with torch.no_grad():
|
| 145 |
-
upscale2 =
|
| 146 |
print('-- got upscaled image --')
|
| 147 |
downscale2 = upscale2.resize((upscale2.width // 4, upscale2.height // 4),Image.LANCZOS)
|
| 148 |
upscale_path = f"sd3keras_upscale_{timestamp}.png"
|
|
|
|
| 23 |
#torch.backends.cuda.preferred_linalg_library="cusolver"
|
| 24 |
torch.set_float32_matmul_precision("highest")
|
| 25 |
|
| 26 |
+
text_to_image = keras_hub.models.StableDiffusion3TextToImage.from_preset(
|
| 27 |
+
"stable_diffusion_3_medium", device='cuda', width=768, height=768, dtype="bfloat16"
|
| 28 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
code = r'''
|
| 31 |
import paramiko
|
|
|
|
| 48 |
print(f"FTP upload error: {e}")
|
| 49 |
'''
|
| 50 |
|
| 51 |
+
upscaler_2 = UpscaleWithModel.from_pretrained("Kim2091/ClearRealityV1").to(torch.device('cuda'))
|
| 52 |
+
|
| 53 |
pyx = cyper.inline(code, fast_indexing=True, directives=dict(boundscheck=False, wraparound=False, language_level=3))
|
| 54 |
|
| 55 |
MAX_SEED = np.iinfo(np.int32).max
|
|
|
|
| 77 |
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
| 78 |
pyx.upload_to_ftp(sd35_path)
|
| 79 |
with torch.no_grad():
|
| 80 |
+
upscale2 = upscaler_2(sd_image, tiling=True, tile_width=256, tile_height=256)
|
| 81 |
print('-- got upscaled image --')
|
| 82 |
downscale2 = upscale2.resize((upscale2.width // 4, upscale2.height // 4),Image.LANCZOS)
|
| 83 |
upscale_path = f"sd3keras_upscale_{timestamp}.png"
|
|
|
|
| 106 |
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
| 107 |
pyx.upload_to_ftp(sd35_path)
|
| 108 |
with torch.no_grad():
|
| 109 |
+
upscale2 = upscaler_2(sd_image, tiling=True, tile_width=256, tile_height=256)
|
| 110 |
print('-- got upscaled image --')
|
| 111 |
downscale2 = upscale2.resize((upscale2.width // 4, upscale2.height // 4),Image.LANCZOS)
|
| 112 |
upscale_path = f"sd3keras_upscale_{timestamp}.png"
|
|
|
|
| 135 |
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
| 136 |
pyx.upload_to_ftp(sd35_path)
|
| 137 |
with torch.no_grad():
|
| 138 |
+
upscale2 = upscaler_2(sd_image, tiling=True, tile_width=256, tile_height=256)
|
| 139 |
print('-- got upscaled image --')
|
| 140 |
downscale2 = upscale2.resize((upscale2.width // 4, upscale2.height // 4),Image.LANCZOS)
|
| 141 |
upscale_path = f"sd3keras_upscale_{timestamp}.png"
|