Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -15,15 +15,13 @@ import os
|
|
15 |
from image_gen_aux import UpscaleWithModel
|
16 |
from huggingface_hub import hf_hub_download
|
17 |
|
|
|
|
|
18 |
#from diffusers import SD3Transformer2DModel, AutoencoderKL
|
19 |
#from models.transformer_sd3 import SD3Transformer2DModel
|
20 |
#from pipeline_stable_diffusion_3_ipa import StableDiffusion3Pipeline
|
21 |
-
from PIL import Image
|
22 |
|
23 |
-
|
24 |
-
FTP_USER = "ford442"
|
25 |
-
FTP_PASS = "GoogleBez12!"
|
26 |
-
FTP_DIR = "1ink.us/stable_diff/" # Remote directory on FTP server
|
27 |
|
28 |
torch.backends.cuda.matmul.allow_tf32 = False
|
29 |
torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = False
|
@@ -36,6 +34,16 @@ torch.backends.cudnn.benchmark = False
|
|
36 |
|
37 |
hftoken = os.getenv("HF_AUTH_TOKEN")
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
def upload_to_ftp(filename):
|
40 |
try:
|
41 |
transport = paramiko.Transport((FTP_HOST, 22))
|
@@ -48,6 +56,10 @@ def upload_to_ftp(filename):
|
|
48 |
print(f"Uploaded {filename} to FTP server")
|
49 |
except Exception as e:
|
50 |
print(f"FTP upload error: {e}")
|
|
|
|
|
|
|
|
|
51 |
|
52 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
53 |
torch_dtype = torch.bfloat16
|
@@ -68,10 +80,7 @@ pipe = StableDiffusion3Pipeline.from_pretrained(
|
|
68 |
)
|
69 |
|
70 |
#pipe.to(device=device, dtype=torch.bfloat16)
|
71 |
-
|
72 |
-
#pipe.enable_model_cpu_offload()
|
73 |
pipe.to(device)
|
74 |
-
#pipe.to(device=device, dtype=torch.bfloat16)
|
75 |
|
76 |
upscaler_2 = UpscaleWithModel.from_pretrained("Kim2091/ClearRealityV1").to(torch.device('cpu'))
|
77 |
|
@@ -79,7 +88,7 @@ MAX_SEED = np.iinfo(np.int32).max
|
|
79 |
|
80 |
MAX_IMAGE_SIZE = 4096
|
81 |
|
82 |
-
@spaces.GPU(duration=
|
83 |
def infer_30(
|
84 |
prompt,
|
85 |
negative_prompt_1,
|
@@ -110,21 +119,22 @@ def infer_30(
|
|
110 |
max_sequence_length=512
|
111 |
).images[0]
|
112 |
print('-- got image --')
|
113 |
-
|
|
|
114 |
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
115 |
-
upload_to_ftp(sd35_path)
|
116 |
# pipe.unet.to('cpu')
|
117 |
upscaler_2.to(torch.device('cuda'))
|
118 |
with torch.no_grad():
|
119 |
upscale2 = upscaler_2(sd_image, tiling=True, tile_width=256, tile_height=256)
|
120 |
print('-- got upscaled image --')
|
121 |
downscale2 = upscale2.resize((upscale2.width // 4, upscale2.height // 4),Image.LANCZOS)
|
122 |
-
upscale_path = f"sd35l_upscale_{
|
123 |
downscale2.save(upscale_path,optimize=False,compress_level=0)
|
124 |
-
upload_to_ftp(upscale_path)
|
125 |
return sd_image, prompt
|
126 |
|
127 |
-
@spaces.GPU(duration=
|
128 |
def infer_60(
|
129 |
prompt,
|
130 |
negative_prompt_1,
|
@@ -155,21 +165,22 @@ def infer_60(
|
|
155 |
max_sequence_length=512
|
156 |
).images[0]
|
157 |
print('-- got image --')
|
158 |
-
|
|
|
159 |
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
160 |
-
upload_to_ftp(sd35_path)
|
161 |
# pipe.unet.to('cpu')
|
162 |
upscaler_2.to(torch.device('cuda'))
|
163 |
with torch.no_grad():
|
164 |
upscale2 = upscaler_2(sd_image, tiling=True, tile_width=256, tile_height=256)
|
165 |
print('-- got upscaled image --')
|
166 |
downscale2 = upscale2.resize((upscale2.width // 4, upscale2.height // 4),Image.LANCZOS)
|
167 |
-
upscale_path = f"sd35l_upscale_{
|
168 |
downscale2.save(upscale_path,optimize=False,compress_level=0)
|
169 |
-
upload_to_ftp(upscale_path)
|
170 |
return sd_image, prompt
|
171 |
|
172 |
-
@spaces.GPU(duration=
|
173 |
def infer_90(
|
174 |
prompt,
|
175 |
negative_prompt_1,
|
@@ -200,21 +211,22 @@ def infer_90(
|
|
200 |
max_sequence_length=512
|
201 |
).images[0]
|
202 |
print('-- got image --')
|
203 |
-
|
|
|
204 |
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
205 |
-
upload_to_ftp(sd35_path)
|
206 |
# pipe.unet.to('cpu')
|
207 |
upscaler_2.to(torch.device('cuda'))
|
208 |
with torch.no_grad():
|
209 |
upscale2 = upscaler_2(sd_image, tiling=True, tile_width=256, tile_height=256)
|
210 |
print('-- got upscaled image --')
|
211 |
downscale2 = upscale2.resize((upscale2.width // 4, upscale2.height // 4),Image.LANCZOS)
|
212 |
-
upscale_path = f"sd35l_upscale_{
|
213 |
downscale2.save(upscale_path,optimize=False,compress_level=0)
|
214 |
-
upload_to_ftp(upscale_path)
|
215 |
return sd_image, prompt
|
216 |
|
217 |
-
@spaces.GPU(duration=
|
218 |
def infer_100(
|
219 |
prompt,
|
220 |
negative_prompt_1,
|
@@ -245,18 +257,19 @@ def infer_100(
|
|
245 |
max_sequence_length=512
|
246 |
).images[0]
|
247 |
print('-- got image --')
|
248 |
-
|
|
|
249 |
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
250 |
-
upload_to_ftp(sd35_path)
|
251 |
# pipe.unet.to('cpu')
|
252 |
upscaler_2.to(torch.device('cuda'))
|
253 |
with torch.no_grad():
|
254 |
upscale2 = upscaler_2(sd_image, tiling=True, tile_width=256, tile_height=256)
|
255 |
print('-- got upscaled image --')
|
256 |
downscale2 = upscale2.resize((upscale2.width // 4, upscale2.height // 4),Image.LANCZOS)
|
257 |
-
upscale_path = f"sd35l_upscale_{
|
258 |
downscale2.save(upscale_path,optimize=False,compress_level=0)
|
259 |
-
upload_to_ftp(upscale_path)
|
260 |
return sd_image, prompt
|
261 |
|
262 |
css = """
|
|
|
15 |
from image_gen_aux import UpscaleWithModel
|
16 |
from huggingface_hub import hf_hub_download
|
17 |
|
18 |
+
import cyper
|
19 |
+
|
20 |
#from diffusers import SD3Transformer2DModel, AutoencoderKL
|
21 |
#from models.transformer_sd3 import SD3Transformer2DModel
|
22 |
#from pipeline_stable_diffusion_3_ipa import StableDiffusion3Pipeline
|
|
|
23 |
|
24 |
+
from PIL import Image
|
|
|
|
|
|
|
25 |
|
26 |
torch.backends.cuda.matmul.allow_tf32 = False
|
27 |
torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = False
|
|
|
34 |
|
35 |
hftoken = os.getenv("HF_AUTH_TOKEN")
|
36 |
|
37 |
+
|
38 |
+
code = r'''
|
39 |
+
import torch
|
40 |
+
import paramiko
|
41 |
+
import os
|
42 |
+
FTP_HOST = os.getenv("FTP_HOST")
|
43 |
+
FTP_USER = os.getenv("FTP_USER")
|
44 |
+
FTP_PASS = os.getenv("FTP_PASS")
|
45 |
+
FTP_DIR = os.getenv("FTP_DIR")
|
46 |
+
|
47 |
def upload_to_ftp(filename):
|
48 |
try:
|
49 |
transport = paramiko.Transport((FTP_HOST, 22))
|
|
|
56 |
print(f"Uploaded {filename} to FTP server")
|
57 |
except Exception as e:
|
58 |
print(f"FTP upload error: {e}")
|
59 |
+
|
60 |
+
'''
|
61 |
+
|
62 |
+
pyx = cyper.inline(code, fast_indexing=True, directives=dict(boundscheck=False, wraparound=False, language_level=3))
|
63 |
|
64 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
65 |
torch_dtype = torch.bfloat16
|
|
|
80 |
)
|
81 |
|
82 |
#pipe.to(device=device, dtype=torch.bfloat16)
|
|
|
|
|
83 |
pipe.to(device)
|
|
|
84 |
|
85 |
upscaler_2 = UpscaleWithModel.from_pretrained("Kim2091/ClearRealityV1").to(torch.device('cpu'))
|
86 |
|
|
|
88 |
|
89 |
MAX_IMAGE_SIZE = 4096
|
90 |
|
91 |
+
@spaces.GPU(duration=40)
|
92 |
def infer_30(
|
93 |
prompt,
|
94 |
negative_prompt_1,
|
|
|
119 |
max_sequence_length=512
|
120 |
).images[0]
|
121 |
print('-- got image --')
|
122 |
+
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
123 |
+
sd35_path = f"sd35l_{timestamp}.png"
|
124 |
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
125 |
+
pyx.upload_to_ftp(sd35_path)
|
126 |
# pipe.unet.to('cpu')
|
127 |
upscaler_2.to(torch.device('cuda'))
|
128 |
with torch.no_grad():
|
129 |
upscale2 = upscaler_2(sd_image, tiling=True, tile_width=256, tile_height=256)
|
130 |
print('-- got upscaled image --')
|
131 |
downscale2 = upscale2.resize((upscale2.width // 4, upscale2.height // 4),Image.LANCZOS)
|
132 |
+
upscale_path = f"sd35l_upscale_{timestamp}.png"
|
133 |
downscale2.save(upscale_path,optimize=False,compress_level=0)
|
134 |
+
pyx.upload_to_ftp(upscale_path)
|
135 |
return sd_image, prompt
|
136 |
|
137 |
+
@spaces.GPU(duration=70)
|
138 |
def infer_60(
|
139 |
prompt,
|
140 |
negative_prompt_1,
|
|
|
165 |
max_sequence_length=512
|
166 |
).images[0]
|
167 |
print('-- got image --')
|
168 |
+
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
169 |
+
sd35_path = f"sd35l_{timestamp}.png"
|
170 |
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
171 |
+
pyx.upload_to_ftp(sd35_path)
|
172 |
# pipe.unet.to('cpu')
|
173 |
upscaler_2.to(torch.device('cuda'))
|
174 |
with torch.no_grad():
|
175 |
upscale2 = upscaler_2(sd_image, tiling=True, tile_width=256, tile_height=256)
|
176 |
print('-- got upscaled image --')
|
177 |
downscale2 = upscale2.resize((upscale2.width // 4, upscale2.height // 4),Image.LANCZOS)
|
178 |
+
upscale_path = f"sd35l_upscale_{timestamp}.png"
|
179 |
downscale2.save(upscale_path,optimize=False,compress_level=0)
|
180 |
+
pyx.upload_to_ftp(upscale_path)
|
181 |
return sd_image, prompt
|
182 |
|
183 |
+
@spaces.GPU(duration=100)
|
184 |
def infer_90(
|
185 |
prompt,
|
186 |
negative_prompt_1,
|
|
|
211 |
max_sequence_length=512
|
212 |
).images[0]
|
213 |
print('-- got image --')
|
214 |
+
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
215 |
+
sd35_path = f"sd35l_{timestamp}.png"
|
216 |
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
217 |
+
pyx.upload_to_ftp(sd35_path)
|
218 |
# pipe.unet.to('cpu')
|
219 |
upscaler_2.to(torch.device('cuda'))
|
220 |
with torch.no_grad():
|
221 |
upscale2 = upscaler_2(sd_image, tiling=True, tile_width=256, tile_height=256)
|
222 |
print('-- got upscaled image --')
|
223 |
downscale2 = upscale2.resize((upscale2.width // 4, upscale2.height // 4),Image.LANCZOS)
|
224 |
+
upscale_path = f"sd35l_upscale_{timestamp}.png"
|
225 |
downscale2.save(upscale_path,optimize=False,compress_level=0)
|
226 |
+
pyx.upload_to_ftp(upscale_path)
|
227 |
return sd_image, prompt
|
228 |
|
229 |
+
@spaces.GPU(duration=110)
|
230 |
def infer_100(
|
231 |
prompt,
|
232 |
negative_prompt_1,
|
|
|
257 |
max_sequence_length=512
|
258 |
).images[0]
|
259 |
print('-- got image --')
|
260 |
+
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
261 |
+
sd35_path = f"sd35l_{timestamp}.png"
|
262 |
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
263 |
+
pyx.upload_to_ftp(sd35_path)
|
264 |
# pipe.unet.to('cpu')
|
265 |
upscaler_2.to(torch.device('cuda'))
|
266 |
with torch.no_grad():
|
267 |
upscale2 = upscaler_2(sd_image, tiling=True, tile_width=256, tile_height=256)
|
268 |
print('-- got upscaled image --')
|
269 |
downscale2 = upscale2.resize((upscale2.width // 4, upscale2.height // 4),Image.LANCZOS)
|
270 |
+
upscale_path = f"sd35l_upscale_{timestamp}.png"
|
271 |
downscale2.save(upscale_path,optimize=False,compress_level=0)
|
272 |
+
pyx.upload_to_ftp(upscale_path)
|
273 |
return sd_image, prompt
|
274 |
|
275 |
css = """
|