Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -61,7 +61,7 @@ checkpoint = "microsoft/Phi-3.5-mini-instruct"
|
|
61 |
vae = AutoencoderKL.from_pretrained("ford442/sdxl-vae-bf16")
|
62 |
#vae = AutoencoderKL.from_pretrained("ford442/sdxl-vae-bf16")
|
63 |
|
64 |
-
pipe = StableDiffusion3Pipeline.from_pretrained("ford442/stable-diffusion-3.5-medium-bf16").to(
|
65 |
#pipe = StableDiffusion3Pipeline.from_pretrained("ford442/stable-diffusion-3.5-medium-bf16").to(torch.device("cuda:0"))
|
66 |
#pipe = StableDiffusion3Pipeline.from_pretrained("ford442/RealVis_Medium_1.0b_bf16", torch_dtype=torch.bfloat16)
|
67 |
#pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3.5-medium", token=hftoken, torch_dtype=torch.float32, device_map='balanced')
|
@@ -75,7 +75,7 @@ pipe = StableDiffusion3Pipeline.from_pretrained("ford442/stable-diffusion-3.5-me
|
|
75 |
#pipe = torch.compile(pipe)
|
76 |
# pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config, beta_schedule="scaled_linear")
|
77 |
|
78 |
-
refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained("ford442/stable-diffusion-xl-refiner-1.0-bf16", vae=AutoencoderKL.from_pretrained("ford442/sdxl-vae-bf16"), requires_aesthetics_score=True).to(
|
79 |
#refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", vae=vae, torch_dtype=torch.float32, requires_aesthetics_score=True, device_map='balanced')
|
80 |
refiner.scheduler=EulerAncestralDiscreteScheduler.from_config(refiner.scheduler.config)
|
81 |
#refiner.enable_model_cpu_offload()
|
@@ -131,6 +131,8 @@ def infer(
|
|
131 |
latent_file, # Add latents file input
|
132 |
progress=gr.Progress(track_tqdm=True),
|
133 |
):
|
|
|
|
|
134 |
torch.set_float32_matmul_precision("highest")
|
135 |
seed = random.randint(0, MAX_SEED)
|
136 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
@@ -254,6 +256,8 @@ def infer(
|
|
254 |
#torch.save(generated_latents, latent_path)
|
255 |
#upload_to_ftp(latent_path)
|
256 |
#refiner.scheduler.set_timesteps(num_inference_steps,device)
|
|
|
|
|
257 |
refine = refiner(
|
258 |
prompt=f"{enhanced_prompt_2}, high quality masterpiece, complex details",
|
259 |
negative_prompt = negative_prompt,
|
@@ -265,9 +269,12 @@ def infer(
|
|
265 |
refine_path = f"sd35_refine_{seed}.png"
|
266 |
refine.save(refine_path,optimize=False,compress_level=0)
|
267 |
upload_to_ftp(refine_path)
|
|
|
|
|
268 |
with torch.no_grad():
|
269 |
upscale2 = upscaler_2(refine, tiling=True, tile_width=256, tile_height=256)
|
270 |
print('-- got upscaled image --')
|
|
|
271 |
downscale2 = upscale2.resize((upscale2.width // 4, upscale2.height // 4),Image.LANCZOS)
|
272 |
upscale_path = f"sd35_upscale_{seed}.png"
|
273 |
downscale2.save(upscale_path,optimize=False,compress_level=0)
|
|
|
61 |
vae = AutoencoderKL.from_pretrained("ford442/sdxl-vae-bf16")
|
62 |
#vae = AutoencoderKL.from_pretrained("ford442/sdxl-vae-bf16")
|
63 |
|
64 |
+
pipe = StableDiffusion3Pipeline.from_pretrained("ford442/stable-diffusion-3.5-medium-bf16").to(torch.bfloat16)
|
65 |
#pipe = StableDiffusion3Pipeline.from_pretrained("ford442/stable-diffusion-3.5-medium-bf16").to(torch.device("cuda:0"))
|
66 |
#pipe = StableDiffusion3Pipeline.from_pretrained("ford442/RealVis_Medium_1.0b_bf16", torch_dtype=torch.bfloat16)
|
67 |
#pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3.5-medium", token=hftoken, torch_dtype=torch.float32, device_map='balanced')
|
|
|
75 |
#pipe = torch.compile(pipe)
|
76 |
# pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config, beta_schedule="scaled_linear")
|
77 |
|
78 |
+
refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained("ford442/stable-diffusion-xl-refiner-1.0-bf16", vae=AutoencoderKL.from_pretrained("ford442/sdxl-vae-bf16"), requires_aesthetics_score=True).to(torch.bfloat16)
|
79 |
#refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", vae=vae, torch_dtype=torch.float32, requires_aesthetics_score=True, device_map='balanced')
|
80 |
refiner.scheduler=EulerAncestralDiscreteScheduler.from_config(refiner.scheduler.config)
|
81 |
#refiner.enable_model_cpu_offload()
|
|
|
131 |
latent_file, # Add latents file input
|
132 |
progress=gr.Progress(track_tqdm=True),
|
133 |
):
|
134 |
+
upscaler_2.to(torch.device('cpu'))
|
135 |
+
pipe.to(torch.device('cuda'))
|
136 |
torch.set_float32_matmul_precision("highest")
|
137 |
seed = random.randint(0, MAX_SEED)
|
138 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
|
|
256 |
#torch.save(generated_latents, latent_path)
|
257 |
#upload_to_ftp(latent_path)
|
258 |
#refiner.scheduler.set_timesteps(num_inference_steps,device)
|
259 |
+
pipe.to(torch.device('cpu'))
|
260 |
+
refiner.to(torch.device('cuda'))
|
261 |
refine = refiner(
|
262 |
prompt=f"{enhanced_prompt_2}, high quality masterpiece, complex details",
|
263 |
negative_prompt = negative_prompt,
|
|
|
269 |
refine_path = f"sd35_refine_{seed}.png"
|
270 |
refine.save(refine_path,optimize=False,compress_level=0)
|
271 |
upload_to_ftp(refine_path)
|
272 |
+
refiner.to(torch.device('cpu'))
|
273 |
+
upscaler_2.to(torch.device('cuda'))
|
274 |
with torch.no_grad():
|
275 |
upscale2 = upscaler_2(refine, tiling=True, tile_width=256, tile_height=256)
|
276 |
print('-- got upscaled image --')
|
277 |
+
upscaler_2.to(torch.device('cpu'))
|
278 |
downscale2 = upscale2.resize((upscale2.width // 4, upscale2.height // 4),Image.LANCZOS)
|
279 |
upscale_path = f"sd35_upscale_{seed}.png"
|
280 |
downscale2.save(upscale_path,optimize=False,compress_level=0)
|