Create app py
Browse files
app py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
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 login
|
8 |
+
import os
|
9 |
+
|
10 |
+
login(token=os.environ.get('HF_KEY'))
|
11 |
+
|
12 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
13 |
+
|
14 |
+
torch.cuda.max_memory_allocated(device=device)
|
15 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-0.9", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
16 |
+
pipe = pipe.to(device)
|
17 |
+
pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
|
18 |
+
pipe.enable_xformers_memory_efficient_attention()
|
19 |
+
torch.cuda.empty_cache()
|
20 |
+
|
21 |
+
refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-0.9", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
22 |
+
refiner = refiner.to(device)
|
23 |
+
refiner.unet = torch.compile(refiner.unet, mode="reduce-overhead", fullgraph=True)
|
24 |
+
refiner.enable_xformers_memory_efficient_attention()
|
25 |
+
torch.cuda.empty_cache()
|
26 |
+
|
27 |
+
def genie (prompt, negative_prompt, scale, steps, seed):
|
28 |
+
torch.cuda.empty_cache()
|
29 |
+
generator = torch.Generator(device=device).manual_seed(seed)
|
30 |
+
int_image = pipe(prompt, negative_prompt=negative_prompt, num_inference_steps=steps, guidance_scale=scale, num_images_per_prompt=1, generator=generator, width=768, height=768, output_type="latent").images
|
31 |
+
torch.cuda.empty_cache()
|
32 |
+
image = refiner(prompt=prompt, image=int_image).images[0]
|
33 |
+
return image
|
34 |
+
|
35 |
+
gr.Interface(fn=genie, inputs=[gr.Textbox(label='What you want the AI to generate. 77 Token Limit.'), gr.Textbox(label='What you Do Not want the AI to generate.'), gr.Slider(1, 15, 10), gr.Slider(25, maximum=50, value=25, step=1), gr.Slider(minimum=1, step=1, maximum=999999999999999999, randomize=True)], outputs='image', title="Stable Diffusion XL .9 CPU", description="SDXL .9 CPU. <b>WARNING:</b> Extremely Slow. 65s/Iteration. Expect 25-50mins an image for 25-50 iterations respectively.", article = "Code Monkey: <a href=\"https://huggingface.co/Manjushri\">Manjushri</a>").launch(debug=True, max_threads=80)
|