Update app.py
Browse files
app.py
CHANGED
@@ -87,7 +87,13 @@ pipe.vae=vaeX.to(device)
|
|
87 |
text_encoder=CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder', token=True).to(device=device, dtype=torch.bfloat16)
|
88 |
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)
|
89 |
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)
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
upscaler_2 = UpscaleWithModel.from_pretrained("Kim2091/ClearRealityV1").to(torch.device("cuda:0"))
|
92 |
|
93 |
MAX_SEED = np.iinfo(np.int32).max
|
@@ -151,11 +157,6 @@ def infer(
|
|
151 |
sd_image_e.resize((height,width), Image.LANCZOS)
|
152 |
else:
|
153 |
sd_image_e = None
|
154 |
-
pipe.init_ipadapter(
|
155 |
-
ip_adapter_path=ipadapter_path,
|
156 |
-
image_encoder_path=image_encoder_path,
|
157 |
-
nb_token=64,
|
158 |
-
)
|
159 |
print('-- generating image --')
|
160 |
sd_image = pipe(
|
161 |
width=width,
|
@@ -180,38 +181,19 @@ def infer(
|
|
180 |
scale_5=latent_file_5_scale,
|
181 |
).images[0]
|
182 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
183 |
-
rv_path = f"
|
184 |
sd_image.save(rv_path,optimize=False,compress_level=0)
|
185 |
upload_to_ftp(rv_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
else:
|
187 |
-
print('--
|
188 |
-
sd_image = pipe(
|
189 |
-
prompt=prompt,
|
190 |
-
prompt_2=enhanced_prompt_2,
|
191 |
-
prompt_3=enhanced_prompt,
|
192 |
-
negative_prompt=negative_prompt_1,
|
193 |
-
negative_prompt_2=negative_prompt_2,
|
194 |
-
negative_prompt_3=negative_prompt_3,
|
195 |
-
guidance_scale=guidance_scale,
|
196 |
-
num_inference_steps=num_inference_steps,
|
197 |
-
width=width,
|
198 |
-
height=height,
|
199 |
-
generator=generator,
|
200 |
-
max_sequence_length=512
|
201 |
-
).images[0]
|
202 |
-
print('-- got image --')
|
203 |
-
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
204 |
-
sd35_path = f"sd35l_{timestamp}.png"
|
205 |
-
sd_image.save(sd35_path,optimize=False,compress_level=0)
|
206 |
-
upload_to_ftp(sd35_path)
|
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_{seed}.png"
|
213 |
-
downscale2.save(upscale_path,optimize=False,compress_level=0)
|
214 |
-
upload_to_ftp(upscale_path)
|
215 |
return sd_image, enhanced_prompt
|
216 |
|
217 |
examples = [
|
|
|
87 |
text_encoder=CLIPTextModelWithProjection.from_pretrained("ford442/stable-diffusion-3.5-large-bf16", subfolder='text_encoder', token=True).to(device=device, dtype=torch.bfloat16)
|
88 |
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)
|
89 |
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)
|
90 |
+
|
91 |
+
pipe.init_ipadapter(
|
92 |
+
ip_adapter_path=ipadapter_path,
|
93 |
+
image_encoder_path=image_encoder_path,
|
94 |
+
nb_token=64,
|
95 |
+
)
|
96 |
+
|
97 |
upscaler_2 = UpscaleWithModel.from_pretrained("Kim2091/ClearRealityV1").to(torch.device("cuda:0"))
|
98 |
|
99 |
MAX_SEED = np.iinfo(np.int32).max
|
|
|
157 |
sd_image_e.resize((height,width), Image.LANCZOS)
|
158 |
else:
|
159 |
sd_image_e = None
|
|
|
|
|
|
|
|
|
|
|
160 |
print('-- generating image --')
|
161 |
sd_image = pipe(
|
162 |
width=width,
|
|
|
181 |
scale_5=latent_file_5_scale,
|
182 |
).images[0]
|
183 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
184 |
+
rv_path = f"sd35IP_{timestamp}.png"
|
185 |
sd_image.save(rv_path,optimize=False,compress_level=0)
|
186 |
upload_to_ftp(rv_path)
|
187 |
+
upscaler_2.to(torch.device('cuda'))
|
188 |
+
with torch.no_grad():
|
189 |
+
upscale2 = upscaler_2(sd_image, tiling=True, tile_width=256, tile_height=256)
|
190 |
+
print('-- got upscaled image --')
|
191 |
+
downscale2 = upscale2.resize((upscale2.width // 4, upscale2.height // 4),Image.LANCZOS)
|
192 |
+
upscale_path = f"sd35l_upscale_{seed}.png"
|
193 |
+
downscale2.save(upscale_path,optimize=False,compress_level=0)
|
194 |
+
upload_to_ftp(upscale_path)
|
195 |
else:
|
196 |
+
print('-- at least one input image required --')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
return sd_image, enhanced_prompt
|
198 |
|
199 |
examples = [
|