Spaces:
Runtime error
Runtime error
Commit
·
127aa22
0
Parent(s):
Duplicate from RamAnanth1/stable-diffusion-xl
Browse filesCo-authored-by: Ram Ananth <[email protected]>
- .gitattributes +34 -0
- README.md +13 -0
- app.py +276 -0
- requirements.txt +1 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Stable Diffusion XL
|
3 |
+
emoji: 🔥
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: red
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.11.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
duplicated_from: RamAnanth1/stable-diffusion-xl
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,276 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from stability_sdk import client
|
3 |
+
import stability_sdk.interfaces.gooseai.generation.generation_pb2 as generation
|
4 |
+
from PIL import Image
|
5 |
+
import io
|
6 |
+
import os
|
7 |
+
import warnings
|
8 |
+
|
9 |
+
|
10 |
+
# theme = gr.themes.Monochrome(
|
11 |
+
# primary_hue="indigo",
|
12 |
+
# secondary_hue="blue",
|
13 |
+
# neutral_hue="slate",
|
14 |
+
# radius_size=gr.themes.sizes.radius_sm,
|
15 |
+
# font=[gr.themes.GoogleFont("Open Sans"), "ui-sans-serif", "system-ui", "sans-serif"],
|
16 |
+
# )
|
17 |
+
|
18 |
+
def infer(prompt, api_key):
|
19 |
+
stability_api = client.StabilityInference(
|
20 |
+
key=api_key, # API Key reference.
|
21 |
+
verbose=True, # Print debug messages.
|
22 |
+
engine="stable-diffusion-xl-beta-v2-2-2", # Set the engine to use for generation.
|
23 |
+
# Available engines: stable-diffusion-v1 stable-diffusion-v1-5 stable-diffusion-512-v2-0 stable-diffusion-768-v2-0 stable-inpainting-v1-0 stable-inpainting-512-v2-0
|
24 |
+
)
|
25 |
+
answers = stability_api.generate(
|
26 |
+
prompt=prompt,
|
27 |
+
#seed=992446758, # If a seed is provided, the resulting generated image will be deterministic.
|
28 |
+
# What this means is that as long as all generation parameters remain the same, you can always recall the same image simply by generating it again.
|
29 |
+
# Note: This isn't quite the case for Clip Guided generations, which we'll tackle in a future example notebook.
|
30 |
+
steps=50, # Amount of inference steps performed on image generation. Defaults to 30.
|
31 |
+
cfg_scale=8.0, # Influences how strongly your generation is guided to match your prompt.
|
32 |
+
# Setting this value higher increases the strength in which it tries to match your prompt.
|
33 |
+
# Defaults to 7.0 if not specified.
|
34 |
+
width=512, # Generation width, defaults to 512 if not included.
|
35 |
+
height=512, # Generation height, defaults to 512 if not included.
|
36 |
+
samples=2, # Number of images to generate, defaults to 1 if not included.
|
37 |
+
sampler=generation.SAMPLER_K_DPMPP_2M # Choose which sampler we want to denoise our generation with.
|
38 |
+
# Defaults to k_dpmpp_2m if not specified. Clip Guidance only supports ancestral samplers.
|
39 |
+
# (Available Samplers: ddim, plms, k_euler, k_euler_ancestral, k_heun, k_dpm_2, k_dpm_2_ancestral, k_dpmpp_2s_ancestral, k_lms, k_dpmpp_2m)
|
40 |
+
)
|
41 |
+
results = []
|
42 |
+
for resp in answers:
|
43 |
+
for artifact in resp.artifacts:
|
44 |
+
if artifact.finish_reason == generation.FILTER:
|
45 |
+
warnings.warn(
|
46 |
+
"Your request activated the API's safety filters and could not be processed."
|
47 |
+
"Please modify the prompt and try again.")
|
48 |
+
if artifact.type == generation.ARTIFACT_IMAGE:
|
49 |
+
img = Image.open(io.BytesIO(artifact.binary))
|
50 |
+
results.append(img)
|
51 |
+
|
52 |
+
return results
|
53 |
+
|
54 |
+
css = """
|
55 |
+
.gradio-container {
|
56 |
+
font-family: 'IBM Plex Sans', sans-serif;
|
57 |
+
}
|
58 |
+
.gr-button {
|
59 |
+
color: white;
|
60 |
+
border-color: black;
|
61 |
+
background: black;
|
62 |
+
}
|
63 |
+
input[type='range'] {
|
64 |
+
accent-color: black;
|
65 |
+
}
|
66 |
+
.dark input[type='range'] {
|
67 |
+
accent-color: #dfdfdf;
|
68 |
+
}
|
69 |
+
.container {
|
70 |
+
max-width: 730px;
|
71 |
+
margin: auto;
|
72 |
+
padding-top: 1.5rem;
|
73 |
+
}
|
74 |
+
#gallery {
|
75 |
+
min-height: 22rem;
|
76 |
+
margin-bottom: 15px;
|
77 |
+
margin-left: auto;
|
78 |
+
margin-right: auto;
|
79 |
+
border-bottom-right-radius: .5rem !important;
|
80 |
+
border-bottom-left-radius: .5rem !important;
|
81 |
+
}
|
82 |
+
#gallery>div>.h-full {
|
83 |
+
min-height: 20rem;
|
84 |
+
}
|
85 |
+
.details:hover {
|
86 |
+
text-decoration: underline;
|
87 |
+
}
|
88 |
+
.gr-button {
|
89 |
+
white-space: nowrap;
|
90 |
+
}
|
91 |
+
.gr-button:focus {
|
92 |
+
border-color: rgb(147 197 253 / var(--tw-border-opacity));
|
93 |
+
outline: none;
|
94 |
+
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
|
95 |
+
--tw-border-opacity: 1;
|
96 |
+
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
|
97 |
+
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
|
98 |
+
--tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
|
99 |
+
--tw-ring-opacity: .5;
|
100 |
+
}
|
101 |
+
#advanced-btn {
|
102 |
+
font-size: .7rem !important;
|
103 |
+
line-height: 19px;
|
104 |
+
margin-top: 12px;
|
105 |
+
margin-bottom: 12px;
|
106 |
+
padding: 2px 8px;
|
107 |
+
border-radius: 14px !important;
|
108 |
+
}
|
109 |
+
#advanced-options {
|
110 |
+
display: none;
|
111 |
+
margin-bottom: 20px;
|
112 |
+
}
|
113 |
+
.footer {
|
114 |
+
margin-bottom: 45px;
|
115 |
+
margin-top: 35px;
|
116 |
+
text-align: center;
|
117 |
+
border-bottom: 1px solid #e5e5e5;
|
118 |
+
}
|
119 |
+
.footer>p {
|
120 |
+
font-size: .8rem;
|
121 |
+
display: inline-block;
|
122 |
+
padding: 0 10px;
|
123 |
+
transform: translateY(10px);
|
124 |
+
background: white;
|
125 |
+
}
|
126 |
+
.dark .footer {
|
127 |
+
border-color: #303030;
|
128 |
+
}
|
129 |
+
.dark .footer>p {
|
130 |
+
background: #0b0f19;
|
131 |
+
}
|
132 |
+
.acknowledgments h4{
|
133 |
+
margin: 1.25em 0 .25em 0;
|
134 |
+
font-weight: bold;
|
135 |
+
font-size: 115%;
|
136 |
+
}
|
137 |
+
.animate-spin {
|
138 |
+
animation: spin 1s linear infinite;
|
139 |
+
}
|
140 |
+
@keyframes spin {
|
141 |
+
from {
|
142 |
+
transform: rotate(0deg);
|
143 |
+
}
|
144 |
+
to {
|
145 |
+
transform: rotate(360deg);
|
146 |
+
}
|
147 |
+
}
|
148 |
+
#share-btn-container {
|
149 |
+
display: flex; padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; width: 13rem;
|
150 |
+
margin-top: 10px;
|
151 |
+
margin-left: auto;
|
152 |
+
}
|
153 |
+
#share-btn {
|
154 |
+
all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.25rem !important; padding-bottom: 0.25rem !important;right:0;
|
155 |
+
}
|
156 |
+
#share-btn * {
|
157 |
+
all: unset;
|
158 |
+
}
|
159 |
+
#share-btn-container div:nth-child(-n+2){
|
160 |
+
width: auto !important;
|
161 |
+
min-height: 0px !important;
|
162 |
+
}
|
163 |
+
#share-btn-container .wrap {
|
164 |
+
display: none !important;
|
165 |
+
}
|
166 |
+
|
167 |
+
.gr-form{
|
168 |
+
flex: 1 1 50%; border-top-right-radius: 0; border-bottom-right-radius: 0;
|
169 |
+
}
|
170 |
+
#prompt-container{
|
171 |
+
gap: 0;
|
172 |
+
}
|
173 |
+
#prompt-text-input, #negative-prompt-text-input{padding: .45rem 0.625rem}
|
174 |
+
#component-16{border-top-width: 1px!important;margin-top: 1em}
|
175 |
+
.image_duplication{position: absolute; width: 100px; left: 50px}
|
176 |
+
"""
|
177 |
+
|
178 |
+
with gr.Blocks(css = css) as demo:
|
179 |
+
gr.HTML(
|
180 |
+
"""
|
181 |
+
<div style="text-align: center; margin: 0 auto;">
|
182 |
+
<div
|
183 |
+
style="
|
184 |
+
display: inline-flex;
|
185 |
+
align-items: center;
|
186 |
+
gap: 0.8rem;
|
187 |
+
font-size: 1.75rem;
|
188 |
+
"
|
189 |
+
>
|
190 |
+
<svg
|
191 |
+
width="0.65em"
|
192 |
+
height="0.65em"
|
193 |
+
viewBox="0 0 115 115"
|
194 |
+
fill="none"
|
195 |
+
xmlns="http://www.w3.org/2000/svg"
|
196 |
+
>
|
197 |
+
<rect width="23" height="23" fill="white"></rect>
|
198 |
+
<rect y="69" width="23" height="23" fill="white"></rect>
|
199 |
+
<rect x="23" width="23" height="23" fill="#AEAEAE"></rect>
|
200 |
+
<rect x="23" y="69" width="23" height="23" fill="#AEAEAE"></rect>
|
201 |
+
<rect x="46" width="23" height="23" fill="white"></rect>
|
202 |
+
<rect x="46" y="69" width="23" height="23" fill="white"></rect>
|
203 |
+
<rect x="69" width="23" height="23" fill="black"></rect>
|
204 |
+
<rect x="69" y="69" width="23" height="23" fill="black"></rect>
|
205 |
+
<rect x="92" width="23" height="23" fill="#D9D9D9"></rect>
|
206 |
+
<rect x="92" y="69" width="23" height="23" fill="#AEAEAE"></rect>
|
207 |
+
<rect x="115" y="46" width="23" height="23" fill="white"></rect>
|
208 |
+
<rect x="115" y="115" width="23" height="23" fill="white"></rect>
|
209 |
+
<rect x="115" y="69" width="23" height="23" fill="#D9D9D9"></rect>
|
210 |
+
<rect x="92" y="46" width="23" height="23" fill="#AEAEAE"></rect>
|
211 |
+
<rect x="92" y="115" width="23" height="23" fill="#AEAEAE"></rect>
|
212 |
+
<rect x="92" y="69" width="23" height="23" fill="white"></rect>
|
213 |
+
<rect x="69" y="46" width="23" height="23" fill="white"></rect>
|
214 |
+
<rect x="69" y="115" width="23" height="23" fill="white"></rect>
|
215 |
+
<rect x="69" y="69" width="23" height="23" fill="#D9D9D9"></rect>
|
216 |
+
<rect x="46" y="46" width="23" height="23" fill="black"></rect>
|
217 |
+
<rect x="46" y="115" width="23" height="23" fill="black"></rect>
|
218 |
+
<rect x="46" y="69" width="23" height="23" fill="black"></rect>
|
219 |
+
<rect x="23" y="46" width="23" height="23" fill="#D9D9D9"></rect>
|
220 |
+
<rect x="23" y="115" width="23" height="23" fill="#AEAEAE"></rect>
|
221 |
+
<rect x="23" y="69" width="23" height="23" fill="black"></rect>
|
222 |
+
</svg>
|
223 |
+
<h1 style="font-weight: 900; margin-bottom: 7px;margin-top:5px">
|
224 |
+
Stable Diffusion XL Demo
|
225 |
+
</h1>
|
226 |
+
</div>
|
227 |
+
<p style="margin-bottom: 10px; font-size: 94%; line-height: 23px;">
|
228 |
+
This is an unoffical demo for Stable Diffusion XL, which is the latest stable diffusion model released by Stability AI. The main features include Next-level photorealism capabilities, image composition and face generation, use of shorter prompts to create descriptive imagery, greater capability to produce legible text and rich visuals and jaw-dropping aesthetics. Please refer to
|
229 |
+
<a
|
230 |
+
href="https://stability.ai/stable-diffusion"
|
231 |
+
style="text-decoration: underline;"
|
232 |
+
target="_blank"
|
233 |
+
>the official website</a
|
234 |
+
>.</a> for further information
|
235 |
+
</p>
|
236 |
+
</div>
|
237 |
+
"""
|
238 |
+
)
|
239 |
+
gr.HTML("<p>You can duplicate this Space to run it privately without a queue for shorter queue times : <a style='display:inline-block' href='https://huggingface.co/spaces/RamAnanth1/stable-diffusion-xl?duplicate=true'><img src='https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14' alt='Duplicate Space'></a> </p>")
|
240 |
+
|
241 |
+
api_key_input = gr.Textbox(type = "password", label = "Enter your StabilityAI API key here")
|
242 |
+
|
243 |
+
with gr.Row(elem_id="prompt-container").style(mobile_collapse=False, equal_height=True):
|
244 |
+
with gr.Column():
|
245 |
+
text = gr.Textbox(
|
246 |
+
label="Enter your prompt",
|
247 |
+
show_label=False,
|
248 |
+
max_lines=1,
|
249 |
+
placeholder="Enter your prompt",
|
250 |
+
elem_id="prompt-text-input",
|
251 |
+
).style(
|
252 |
+
border=(True, False, True, True),
|
253 |
+
rounded=(True, False, False, True),
|
254 |
+
container=False,
|
255 |
+
)
|
256 |
+
btn = gr.Button("Generate image").style(
|
257 |
+
margin=False,
|
258 |
+
rounded=(False, True, True, False),
|
259 |
+
full_width=False,
|
260 |
+
)
|
261 |
+
|
262 |
+
gallery = gr.Gallery(
|
263 |
+
label="Generated images", show_label=False, elem_id="gallery"
|
264 |
+
).style(grid=[2], height="auto")
|
265 |
+
|
266 |
+
btn.click(infer, inputs=[text, api_key_input], outputs=[gallery])
|
267 |
+
examples = [
|
268 |
+
["Vintage hot rod with custom flame paint job"],
|
269 |
+
["Ancient, mysterious temple in a mountain range, surrounded by misty clouds and tall peaks"],
|
270 |
+
["Glimpses of a herd of wild elephants crossing a savanna"],
|
271 |
+
["Beautiful waterfall in a lush jungle, with sunlight shining through the trees,"]
|
272 |
+
]
|
273 |
+
ex = gr.Examples(examples=examples,inputs=[text], cache_examples=False)
|
274 |
+
|
275 |
+
|
276 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
stability-sdk
|