Spaces:
Runtime error
Runtime error
apolinario
commited on
Commit
•
0a27246
1
Parent(s):
853b5ac
2x2 Grid and minor improvements
Browse files- app.py +32 -25
- requirements.txt +1 -0
app.py
CHANGED
@@ -18,7 +18,7 @@ word_list = word_list_dataset["train"]['text']
|
|
18 |
def infer(prompt, samples, steps, scale, seed):
|
19 |
for filter in word_list:
|
20 |
if re.search(rf"\b{filter}\b", prompt):
|
21 |
-
raise
|
22 |
|
23 |
generator = torch.Generator(device=device).manual_seed(seed)
|
24 |
with autocast("cuda"):
|
@@ -36,8 +36,7 @@ def infer(prompt, samples, steps, scale, seed):
|
|
36 |
else:
|
37 |
images.append(image)
|
38 |
return images
|
39 |
-
|
40 |
-
|
41 |
css = """
|
42 |
.gradio-container {
|
43 |
font-family: 'IBM Plex Sans', sans-serif;
|
@@ -54,13 +53,21 @@ css = """
|
|
54 |
accent-color: #dfdfdf;
|
55 |
}
|
56 |
.container {
|
57 |
-
max-width:
|
58 |
margin: auto;
|
59 |
-
padding-top:
|
|
|
|
|
|
|
|
|
|
|
60 |
}
|
61 |
#gallery {
|
|
|
62 |
min-height: 22rem;
|
63 |
margin-bottom: 15px;
|
|
|
|
|
64 |
border-bottom-right-radius: .5rem !important;
|
65 |
border-bottom-left-radius: .5rem !important;
|
66 |
}
|
@@ -86,7 +93,7 @@ css = """
|
|
86 |
#advanced-btn {
|
87 |
font-size: .7rem !important;
|
88 |
line-height: 19px;
|
89 |
-
margin-top:
|
90 |
margin-bottom: 12px;
|
91 |
padding: 2px 8px;
|
92 |
border-radius: 14px !important;
|
@@ -126,36 +133,36 @@ block = gr.Blocks(css=css)
|
|
126 |
examples = [
|
127 |
[
|
128 |
'A high tech solarpunk utopia in the Amazon rainforest',
|
129 |
-
|
130 |
-
|
131 |
7.5,
|
132 |
1024,
|
133 |
],
|
134 |
[
|
135 |
'A pikachu fine dining with a view to the Eiffel Tower',
|
136 |
-
|
137 |
-
|
138 |
7,
|
139 |
1024,
|
140 |
],
|
141 |
[
|
142 |
'A mecha robot in a favela in expressionist style',
|
143 |
-
|
144 |
-
|
145 |
7,
|
146 |
1024,
|
147 |
],
|
148 |
[
|
149 |
'an insect robot preparing a delicious meal',
|
150 |
-
|
151 |
-
|
152 |
7,
|
153 |
1024,
|
154 |
],
|
155 |
[
|
156 |
"A small cabin on top of a snowy mountain in the style of disney, arstation",
|
157 |
-
|
158 |
-
|
159 |
7,
|
160 |
1024,
|
161 |
],
|
@@ -164,7 +171,7 @@ examples = [
|
|
164 |
with block:
|
165 |
gr.HTML(
|
166 |
"""
|
167 |
-
<div style="text-align: center; max-width:
|
168 |
<div
|
169 |
style="
|
170 |
display: inline-flex;
|
@@ -207,12 +214,12 @@ with block:
|
|
207 |
<rect x="23" y="69" width="23" height="23" fill="black"></rect>
|
208 |
</svg>
|
209 |
<h1 style="font-weight: 900; margin-bottom: 7px;">
|
210 |
-
Stable Diffusion
|
211 |
</h1>
|
212 |
</div>
|
213 |
-
<p style="margin-bottom:
|
214 |
Stable Diffusion is a state of the art text-to-image model that generates
|
215 |
-
images from
|
216 |
access you can try
|
217 |
<a
|
218 |
href="http://beta.dreamstudio.ai/"
|
@@ -225,7 +232,7 @@ with block:
|
|
225 |
"""
|
226 |
)
|
227 |
with gr.Group():
|
228 |
-
with gr.Box():
|
229 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
230 |
text = gr.Textbox(
|
231 |
label="Enter your prompt",
|
@@ -244,18 +251,18 @@ with block:
|
|
244 |
|
245 |
gallery = gr.Gallery(
|
246 |
label="Generated images", show_label=False, elem_id="gallery"
|
247 |
-
).style(grid=[
|
248 |
|
249 |
advanced_button = gr.Button("Advanced options", elem_id="advanced-btn")
|
250 |
|
251 |
with gr.Row(elem_id="advanced-options"):
|
252 |
-
samples = gr.Slider(label="Images", minimum=1, maximum=
|
253 |
-
steps = gr.Slider(label="Steps", minimum=1, maximum=50, value=
|
254 |
scale = gr.Slider(
|
255 |
label="Guidance Scale", minimum=0, maximum=50, value=7.5, step=0.1
|
256 |
)
|
257 |
seed = gr.Slider(
|
258 |
-
label="
|
259 |
minimum=0,
|
260 |
maximum=2147483647,
|
261 |
step=1,
|
|
|
18 |
def infer(prompt, samples, steps, scale, seed):
|
19 |
for filter in word_list:
|
20 |
if re.search(rf"\b{filter}\b", prompt):
|
21 |
+
raise gr.Error("Unsafe content found. Please try again with different prompts.")
|
22 |
|
23 |
generator = torch.Generator(device=device).manual_seed(seed)
|
24 |
with autocast("cuda"):
|
|
|
36 |
else:
|
37 |
images.append(image)
|
38 |
return images
|
39 |
+
|
|
|
40 |
css = """
|
41 |
.gradio-container {
|
42 |
font-family: 'IBM Plex Sans', sans-serif;
|
|
|
53 |
accent-color: #dfdfdf;
|
54 |
}
|
55 |
.container {
|
56 |
+
max-width: 730px;
|
57 |
margin: auto;
|
58 |
+
padding-top: 1.5rem;
|
59 |
+
}
|
60 |
+
#prompt-area {
|
61 |
+
max-width: 650px;
|
62 |
+
margin-left: auto;
|
63 |
+
margin-right: auto
|
64 |
}
|
65 |
#gallery {
|
66 |
+
max-width: 650px;
|
67 |
min-height: 22rem;
|
68 |
margin-bottom: 15px;
|
69 |
+
margin-left: auto;
|
70 |
+
margin-right: auto;
|
71 |
border-bottom-right-radius: .5rem !important;
|
72 |
border-bottom-left-radius: .5rem !important;
|
73 |
}
|
|
|
93 |
#advanced-btn {
|
94 |
font-size: .7rem !important;
|
95 |
line-height: 19px;
|
96 |
+
margin-top: 12px;
|
97 |
margin-bottom: 12px;
|
98 |
padding: 2px 8px;
|
99 |
border-radius: 14px !important;
|
|
|
133 |
examples = [
|
134 |
[
|
135 |
'A high tech solarpunk utopia in the Amazon rainforest',
|
136 |
+
4,
|
137 |
+
45,
|
138 |
7.5,
|
139 |
1024,
|
140 |
],
|
141 |
[
|
142 |
'A pikachu fine dining with a view to the Eiffel Tower',
|
143 |
+
4,
|
144 |
+
45,
|
145 |
7,
|
146 |
1024,
|
147 |
],
|
148 |
[
|
149 |
'A mecha robot in a favela in expressionist style',
|
150 |
+
4,
|
151 |
+
45,
|
152 |
7,
|
153 |
1024,
|
154 |
],
|
155 |
[
|
156 |
'an insect robot preparing a delicious meal',
|
157 |
+
4,
|
158 |
+
45,
|
159 |
7,
|
160 |
1024,
|
161 |
],
|
162 |
[
|
163 |
"A small cabin on top of a snowy mountain in the style of disney, arstation",
|
164 |
+
4,
|
165 |
+
45,
|
166 |
7,
|
167 |
1024,
|
168 |
],
|
|
|
171 |
with block:
|
172 |
gr.HTML(
|
173 |
"""
|
174 |
+
<div style="text-align: center; max-width: 650px; margin: 0 auto;">
|
175 |
<div
|
176 |
style="
|
177 |
display: inline-flex;
|
|
|
214 |
<rect x="23" y="69" width="23" height="23" fill="black"></rect>
|
215 |
</svg>
|
216 |
<h1 style="font-weight: 900; margin-bottom: 7px;">
|
217 |
+
Stable Diffusion Demo
|
218 |
</h1>
|
219 |
</div>
|
220 |
+
<p style="margin-bottom: 10px; font-size: 94%">
|
221 |
Stable Diffusion is a state of the art text-to-image model that generates
|
222 |
+
images from text.<br>For faster generation and forthcoming API
|
223 |
access you can try
|
224 |
<a
|
225 |
href="http://beta.dreamstudio.ai/"
|
|
|
232 |
"""
|
233 |
)
|
234 |
with gr.Group():
|
235 |
+
with gr.Box(elem_id="prompt-area"):
|
236 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
237 |
text = gr.Textbox(
|
238 |
label="Enter your prompt",
|
|
|
251 |
|
252 |
gallery = gr.Gallery(
|
253 |
label="Generated images", show_label=False, elem_id="gallery"
|
254 |
+
).style(grid=[2], height="auto")
|
255 |
|
256 |
advanced_button = gr.Button("Advanced options", elem_id="advanced-btn")
|
257 |
|
258 |
with gr.Row(elem_id="advanced-options"):
|
259 |
+
samples = gr.Slider(label="Images", minimum=1, maximum=4, value=4, step=1)
|
260 |
+
steps = gr.Slider(label="Steps", minimum=1, maximum=50, value=45, step=1)
|
261 |
scale = gr.Slider(
|
262 |
label="Guidance Scale", minimum=0, maximum=50, value=7.5, step=0.1
|
263 |
)
|
264 |
seed = gr.Slider(
|
265 |
+
label="Seed",
|
266 |
minimum=0,
|
267 |
maximum=2147483647,
|
268 |
step=1,
|
requirements.txt
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
diffusers
|
2 |
transformers
|
3 |
nvidia-ml-py3
|
|
|
4 |
--extra-index-url https://download.pytorch.org/whl/cu113 torch
|
|
|
1 |
diffusers
|
2 |
transformers
|
3 |
nvidia-ml-py3
|
4 |
+
ftfy
|
5 |
--extra-index-url https://download.pytorch.org/whl/cu113 torch
|