Spaces:
Runtime error
Runtime error
Commit
·
2d52fac
1
Parent(s):
d6e73d2
update: app + readme
Browse files
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
colorFrom: blue
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
@@ -10,3 +10,5 @@ pinned: false
|
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
1 |
---
|
2 |
+
title: Reproducible Stable Diffusion XL
|
3 |
+
emoji: 🐝
|
4 |
colorFrom: blue
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
|
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
13 |
+
|
14 |
+
This space enables us to generate images using Stable Diffusion XL and track your experiments using Weights & Biases. In order to learn more able engineering better prompts for Stable Diffusion models and how to make your experiments reproducible using [Weights & Biases](https://wandb.ai/site), check out [this report](https://wandb.ai/geekyrakshit/diffusers-prompt-engineering/reports/A-Guide-to-Prompt-Engineering-for-Diffusion-Models--Vmlldzo1NzY4NzQ3). This app is powered by [🤗 Diffusers](https://huggingface.co/docs/diffusers) and [Weights & Biases](https://wandb.ai/site). A Weights & Biases API key is necessary to run this app, which you can find at **[https://wandb.ai/authorize](https://wandb.ai/authorize)**.
|
app.py
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
import os
|
|
|
2 |
|
3 |
import gradio as gr
|
4 |
|
5 |
import torch
|
6 |
from diffusers import DiffusionPipeline
|
7 |
|
|
|
8 |
from wandb_addons.diffusers import get_wandb_callback
|
9 |
|
10 |
|
@@ -35,7 +37,10 @@ def generate_image(
|
|
35 |
seed,
|
36 |
guidance_rescale,
|
37 |
):
|
38 |
-
|
|
|
|
|
|
|
39 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
40 |
configs = {
|
41 |
"guidance_scale": guidance_scale,
|
@@ -50,6 +55,7 @@ def generate_image(
|
|
50 |
num_inference_steps=num_inference_steps,
|
51 |
configs=configs,
|
52 |
)
|
|
|
53 |
image = pipeline(
|
54 |
prompt,
|
55 |
negative_prompt=negative_prompt,
|
@@ -62,14 +68,15 @@ def generate_image(
|
|
62 |
).images[0]
|
63 |
if torch.cuda.is_available():
|
64 |
torch.cuda.empty_cache()
|
65 |
-
|
|
|
66 |
|
67 |
|
68 |
gr.Interface(
|
69 |
fn=generate_image,
|
70 |
inputs=[
|
71 |
gr.Textbox(label="WandB Project Name", value="Stable-Diffusion-XL"),
|
72 |
-
gr.Textbox(label="WandB API Key", type="password"),
|
73 |
gr.Textbox(
|
74 |
label="Prompt",
|
75 |
lines=3,
|
@@ -107,7 +114,84 @@ gr.Interface(
|
|
107 |
label="Guidance Rescale Factor",
|
108 |
),
|
109 |
],
|
110 |
-
outputs="image",
|
111 |
-
title="Reproducible Stable Diffusion
|
112 |
-
description="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
).launch(debug=True, max_threads=80)
|
|
|
1 |
import os
|
2 |
+
import shutil
|
3 |
|
4 |
import gradio as gr
|
5 |
|
6 |
import torch
|
7 |
from diffusers import DiffusionPipeline
|
8 |
|
9 |
+
import wandb
|
10 |
from wandb_addons.diffusers import get_wandb_callback
|
11 |
|
12 |
|
|
|
37 |
seed,
|
38 |
guidance_rescale,
|
39 |
):
|
40 |
+
if wandb_api_key is None or wandb_api_key == "":
|
41 |
+
raise gr.Error("A WandB API key is required to run this app! You can get one from https://wandb.ai/authorize")
|
42 |
+
else:
|
43 |
+
os.environ["WANDB_API_KEY"] = wandb_api_key
|
44 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
45 |
configs = {
|
46 |
"guidance_scale": guidance_scale,
|
|
|
55 |
num_inference_steps=num_inference_steps,
|
56 |
configs=configs,
|
57 |
)
|
58 |
+
run_url = wandb.run.get_url()
|
59 |
image = pipeline(
|
60 |
prompt,
|
61 |
negative_prompt=negative_prompt,
|
|
|
68 |
).images[0]
|
69 |
if torch.cuda.is_available():
|
70 |
torch.cuda.empty_cache()
|
71 |
+
shutil.rmtree("wandb")
|
72 |
+
return image, f"**WandB Run:** [{run_url}]({run_url})"
|
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 API Key (You can get one from https://wandb.ai/authorize)", type="password", value=None),
|
80 |
gr.Textbox(
|
81 |
label="Prompt",
|
82 |
lines=3,
|
|
|
114 |
label="Guidance Rescale Factor",
|
115 |
),
|
116 |
],
|
117 |
+
outputs=["image", "markdown"],
|
118 |
+
title="Reproducible Stable Diffusion-XL with WandB",
|
119 |
+
description="""
|
120 |
+
This space enables us to generate images using Stable Diffusion XL and track your experiments using Weights & Biases. In order to learn more able engineering better prompts for Stable Diffusion models and how to make your experiments reproducible using [Weights & Biases](https://wandb.ai/site), check out [this report](https://wandb.ai/geekyrakshit/diffusers-prompt-engineering/reports/A-Guide-to-Prompt-Engineering-for-Diffusion-Models--Vmlldzo1NzY4NzQ3).
|
121 |
+
This app is powered by [🤗 Diffusers](https://huggingface.co/docs/diffusers) and [Weights & Biases](https://wandb.ai/site). A **Weights & Biases API key is necessary** to run this app, which you can find at **[https://wandb.ai/authorize](https://wandb.ai/authorize)**.
|
122 |
+
""",
|
123 |
+
examples=[
|
124 |
+
[
|
125 |
+
"Stable-Diffusion-XL",
|
126 |
+
None,
|
127 |
+
"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",
|
128 |
+
"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",
|
129 |
+
1024,
|
130 |
+
1024,
|
131 |
+
50,
|
132 |
+
5.0,
|
133 |
+
256174057,
|
134 |
+
0.0,
|
135 |
+
],
|
136 |
+
[
|
137 |
+
"Stable-Diffusion-XL",
|
138 |
+
None,
|
139 |
+
"hyper realistic photograph, Kodak disposable photography of young queen sit on her throne, blonde hair, red lips, white skin, 8k",
|
140 |
+
None,
|
141 |
+
1024,
|
142 |
+
1024,
|
143 |
+
50,
|
144 |
+
5.0,
|
145 |
+
189708808,
|
146 |
+
0.0,
|
147 |
+
],
|
148 |
+
[
|
149 |
+
"Stable-Diffusion-XL",
|
150 |
+
None,
|
151 |
+
"hyper realistic waist up portrait of a teen boy with messy dark blond hair, light brown eyes, smiling, dimples, textured skin, realistic features, imperfect skin, 85mm lens Sony Lens, bokeh, sharp focus, professional photography, warm lighting, soft lights, realistic sharp eyes, sharp focus, set a busy street in the evening as background",
|
152 |
+
None,
|
153 |
+
1024,
|
154 |
+
1024,
|
155 |
+
50,
|
156 |
+
5.0,
|
157 |
+
267243010,
|
158 |
+
0.0,
|
159 |
+
],
|
160 |
+
[
|
161 |
+
"Stable-Diffusion-XL",
|
162 |
+
None,
|
163 |
+
"A Cinematic Film Still Food Photography of a Cocktail, shot on fujifilm xt4, Professional Advertisement Photography, Dynamic Effects, Foaming Gas, Epic, Beautiful Details, Mysterious micro effects, Highly Detailed",
|
164 |
+
None,
|
165 |
+
1024,
|
166 |
+
1024,
|
167 |
+
50,
|
168 |
+
5.0,
|
169 |
+
1073711987,
|
170 |
+
0.0,
|
171 |
+
],
|
172 |
+
[
|
173 |
+
"Stable-Diffusion-XL",
|
174 |
+
None,
|
175 |
+
"hyper realistic photograph, photography of a children dressed like a gangster, 50 mm, film grain, Kodak portra 800",
|
176 |
+
None,
|
177 |
+
1024,
|
178 |
+
1024,
|
179 |
+
50,
|
180 |
+
5.0,
|
181 |
+
355517910,
|
182 |
+
0.0,
|
183 |
+
],
|
184 |
+
[
|
185 |
+
"Stable-Diffusion-XL",
|
186 |
+
None,
|
187 |
+
"a girl as personification of chocolate cupcake",
|
188 |
+
"deformed, disfigured, poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limb, disconnected limb, mutated hands and fingers, blurry",
|
189 |
+
1024,
|
190 |
+
1024,
|
191 |
+
50,
|
192 |
+
5.0,
|
193 |
+
595687707,
|
194 |
+
0.0,
|
195 |
+
],
|
196 |
+
],
|
197 |
).launch(debug=True, max_threads=80)
|