Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,37 +3,50 @@ import torch
|
|
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 |
-
# Open it for reduce GPU memory usage
|
16 |
-
#pipe.enable_model_cpu_offload()
|
17 |
-
pipe.vae.enable_slicing()
|
18 |
-
pipe.vae.enable_tiling()
|
19 |
-
torch.cuda.empty_cache()
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
torch.cuda.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
33 |
|
34 |
return image
|
35 |
|
36 |
-
gr.Interface(fn=genie, inputs=[gr.
|
|
|
37 |
gr.Textbox(label='What you Do Not want the AI to generate. 77 Token Limit'),
|
38 |
gr.Slider(512, 1536, 1024, step=128, label='Height'),
|
39 |
gr.Slider(512, 1536, 1024, step=128, label='Width'),
|
@@ -41,6 +54,6 @@ gr.Interface(fn=genie, inputs=[gr.Textbox(label='What you want the AI to generat
|
|
41 |
gr.Slider(10, maximum=50, value=25, step=5, label='Number of Prior Iterations'),
|
42 |
gr.Slider(minimum=0, step=1, maximum=9999999999999999, randomize=True, label='Seed: 0 is Random')],
|
43 |
outputs=gr.Image(label='Generated Image'),
|
44 |
-
title="Manju Dream Booth V2.
|
45 |
description="<br><br><b/>Warning: This Demo is capable of producing NSFW content.",
|
46 |
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)
|
|
|
3 |
import numpy as np
|
4 |
import modin.pandas as pd
|
5 |
from PIL import Image
|
6 |
+
from diffusers import DiffusionPipeline, QwenImagePipeline #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 |
|
13 |
+
def genie (Model, Prompt, negative_prompt, height, width, scale, steps, seed):
|
14 |
+
generator = np.random.seed(0) if seed == 0 else torch.manual_seed(seed)
|
15 |
+
if Model == "SD3":
|
16 |
+
#torch.cuda.max_memory_allocated(device=device)
|
17 |
+
torch.cuda.empty_cache()
|
18 |
+
SD3 = QwenImagePipeline.from_pretrained("Qwen/Qwen-Image", torch_dtype=torch.bfloat16).to(device)
|
19 |
+
torch.cuda.empty_cache()
|
20 |
+
image=SD3(
|
21 |
+
prompt=Prompt,
|
22 |
+
height=height,
|
23 |
+
width=width,
|
24 |
+
negative_prompt=negative_prompt,
|
25 |
+
guidance_scale=scale,
|
26 |
+
num_images_per_prompt=1,
|
27 |
+
num_inference_steps=steps).images[0]
|
28 |
+
if Model == "FXL":
|
29 |
|
30 |
+
torch.cuda.empty_cache()
|
31 |
+
#torch.cuda.max_memory_allocated(device=device)
|
32 |
+
pipe = DiffusionPipeline.from_pretrained("circulus/canvers-fusionXL-v1", torch_dtype=torch.float16)
|
33 |
+
pipe.enable_xformers_memory_efficient_attention()
|
34 |
+
pipe = pipe.to(device)
|
35 |
+
torch.cuda.empty_cache()
|
36 |
|
37 |
+
#torch.cuda.max_memory_allocated(device=device)
|
38 |
+
int_image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale, output_type="latent").images
|
39 |
+
pipe = 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")
|
40 |
+
pipe.enable_xformers_memory_efficient_attention()
|
41 |
+
pipe = pipe.to(device)
|
42 |
+
torch.cuda.empty_cache()
|
43 |
+
image = pipe(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=.99).images[0]
|
44 |
+
torch.cuda.empty_cache()
|
45 |
|
46 |
return image
|
47 |
|
48 |
+
gr.Interface(fn=genie, inputs=[gr.Radio(["SD3", "FXL"], value='SD3', label='Choose Model'),
|
49 |
+
gr.Textbox(label='What you want the AI to generate. 77 Token Limit.'),
|
50 |
gr.Textbox(label='What you Do Not want the AI to generate. 77 Token Limit'),
|
51 |
gr.Slider(512, 1536, 1024, step=128, label='Height'),
|
52 |
gr.Slider(512, 1536, 1024, step=128, label='Width'),
|
|
|
54 |
gr.Slider(10, maximum=50, value=25, step=5, label='Number of Prior Iterations'),
|
55 |
gr.Slider(minimum=0, step=1, maximum=9999999999999999, randomize=True, label='Seed: 0 is Random')],
|
56 |
outputs=gr.Image(label='Generated Image'),
|
57 |
+
title="Manju Dream Booth V2.4 with Stable Diffusion 3 & Fusion XL - GPU",
|
58 |
description="<br><br><b/>Warning: This Demo is capable of producing NSFW content.",
|
59 |
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)
|