Spaces:
Running
on
T4
Running
on
T4
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,15 +10,22 @@ device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
|
| 10 |
pipe = DiffusionPipeline.from_pretrained("circulus/canvers-real-v3.8.1", torch_dtype=torch.float16, safety_checker=None) if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("circulus/canvers-real-v3.8.1")
|
| 11 |
pipe = pipe.to(device)
|
| 12 |
pipe.enable_xformers_memory_efficient_attention()
|
|
|
|
|
|
|
| 13 |
anime = DiffusionPipeline.from_pretrained("circulus/canvers-anime-v3.8.1", torch_dtype=torch.float16, safety_checker=None) if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("circulus/canvers-anime-v3.8.1")
|
| 14 |
anime = anime.to(device)
|
| 15 |
anime.enable_xformers_memory_efficient_attention()
|
|
|
|
|
|
|
| 16 |
disney = DiffusionPipeline.from_pretrained("circulus/canvers-disney-v3.8.1", torch_dtype=torch.float16, safety_checker=None) if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("circulus/canvers-disney-v3.8.1")
|
| 17 |
disney = disney.to(device)
|
| 18 |
disney.enable_xformers_memory_efficient_attention()
|
|
|
|
|
|
|
| 19 |
refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", use_safetensors=True, torch_dtype=torch.float16, variant="fp16") if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0")
|
| 20 |
refiner.enable_xformers_memory_efficient_attention()
|
| 21 |
refiner = refiner.to(device)
|
|
|
|
| 22 |
|
| 23 |
def genie (Model, Prompt, negative_prompt, height, width, scale, steps, seed, upscale, high_noise_frac):
|
| 24 |
generator = np.random.seed(0) if seed == 0 else torch.manual_seed(seed)
|
|
@@ -26,27 +33,32 @@ def genie (Model, Prompt, negative_prompt, height, width, scale, steps, seed, up
|
|
| 26 |
if upscale == "Yes":
|
| 27 |
int_image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images
|
| 28 |
image = refiner(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
|
|
|
|
| 29 |
return image
|
| 30 |
else:
|
| 31 |
image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
|
|
|
|
| 32 |
return image
|
| 33 |
|
| 34 |
if Model == "Anime":
|
| 35 |
if upscale == "Yes":
|
| 36 |
int_image = anime(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images
|
| 37 |
image = refiner(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
|
|
|
|
| 38 |
return image
|
| 39 |
else:
|
| 40 |
image = anime(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
|
|
|
|
| 41 |
return image
|
| 42 |
else:
|
| 43 |
if upscale == "Yes":
|
| 44 |
int_image = disney(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images
|
| 45 |
image = refiner(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
|
|
|
|
| 46 |
return image
|
| 47 |
else:
|
| 48 |
image = disney(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
|
| 49 |
-
|
| 50 |
return image
|
| 51 |
|
| 52 |
gr.Interface(fn=genie, inputs=[gr.Radio(['Real', 'Anime', 'Disney'], value='Real', label='Choose Canvers Model'),
|
|
|
|
| 10 |
pipe = DiffusionPipeline.from_pretrained("circulus/canvers-real-v3.8.1", torch_dtype=torch.float16, safety_checker=None) if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("circulus/canvers-real-v3.8.1")
|
| 11 |
pipe = pipe.to(device)
|
| 12 |
pipe.enable_xformers_memory_efficient_attention()
|
| 13 |
+
torch.cuda.empty_cache()
|
| 14 |
+
|
| 15 |
anime = DiffusionPipeline.from_pretrained("circulus/canvers-anime-v3.8.1", torch_dtype=torch.float16, safety_checker=None) if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("circulus/canvers-anime-v3.8.1")
|
| 16 |
anime = anime.to(device)
|
| 17 |
anime.enable_xformers_memory_efficient_attention()
|
| 18 |
+
torch.cuda.empty_cache()
|
| 19 |
+
|
| 20 |
disney = DiffusionPipeline.from_pretrained("circulus/canvers-disney-v3.8.1", torch_dtype=torch.float16, safety_checker=None) if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("circulus/canvers-disney-v3.8.1")
|
| 21 |
disney = disney.to(device)
|
| 22 |
disney.enable_xformers_memory_efficient_attention()
|
| 23 |
+
torch.cuda.empty_cache()
|
| 24 |
+
|
| 25 |
refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", use_safetensors=True, torch_dtype=torch.float16, variant="fp16") if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0")
|
| 26 |
refiner.enable_xformers_memory_efficient_attention()
|
| 27 |
refiner = refiner.to(device)
|
| 28 |
+
torch.cuda.empty_cache()
|
| 29 |
|
| 30 |
def genie (Model, Prompt, negative_prompt, height, width, scale, steps, seed, upscale, high_noise_frac):
|
| 31 |
generator = np.random.seed(0) if seed == 0 else torch.manual_seed(seed)
|
|
|
|
| 33 |
if upscale == "Yes":
|
| 34 |
int_image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images
|
| 35 |
image = refiner(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
|
| 36 |
+
torch.cuda.empty_cache()
|
| 37 |
return image
|
| 38 |
else:
|
| 39 |
image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
|
| 40 |
+
torch.cuda.empty_cache()
|
| 41 |
return image
|
| 42 |
|
| 43 |
if Model == "Anime":
|
| 44 |
if upscale == "Yes":
|
| 45 |
int_image = anime(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images
|
| 46 |
image = refiner(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
|
| 47 |
+
torch.cuda.empty_cache()
|
| 48 |
return image
|
| 49 |
else:
|
| 50 |
image = anime(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
|
| 51 |
+
torch.cuda.empty_cache()
|
| 52 |
return image
|
| 53 |
else:
|
| 54 |
if upscale == "Yes":
|
| 55 |
int_image = disney(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images
|
| 56 |
image = refiner(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
|
| 57 |
+
torch.cuda.empty_cache()
|
| 58 |
return image
|
| 59 |
else:
|
| 60 |
image = disney(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
|
| 61 |
+
torch.cuda.empty_cache()
|
| 62 |
return image
|
| 63 |
|
| 64 |
gr.Interface(fn=genie, inputs=[gr.Radio(['Real', 'Anime', 'Disney'], value='Real', label='Choose Canvers Model'),
|