Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,15 @@
|
|
1 |
import spaces
|
2 |
import os
|
3 |
|
4 |
-
os.putenv('PYTORCH_NVML_BASED_CUDA_CHECK','1')
|
5 |
-
os.putenv('TORCH_LINALG_PREFER_CUSOLVER','1')
|
6 |
alloc_conf_parts = [
|
7 |
'expandable_segments:True',
|
8 |
'pinned_use_background_threads:True' # Specific to pinned memory.
|
9 |
]
|
10 |
-
os.environ['PYTORCH_CUDA_ALLOC_CONF'] = ','.join(alloc_conf_parts)
|
11 |
-
os.environ["SAFETENSORS_FAST_GPU"] = "1"
|
12 |
-
os.putenv('HF_HUB_ENABLE_HF_TRANSFER','1')
|
13 |
|
14 |
import gradio as gr
|
15 |
import numpy as np
|
@@ -27,14 +27,14 @@ import time
|
|
27 |
from image_gen_aux import UpscaleWithModel
|
28 |
from huggingface_hub import hf_hub_download
|
29 |
import datetime
|
30 |
-
import cyper
|
31 |
|
32 |
from diffusers import AutoencoderKL
|
33 |
#from models.transformer_sd3 import SD3Transformer2DModel
|
34 |
#from pipeline_stable_diffusion_3_ipa import StableDiffusion3Pipeline
|
35 |
|
36 |
from PIL import Image
|
37 |
-
|
38 |
torch.backends.cuda.matmul.allow_tf32 = False
|
39 |
torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = False
|
40 |
torch.backends.cuda.matmul.allow_fp16_reduced_precision_reduction = False
|
@@ -44,10 +44,10 @@ torch.backends.cudnn.benchmark = False
|
|
44 |
torch.backends.cuda.preferred_blas_library="cublas"
|
45 |
torch.backends.cuda.preferred_linalg_library="cusolver"
|
46 |
torch.set_float32_matmul_precision("highest")
|
47 |
-
|
48 |
hftoken = os.getenv("HF_AUTH_TOKEN")
|
49 |
|
50 |
-
code = r'''
|
51 |
import torch
|
52 |
import paramiko
|
53 |
import os
|
@@ -68,9 +68,9 @@ def upload_to_ftp(filename):
|
|
68 |
print(f"Uploaded {filename} to FTP server")
|
69 |
except Exception as e:
|
70 |
print(f"FTP upload error: {e}")
|
71 |
-
'''
|
72 |
|
73 |
-
pyx = cyper.inline(code, fast_indexing=True, directives=dict(boundscheck=False, wraparound=False, language_level=3))
|
74 |
|
75 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
76 |
#vae=AutoencoderKL.from_pretrained("ford442/sdxl-vae-bf16", use_safetensors=True, subfolder='vae',token=True)
|
@@ -82,11 +82,11 @@ pipe = StableDiffusion3Pipeline.from_pretrained(
|
|
82 |
#vae=None,
|
83 |
#vae=AutoencoderKL.from_pretrained("ford442/stable-diffusion-3.5-large-fp32", use_safetensors=True, subfolder='vae',token=True),
|
84 |
#scheduler = FlowMatchHeunDiscreteScheduler.from_pretrained('ford442/stable-diffusion-3.5-large-bf16', subfolder='scheduler',token=True),
|
85 |
-
text_encoder=None, #CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder', token=True),
|
86 |
# text_encoder=CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder', token=True),
|
87 |
-
text_encoder_2=None, #CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_2',token=True),
|
88 |
# text_encoder_2=CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_2',token=True),
|
89 |
-
text_encoder_3=None, #T5EncoderModel.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_3',token=True),
|
90 |
# text_encoder_3=T5EncoderModel.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_3',token=True),
|
91 |
#tokenizer=CLIPTokenizer.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", add_prefix_space=True, subfolder="tokenizer", token=True),
|
92 |
#tokenizer_2=CLIPTokenizer.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", add_prefix_space=True, subfolder="tokenizer_2", token=True),
|
@@ -95,9 +95,9 @@ pipe = StableDiffusion3Pipeline.from_pretrained(
|
|
95 |
#torch_dtype=torch.bfloat16,
|
96 |
#use_safetensors=False,
|
97 |
)
|
98 |
-
text_encoder=CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder', token=True).to(torch.device("cuda:0")) #, dtype=torch.bfloat16)
|
99 |
-
text_encoder_2=CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_2',token=True).to(torch.device("cuda:0")) #, dtype=torch.bfloat16)
|
100 |
-
text_encoder_3=T5EncoderModel.from_pretrained("ford442/stable-diffusion-3.5-large-fp32", subfolder='text_encoder_3',token=True).to(torch.device("cuda:0")) #, dtype=torch.bfloat16)
|
101 |
|
102 |
pipe.load_lora_weights("ford442/sdxl-vae-bf16", weight_name="LoRA/UltraReal.safetensors")
|
103 |
|
@@ -122,9 +122,9 @@ def infer_30(
|
|
122 |
num_inference_steps,
|
123 |
progress=gr.Progress(track_tqdm=True),
|
124 |
):
|
125 |
-
pipe.text_encoder=text_encoder #CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder', token=True).to(device=device, dtype=torch.bfloat16)
|
126 |
-
pipe.text_encoder_2=text_encoder_2 #CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_2',token=True).to(device=device, dtype=torch.bfloat16)
|
127 |
-
pipe.text_encoder_3=text_encoder_3 #T5EncoderModel.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_3',token=True).to(device=device, dtype=torch.bfloat16)
|
128 |
seed = random.randint(0, MAX_SEED)
|
129 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
130 |
print('-- generating image --')
|
@@ -147,7 +147,8 @@ def infer_30(
|
|
147 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
148 |
sd35_path = f"sd35ll_{timestamp}.png"
|
149 |
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
150 |
-
pyx.upload_to_ftp(sd35_path)
|
|
|
151 |
# pipe.unet.to('cpu')
|
152 |
upscaler_2.to(torch.device('cuda'))
|
153 |
with torch.no_grad():
|
@@ -156,7 +157,8 @@ def infer_30(
|
|
156 |
downscale2 = upscale2.resize((upscale2.width // 4, upscale2.height // 4),Image.LANCZOS)
|
157 |
upscale_path = f"sd35ll_upscale_{timestamp}.png"
|
158 |
downscale2.save(upscale_path,optimize=False,compress_level=0)
|
159 |
-
pyx.upload_to_ftp(upscale_path)
|
|
|
160 |
return sd_image, prompt
|
161 |
|
162 |
@spaces.GPU(duration=70)
|
@@ -171,9 +173,9 @@ def infer_60(
|
|
171 |
num_inference_steps,
|
172 |
progress=gr.Progress(track_tqdm=True),
|
173 |
):
|
174 |
-
pipe.text_encoder=text_encoder #CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder', token=True).to(device=device, dtype=torch.bfloat16)
|
175 |
-
pipe.text_encoder_2=text_encoder_2 #CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_2',token=True).to(device=device, dtype=torch.bfloat16)
|
176 |
-
pipe.text_encoder_3=text_encoder_3 #T5EncoderModel.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_3',token=True).to(device=device, dtype=torch.bfloat16)
|
177 |
seed = random.randint(0, MAX_SEED)
|
178 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
179 |
print('-- generating image --')
|
@@ -196,16 +198,18 @@ def infer_60(
|
|
196 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
197 |
sd35_path = f"sd35ll_{timestamp}.png"
|
198 |
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
199 |
-
pyx.upload_to_ftp(sd35_path)
|
|
|
200 |
# pipe.unet.to('cpu')
|
201 |
upscaler_2.to(torch.device('cuda'))
|
202 |
with torch.no_grad():
|
203 |
upscale2 = upscaler_2(sd_image, tiling=True, tile_width=256, tile_height=256)
|
204 |
print('-- got upscaled image --')
|
205 |
-
downscale2 = upscale2.resize((upscale2.width //
|
206 |
upscale_path = f"sd35ll_upscale_{timestamp}.png"
|
207 |
downscale2.save(upscale_path,optimize=False,compress_level=0)
|
208 |
-
pyx.upload_to_ftp(upscale_path)
|
|
|
209 |
return sd_image, prompt
|
210 |
|
211 |
@spaces.GPU(duration=100)
|
@@ -220,9 +224,9 @@ def infer_90(
|
|
220 |
num_inference_steps,
|
221 |
progress=gr.Progress(track_tqdm=True),
|
222 |
):
|
223 |
-
pipe.text_encoder=text_encoder #CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder', token=True).to(device=device, dtype=torch.bfloat16)
|
224 |
-
pipe.text_encoder_2=text_encoder_2 #CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_2',token=True).to(device=device, dtype=torch.bfloat16)
|
225 |
-
pipe.text_encoder_3=text_encoder_3 #T5EncoderModel.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_3',token=True).to(device=device, dtype=torch.bfloat16)
|
226 |
seed = random.randint(0, MAX_SEED)
|
227 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
228 |
print('-- generating image --')
|
@@ -245,16 +249,18 @@ def infer_90(
|
|
245 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
246 |
sd35_path = f"sd35ll_{timestamp}.png"
|
247 |
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
248 |
-
pyx.upload_to_ftp(sd35_path)
|
|
|
249 |
# pipe.unet.to('cpu')
|
250 |
upscaler_2.to(torch.device('cuda'))
|
251 |
with torch.no_grad():
|
252 |
upscale2 = upscaler_2(sd_image, tiling=True, tile_width=256, tile_height=256)
|
253 |
print('-- got upscaled image --')
|
254 |
-
downscale2 = upscale2.resize((upscale2.width //
|
255 |
upscale_path = f"sd35ll_upscale_{timestamp}.png"
|
256 |
downscale2.save(upscale_path,optimize=False,compress_level=0)
|
257 |
-
pyx.upload_to_ftp(upscale_path)
|
|
|
258 |
return sd_image, prompt
|
259 |
|
260 |
@spaces.GPU(duration=110)
|
@@ -269,6 +275,9 @@ def infer_100(
|
|
269 |
num_inference_steps,
|
270 |
progress=gr.Progress(track_tqdm=True),
|
271 |
):
|
|
|
|
|
|
|
272 |
seed = random.randint(0, MAX_SEED)
|
273 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
274 |
print('-- generating image --')
|
@@ -283,6 +292,7 @@ def infer_100(
|
|
283 |
num_inference_steps=num_inference_steps,
|
284 |
width=width,
|
285 |
height=height,
|
|
|
286 |
generator=generator,
|
287 |
max_sequence_length=512
|
288 |
).images[0]
|
@@ -290,16 +300,18 @@ def infer_100(
|
|
290 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
291 |
sd35_path = f"sd35ll_{timestamp}.png"
|
292 |
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
293 |
-
pyx.upload_to_ftp(sd35_path)
|
|
|
294 |
# pipe.unet.to('cpu')
|
295 |
upscaler_2.to(torch.device('cuda'))
|
296 |
with torch.no_grad():
|
297 |
upscale2 = upscaler_2(sd_image, tiling=True, tile_width=256, tile_height=256)
|
298 |
print('-- got upscaled image --')
|
299 |
-
downscale2 = upscale2.resize((upscale2.width //
|
300 |
upscale_path = f"sd35ll_upscale_{timestamp}.png"
|
301 |
downscale2.save(upscale_path,optimize=False,compress_level=0)
|
302 |
-
pyx.upload_to_ftp(upscale_path)
|
|
|
303 |
return sd_image, prompt
|
304 |
|
305 |
css = """
|
|
|
1 |
import spaces
|
2 |
import os
|
3 |
|
4 |
+
# os.putenv('PYTORCH_NVML_BASED_CUDA_CHECK','1')
|
5 |
+
# os.putenv('TORCH_LINALG_PREFER_CUSOLVER','1')
|
6 |
alloc_conf_parts = [
|
7 |
'expandable_segments:True',
|
8 |
'pinned_use_background_threads:True' # Specific to pinned memory.
|
9 |
]
|
10 |
+
# os.environ['PYTORCH_CUDA_ALLOC_CONF'] = ','.join(alloc_conf_parts)
|
11 |
+
# os.environ["SAFETENSORS_FAST_GPU"] = "1"
|
12 |
+
# os.putenv('HF_HUB_ENABLE_HF_TRANSFER','1')
|
13 |
|
14 |
import gradio as gr
|
15 |
import numpy as np
|
|
|
27 |
from image_gen_aux import UpscaleWithModel
|
28 |
from huggingface_hub import hf_hub_download
|
29 |
import datetime
|
30 |
+
#import cyper
|
31 |
|
32 |
from diffusers import AutoencoderKL
|
33 |
#from models.transformer_sd3 import SD3Transformer2DModel
|
34 |
#from pipeline_stable_diffusion_3_ipa import StableDiffusion3Pipeline
|
35 |
|
36 |
from PIL import Image
|
37 |
+
/*
|
38 |
torch.backends.cuda.matmul.allow_tf32 = False
|
39 |
torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = False
|
40 |
torch.backends.cuda.matmul.allow_fp16_reduced_precision_reduction = False
|
|
|
44 |
torch.backends.cuda.preferred_blas_library="cublas"
|
45 |
torch.backends.cuda.preferred_linalg_library="cusolver"
|
46 |
torch.set_float32_matmul_precision("highest")
|
47 |
+
*/
|
48 |
hftoken = os.getenv("HF_AUTH_TOKEN")
|
49 |
|
50 |
+
# code = r'''
|
51 |
import torch
|
52 |
import paramiko
|
53 |
import os
|
|
|
68 |
print(f"Uploaded {filename} to FTP server")
|
69 |
except Exception as e:
|
70 |
print(f"FTP upload error: {e}")
|
71 |
+
# '''
|
72 |
|
73 |
+
# pyx = cyper.inline(code, fast_indexing=True, directives=dict(boundscheck=False, wraparound=False, language_level=3))
|
74 |
|
75 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
76 |
#vae=AutoencoderKL.from_pretrained("ford442/sdxl-vae-bf16", use_safetensors=True, subfolder='vae',token=True)
|
|
|
82 |
#vae=None,
|
83 |
#vae=AutoencoderKL.from_pretrained("ford442/stable-diffusion-3.5-large-fp32", use_safetensors=True, subfolder='vae',token=True),
|
84 |
#scheduler = FlowMatchHeunDiscreteScheduler.from_pretrained('ford442/stable-diffusion-3.5-large-bf16', subfolder='scheduler',token=True),
|
85 |
+
# text_encoder=None, #CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder', token=True),
|
86 |
# text_encoder=CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder', token=True),
|
87 |
+
# text_encoder_2=None, #CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_2',token=True),
|
88 |
# text_encoder_2=CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_2',token=True),
|
89 |
+
# text_encoder_3=None, #T5EncoderModel.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_3',token=True),
|
90 |
# text_encoder_3=T5EncoderModel.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_3',token=True),
|
91 |
#tokenizer=CLIPTokenizer.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", add_prefix_space=True, subfolder="tokenizer", token=True),
|
92 |
#tokenizer_2=CLIPTokenizer.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", add_prefix_space=True, subfolder="tokenizer_2", token=True),
|
|
|
95 |
#torch_dtype=torch.bfloat16,
|
96 |
#use_safetensors=False,
|
97 |
)
|
98 |
+
#text_encoder=CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder', token=True).to(torch.device("cuda:0")) #, dtype=torch.bfloat16)
|
99 |
+
#text_encoder_2=CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_2',token=True).to(torch.device("cuda:0")) #, dtype=torch.bfloat16)
|
100 |
+
#text_encoder_3=T5EncoderModel.from_pretrained("ford442/stable-diffusion-3.5-large-fp32", subfolder='text_encoder_3',token=True).to(torch.device("cuda:0")) #, dtype=torch.bfloat16)
|
101 |
|
102 |
pipe.load_lora_weights("ford442/sdxl-vae-bf16", weight_name="LoRA/UltraReal.safetensors")
|
103 |
|
|
|
122 |
num_inference_steps,
|
123 |
progress=gr.Progress(track_tqdm=True),
|
124 |
):
|
125 |
+
#pipe.text_encoder=text_encoder #CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder', token=True).to(device=device, dtype=torch.bfloat16)
|
126 |
+
#pipe.text_encoder_2=text_encoder_2 #CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_2',token=True).to(device=device, dtype=torch.bfloat16)
|
127 |
+
#pipe.text_encoder_3=text_encoder_3 #T5EncoderModel.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_3',token=True).to(device=device, dtype=torch.bfloat16)
|
128 |
seed = random.randint(0, MAX_SEED)
|
129 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
130 |
print('-- generating image --')
|
|
|
147 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
148 |
sd35_path = f"sd35ll_{timestamp}.png"
|
149 |
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
150 |
+
#pyx.upload_to_ftp(sd35_path)
|
151 |
+
upload_to_ftp(sd35_path)
|
152 |
# pipe.unet.to('cpu')
|
153 |
upscaler_2.to(torch.device('cuda'))
|
154 |
with torch.no_grad():
|
|
|
157 |
downscale2 = upscale2.resize((upscale2.width // 4, upscale2.height // 4),Image.LANCZOS)
|
158 |
upscale_path = f"sd35ll_upscale_{timestamp}.png"
|
159 |
downscale2.save(upscale_path,optimize=False,compress_level=0)
|
160 |
+
#pyx.upload_to_ftp(upscale_path)
|
161 |
+
upload_to_ftp(upscale_path)
|
162 |
return sd_image, prompt
|
163 |
|
164 |
@spaces.GPU(duration=70)
|
|
|
173 |
num_inference_steps,
|
174 |
progress=gr.Progress(track_tqdm=True),
|
175 |
):
|
176 |
+
#pipe.text_encoder=text_encoder #CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder', token=True).to(device=device, dtype=torch.bfloat16)
|
177 |
+
#pipe.text_encoder_2=text_encoder_2 #CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_2',token=True).to(device=device, dtype=torch.bfloat16)
|
178 |
+
#pipe.text_encoder_3=text_encoder_3 #T5EncoderModel.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_3',token=True).to(device=device, dtype=torch.bfloat16)
|
179 |
seed = random.randint(0, MAX_SEED)
|
180 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
181 |
print('-- generating image --')
|
|
|
198 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
199 |
sd35_path = f"sd35ll_{timestamp}.png"
|
200 |
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
201 |
+
#pyx.upload_to_ftp(sd35_path)
|
202 |
+
upload_to_ftp(sd35_path)
|
203 |
# pipe.unet.to('cpu')
|
204 |
upscaler_2.to(torch.device('cuda'))
|
205 |
with torch.no_grad():
|
206 |
upscale2 = upscaler_2(sd_image, tiling=True, tile_width=256, tile_height=256)
|
207 |
print('-- got upscaled image --')
|
208 |
+
downscale2 = upscale2.resize((upscale2.width // 4, upscale2.height // 4),Image.LANCZOS)
|
209 |
upscale_path = f"sd35ll_upscale_{timestamp}.png"
|
210 |
downscale2.save(upscale_path,optimize=False,compress_level=0)
|
211 |
+
#pyx.upload_to_ftp(upscale_path)
|
212 |
+
upload_to_ftp(upscale_path)
|
213 |
return sd_image, prompt
|
214 |
|
215 |
@spaces.GPU(duration=100)
|
|
|
224 |
num_inference_steps,
|
225 |
progress=gr.Progress(track_tqdm=True),
|
226 |
):
|
227 |
+
#pipe.text_encoder=text_encoder #CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder', token=True).to(device=device, dtype=torch.bfloat16)
|
228 |
+
#pipe.text_encoder_2=text_encoder_2 #CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_2',token=True).to(device=device, dtype=torch.bfloat16)
|
229 |
+
#pipe.text_encoder_3=text_encoder_3 #T5EncoderModel.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_3',token=True).to(device=device, dtype=torch.bfloat16)
|
230 |
seed = random.randint(0, MAX_SEED)
|
231 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
232 |
print('-- generating image --')
|
|
|
249 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
250 |
sd35_path = f"sd35ll_{timestamp}.png"
|
251 |
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
252 |
+
#pyx.upload_to_ftp(sd35_path)
|
253 |
+
upload_to_ftp(sd35_path)
|
254 |
# pipe.unet.to('cpu')
|
255 |
upscaler_2.to(torch.device('cuda'))
|
256 |
with torch.no_grad():
|
257 |
upscale2 = upscaler_2(sd_image, tiling=True, tile_width=256, tile_height=256)
|
258 |
print('-- got upscaled image --')
|
259 |
+
downscale2 = upscale2.resize((upscale2.width // 4, upscale2.height // 4),Image.LANCZOS)
|
260 |
upscale_path = f"sd35ll_upscale_{timestamp}.png"
|
261 |
downscale2.save(upscale_path,optimize=False,compress_level=0)
|
262 |
+
#pyx.upload_to_ftp(upscale_path)
|
263 |
+
upload_to_ftp(upscale_path)
|
264 |
return sd_image, prompt
|
265 |
|
266 |
@spaces.GPU(duration=110)
|
|
|
275 |
num_inference_steps,
|
276 |
progress=gr.Progress(track_tqdm=True),
|
277 |
):
|
278 |
+
#pipe.text_encoder=text_encoder #CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder', token=True).to(device=device, dtype=torch.bfloat16)
|
279 |
+
#pipe.text_encoder_2=text_encoder_2 #CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_2',token=True).to(device=device, dtype=torch.bfloat16)
|
280 |
+
#pipe.text_encoder_3=text_encoder_3 #T5EncoderModel.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder_3',token=True).to(device=device, dtype=torch.bfloat16)
|
281 |
seed = random.randint(0, MAX_SEED)
|
282 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
283 |
print('-- generating image --')
|
|
|
292 |
num_inference_steps=num_inference_steps,
|
293 |
width=width,
|
294 |
height=height,
|
295 |
+
# cross_attention_kwargs={"scale": 0.75},
|
296 |
generator=generator,
|
297 |
max_sequence_length=512
|
298 |
).images[0]
|
|
|
300 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
301 |
sd35_path = f"sd35ll_{timestamp}.png"
|
302 |
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
303 |
+
#pyx.upload_to_ftp(sd35_path)
|
304 |
+
upload_to_ftp(sd35_path)
|
305 |
# pipe.unet.to('cpu')
|
306 |
upscaler_2.to(torch.device('cuda'))
|
307 |
with torch.no_grad():
|
308 |
upscale2 = upscaler_2(sd_image, tiling=True, tile_width=256, tile_height=256)
|
309 |
print('-- got upscaled image --')
|
310 |
+
downscale2 = upscale2.resize((upscale2.width // 4, upscale2.height // 4),Image.LANCZOS)
|
311 |
upscale_path = f"sd35ll_upscale_{timestamp}.png"
|
312 |
downscale2.save(upscale_path,optimize=False,compress_level=0)
|
313 |
+
#pyx.upload_to_ftp(upscale_path)
|
314 |
+
upload_to_ftp(upscale_path)
|
315 |
return sd_image, prompt
|
316 |
|
317 |
css = """
|