Spaces:
Running
on
T4
Running
on
T4
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,49 +3,40 @@ import torch
|
|
| 3 |
import numpy as np
|
| 4 |
import modin.pandas as pd
|
| 5 |
from PIL import Image
|
| 6 |
-
from diffusers import DiffusionPipeline
|
| 7 |
from huggingface_hub import hf_hub_download
|
| 8 |
|
| 9 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 10 |
torch.cuda.max_memory_allocated(device=device)
|
| 11 |
torch.cuda.empty_cache()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
def genie (
|
| 14 |
generator = np.random.seed(0) if seed == 0 else torch.manual_seed(seed)
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
pipe = pipe.to(device)
|
| 20 |
-
torch.cuda.empty_cache()
|
| 21 |
-
|
| 22 |
-
image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
|
| 23 |
-
torch.cuda.empty_cache()
|
| 24 |
-
return image
|
| 25 |
-
|
| 26 |
-
if Model == "Animagine XL 4":
|
| 27 |
-
animagine = DiffusionPipeline.from_pretrained("cagliostrolab/animagine-xl-4.0", torch_dtype=torch.float16, safety_checker=None) if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("cagliostrolab/animagine-xl-4.0")
|
| 28 |
-
animagine.enable_xformers_memory_efficient_attention()
|
| 29 |
-
animagine = animagine.to(device)
|
| 30 |
-
torch.cuda.empty_cache()
|
| 31 |
|
| 32 |
-
image = animagine(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
|
| 33 |
-
torch.cuda.empty_cache()
|
| 34 |
-
return image
|
| 35 |
-
|
| 36 |
-
|
| 37 |
return image
|
| 38 |
|
| 39 |
-
gr.Interface(fn=genie, inputs=[gr.
|
| 40 |
-
gr.Textbox(label='What you want the AI to generate. 77 Token Limit.'),
|
| 41 |
gr.Textbox(label='What you Do Not want the AI to generate. 77 Token Limit'),
|
| 42 |
-
gr.Slider(512,
|
| 43 |
-
gr.Slider(512,
|
| 44 |
-
gr.Slider(
|
| 45 |
-
gr.Slider(
|
| 46 |
-
gr.Slider(minimum=0, step=1, maximum=9999999999999999, randomize=True, label='Seed: 0 is Random'),
|
| 47 |
-
],
|
| 48 |
outputs=gr.Image(label='Generated Image'),
|
| 49 |
-
title="Manju Dream Booth V2.5 - GPU",
|
| 50 |
description="<br><br><b/>Warning: This Demo is capable of producing NSFW content.",
|
| 51 |
-
article = "If You Enjoyed this Demo and would like to Donate, you can send any amount to any of these Wallets. <br><br>SHIB (BEP20): 0xbE8f2f3B71DFEB84E5F7E3aae1909d60658aB891 <br>PayPal: https://www.paypal.me/ManjushriBodhisattva <br>ETH: 0xbE8f2f3B71DFEB84E5F7E3aae1909d60658aB891 <br>DOGE:
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
import modin.pandas as pd
|
| 5 |
from PIL import Image
|
| 6 |
+
from diffusers import DiffusionPipeline, StableDiffusion3Pipeline
|
| 7 |
from huggingface_hub import hf_hub_download
|
| 8 |
|
| 9 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 10 |
torch.cuda.max_memory_allocated(device=device)
|
| 11 |
torch.cuda.empty_cache()
|
| 12 |
+
#torch.cuda.max_memory_allocated(device=device)
|
| 13 |
+
pipe = DiffusionPipeline.from_pretrained("circulus/canvers-fusionXL-v1", torch_dtype=torch.float16).to(device)
|
| 14 |
+
pipe.enable_xformers_memory_efficient_attention()
|
| 15 |
+
torch.cuda.empty_cache()
|
| 16 |
+
|
| 17 |
+
#torch.cuda.max_memory_allocated(device=device)
|
| 18 |
+
refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", use_safetensors=True, torch_dtype=torch.float16, variant="fp16").to(device)
|
| 19 |
+
refiner.enable_xformers_memory_efficient_attention()
|
| 20 |
+
torch.cuda.empty_cache()
|
| 21 |
+
|
| 22 |
|
| 23 |
+
def genie (Prompt, negative_prompt, height, width, scale, steps, seed):
|
| 24 |
generator = np.random.seed(0) if seed == 0 else torch.manual_seed(seed)
|
| 25 |
+
#generator=np.random.seed(0)
|
| 26 |
+
int_image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale, output_type="latent").images
|
| 27 |
+
image = refiner(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=.99).images[0]
|
| 28 |
+
torch.cuda.empty_cache()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
return image
|
| 31 |
|
| 32 |
+
gr.Interface(fn=genie, inputs=[gr.Textbox(label='What you want the AI to generate. 77 Token Limit.'),
|
|
|
|
| 33 |
gr.Textbox(label='What you Do Not want the AI to generate. 77 Token Limit'),
|
| 34 |
+
gr.Slider(512, 1536, 1024, step=128, label='Height'),
|
| 35 |
+
gr.Slider(512, 1536, 1024, step=128, label='Width'),
|
| 36 |
+
gr.Slider(.5, maximum=15, value=7, step=.25, label='Guidance Scale'),
|
| 37 |
+
gr.Slider(10, maximum=50, value=25, step=5, label='Number of Prior Iterations'),
|
| 38 |
+
gr.Slider(minimum=0, step=1, maximum=9999999999999999, randomize=True, label='Seed: 0 is Random')],
|
|
|
|
| 39 |
outputs=gr.Image(label='Generated Image'),
|
| 40 |
+
title="Manju Dream Booth V2.5 with Fusion XL - GPU",
|
| 41 |
description="<br><br><b/>Warning: This Demo is capable of producing NSFW content.",
|
| 42 |
+
article = "If You Enjoyed this Demo and would like to Donate, you can send any amount to any of these Wallets. <br><br>SHIB (BEP20): 0xbE8f2f3B71DFEB84E5F7E3aae1909d60658aB891 <br>PayPal: https://www.paypal.me/ManjushriBodhisattva <br>ETH: 0xbE8f2f3B71DFEB84E5F7E3aae1909d60658aB891 <br>DOGE: D9QdVPtcU1EFH8jDC8jhU9uBcSTqUiA8h6<br><br>Code Monkey: <a href=\"https://huggingface.co/Manjushri\">Manjushri</a>").launch(debug=True)
|