Spaces:
Runtime error
Runtime error
geekyrakshit
commited on
Commit
•
e5ab631
1
Parent(s):
b3692f8
add: sdxl app + dependencies
Browse files- app.py +118 -4
- requirements.txt +10 -0
app.py
CHANGED
@@ -1,7 +1,121 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
import torch
|
4 |
+
import numpy as np
|
5 |
+
import modin.pandas as pd
|
6 |
+
from PIL import Image
|
7 |
+
from diffusers import DiffusionPipeline
|
8 |
|
9 |
+
import wandb
|
10 |
+
from wandb_addons.diffusers import get_wandb_callback
|
11 |
+
|
12 |
+
|
13 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
14 |
+
pipeline = None
|
15 |
+
|
16 |
+
if torch.cuda.is_available():
|
17 |
+
torch.cuda.empty_cache()
|
18 |
+
|
19 |
+
pipeline = DiffusionPipeline.from_pretrained(
|
20 |
+
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
|
21 |
+
)
|
22 |
+
pipeline = pipeline.to("device")
|
23 |
+
pipeline.enable_xformers_memory_efficient_attention()
|
24 |
+
|
25 |
+
else:
|
26 |
+
pipeline = DiffusionPipeline.from_pretrained(
|
27 |
+
"stabilityai/stable-diffusion-xl-base-1.0", use_safetensors=True
|
28 |
+
)
|
29 |
+
pipeline = pipeline.to(device)
|
30 |
+
pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
|
31 |
+
|
32 |
+
|
33 |
+
def generate_image(
|
34 |
+
wandb_project,
|
35 |
+
wandb_entity,
|
36 |
+
wandb_api_key,
|
37 |
+
prompt,
|
38 |
+
negative_prompt,
|
39 |
+
height,
|
40 |
+
width,
|
41 |
+
num_inference_steps,
|
42 |
+
guidance_scale,
|
43 |
+
seed,
|
44 |
+
guidance_rescale,
|
45 |
+
):
|
46 |
+
wandb.login(key=wandb_api_key)
|
47 |
+
generator = torch.Generator(device="cuda").manual_seed(seed)
|
48 |
+
configs = {
|
49 |
+
"guidance_rescale": 0.0,
|
50 |
+
"seed": seed,
|
51 |
+
}
|
52 |
+
callback = get_wandb_callback(
|
53 |
+
pipeline,
|
54 |
+
prompt=prompt,
|
55 |
+
negative_prompt=negative_prompt,
|
56 |
+
wandb_project=wandb_project,
|
57 |
+
wandb_entity=wandb_entity,
|
58 |
+
configs=configs,
|
59 |
+
)
|
60 |
+
image = pipeline(
|
61 |
+
prompt,
|
62 |
+
negative_prompt=negative_prompt,
|
63 |
+
generator=generator,
|
64 |
+
height=height,
|
65 |
+
width=width,
|
66 |
+
callback=callback,
|
67 |
+
eta=configs["eta"],
|
68 |
+
guidance_rescale=configs["guidance_rescale"],
|
69 |
+
).images[0]
|
70 |
+
if torch.cuda.is_available():
|
71 |
+
torch.cuda.empty_cache()
|
72 |
+
return image
|
73 |
+
|
74 |
+
|
75 |
+
gr.Interface(
|
76 |
+
fn=generate_image,
|
77 |
+
inputs=[
|
78 |
+
gr.Textbox(label="Wandb Project Name", value="Stable-Diffusion-XL"),
|
79 |
+
gr.Textbox(label="Wandb Entity Name (Username/Team-name)"),
|
80 |
+
gr.Textbox(label="Wandb API Key", type="password"),
|
81 |
+
gr.Textbox(
|
82 |
+
label="Prompt",
|
83 |
+
lines=3,
|
84 |
+
value="a woman in orange, extremely detailed digital painting, in the style of Fenghua Zhong and Ruan Jia and jeremy lipking and Peter Mohrbacher, mystical colors, rim light, beautiful Lighting, 8k, stunning scene, raytracing, octane, trending on artstation",
|
85 |
+
),
|
86 |
+
gr.Textbox(
|
87 |
+
lablel="Negative Prompt",
|
88 |
+
lines=3,
|
89 |
+
value="blurry, plastic, grainy, duplicate, deformed , disfigured, poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limb, disconnected limb, mutated hands and fingers, text, name, signature, watermark, worst quality, jpeg artifacts, boring composition, uninteresting",
|
90 |
+
),
|
91 |
+
gr.Slider(minimum=512, maximum=1024, value=1024, step=128, label="Height"),
|
92 |
+
gr.Slider(minimum=512, maximum=1024, value=1024, step=128, label="Width"),
|
93 |
+
gr.Slider(
|
94 |
+
minimum=10,
|
95 |
+
maximum=100,
|
96 |
+
value=50,
|
97 |
+
step=128,
|
98 |
+
label="Number of Inference Steps",
|
99 |
+
),
|
100 |
+
gr.Slider(
|
101 |
+
minimum=1.0,
|
102 |
+
maximum=15.0,
|
103 |
+
value=5.0,
|
104 |
+
step=0.25,
|
105 |
+
label="Guidance Scale: How Closely the model follows the Prompt",
|
106 |
+
),
|
107 |
+
gr.Slider(
|
108 |
+
minimum=0, step=1, maximum=999999999999999999, randomize=True, label="Seed"
|
109 |
+
),
|
110 |
+
gr.Slider(
|
111 |
+
minimum=0.0,
|
112 |
+
maximum=1.0,
|
113 |
+
value=0.7,
|
114 |
+
step=0.1,
|
115 |
+
label="Guidance Rescale Factor",
|
116 |
+
),
|
117 |
+
],
|
118 |
+
outputs="image",
|
119 |
+
title="Reproducible Stable Diffusion XL",
|
120 |
+
description="Generate images using Stable Diffusion.",
|
121 |
+
)
|
requirements.txt
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
diffusers
|
3 |
+
accelerate
|
4 |
+
torch
|
5 |
+
ftfy
|
6 |
+
modin[all]
|
7 |
+
xformers
|
8 |
+
invisible_watermark
|
9 |
+
weave
|
10 |
+
wandb-addons @ git+https://github.com/soumik12345/wandb-addons.git@292f049937424a1a40b833c194e0edeb9bed446d
|