Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
clone
#3610
by
ernestchu
- opened
- README.md +7 -8
- app.py +125 -102
- requirements.txt +2 -1
- share_btn.py +8 -0
- unsafe.png +0 -0
README.md
CHANGED
@@ -1,14 +1,13 @@
|
|
1 |
---
|
2 |
-
title: Stable Diffusion
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
app_file: app.py
|
9 |
-
pinned:
|
10 |
license: mit
|
11 |
-
disable_embedding: true
|
12 |
---
|
13 |
|
14 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: Stable Diffusion
|
3 |
+
emoji: π
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: red
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.4b2
|
8 |
app_file: app.py
|
9 |
+
pinned: false
|
10 |
license: mit
|
|
|
11 |
---
|
12 |
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
@@ -1,45 +1,71 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
from datasets import load_dataset
|
3 |
from PIL import Image
|
4 |
-
|
|
|
5 |
import re
|
6 |
import os
|
7 |
import requests
|
8 |
-
|
9 |
-
import base64
|
10 |
|
11 |
from share_btn import community_icon_html, loading_icon_html, share_js
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
word_list = word_list_dataset["train"]['text']
|
15 |
|
16 |
is_gpu_busy = False
|
17 |
-
def infer(prompt
|
18 |
global is_gpu_busy
|
|
|
|
|
|
|
|
|
19 |
for filter in word_list:
|
20 |
if re.search(rf"\b{filter}\b", prompt):
|
21 |
-
print(filter)
|
22 |
-
print(prompt)
|
23 |
raise gr.Error("Unsafe content found. Please try again with different prompts.")
|
24 |
|
|
|
|
|
25 |
images = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
url = os.getenv('JAX_BACKEND_URL')
|
27 |
-
|
28 |
-
payload = {'prompt': prompt, 'negative_prompt': negative, 'guidance_scale': scale}
|
29 |
images_request = requests.post(url, json = payload)
|
30 |
for image in images_request.json()["images"]:
|
31 |
-
|
32 |
-
|
33 |
-
f.write(base64.b64decode(image))
|
34 |
-
images.append(file_path)
|
35 |
|
36 |
-
return images
|
37 |
|
38 |
|
39 |
css = """
|
40 |
-
.gradio-container {
|
41 |
-
max-width: 768px !important;
|
42 |
-
}
|
43 |
.gradio-container {
|
44 |
font-family: 'IBM Plex Sans', sans-serif;
|
45 |
}
|
@@ -57,6 +83,7 @@ css = """
|
|
57 |
.container {
|
58 |
max-width: 730px;
|
59 |
margin: auto;
|
|
|
60 |
}
|
61 |
#gallery {
|
62 |
min-height: 22rem;
|
@@ -121,6 +148,12 @@ css = """
|
|
121 |
font-weight: bold;
|
122 |
font-size: 115%;
|
123 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
.animate-spin {
|
125 |
animation: spin 1s linear infinite;
|
126 |
}
|
@@ -134,36 +167,19 @@ css = """
|
|
134 |
}
|
135 |
#share-btn-container {
|
136 |
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;
|
137 |
-
margin-top: 10px;
|
138 |
-
margin-left: auto;
|
139 |
-
}
|
140 |
-
#share-btn-container .styler{
|
141 |
-
background-color: #000000;
|
142 |
}
|
143 |
#share-btn {
|
144 |
-
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;
|
145 |
}
|
146 |
#share-btn * {
|
147 |
all: unset;
|
148 |
}
|
149 |
-
#share-btn-container div:nth-child(-n+2){
|
150 |
-
width: auto !important;
|
151 |
-
min-height: 0px !important;
|
152 |
-
}
|
153 |
-
#share-btn-container .wrap {
|
154 |
-
display: none !important;
|
155 |
-
}
|
156 |
-
|
157 |
.gr-form{
|
158 |
flex: 1 1 50%; border-top-right-radius: 0; border-bottom-right-radius: 0;
|
159 |
}
|
160 |
#prompt-container{
|
161 |
gap: 0;
|
162 |
}
|
163 |
-
#prompt-text-input, #negative-prompt-text-input{padding: .45rem 0.625rem}
|
164 |
-
#component-16{border-top-width: 1px!important;margin-top: 1em}
|
165 |
-
.image_duplication{position: absolute; width: 100px; left: 50px}
|
166 |
-
button{height: 100%}
|
167 |
"""
|
168 |
|
169 |
block = gr.Blocks(css=css)
|
@@ -171,28 +187,38 @@ block = gr.Blocks(css=css)
|
|
171 |
examples = [
|
172 |
[
|
173 |
'A high tech solarpunk utopia in the Amazon rainforest',
|
174 |
-
|
175 |
-
|
|
|
|
|
176 |
],
|
177 |
[
|
178 |
'A pikachu fine dining with a view to the Eiffel Tower',
|
179 |
-
|
180 |
-
|
|
|
|
|
181 |
],
|
182 |
[
|
183 |
'A mecha robot in a favela in expressionist style',
|
184 |
-
|
185 |
-
|
|
|
|
|
186 |
],
|
187 |
[
|
188 |
'an insect robot preparing a delicious meal',
|
189 |
-
|
190 |
-
|
|
|
|
|
191 |
],
|
192 |
[
|
193 |
"A small cabin on top of a snowy mountain in the style of Disney, artstation",
|
194 |
-
|
195 |
-
|
|
|
|
|
196 |
],
|
197 |
]
|
198 |
|
@@ -200,7 +226,7 @@ examples = [
|
|
200 |
with block:
|
201 |
gr.HTML(
|
202 |
"""
|
203 |
-
<div style="text-align: center; margin: 0 auto;">
|
204 |
<div
|
205 |
style="
|
206 |
display: inline-flex;
|
@@ -242,108 +268,105 @@ with block:
|
|
242 |
<rect x="23" y="115" width="23" height="23" fill="#AEAEAE"></rect>
|
243 |
<rect x="23" y="69" width="23" height="23" fill="black"></rect>
|
244 |
</svg>
|
245 |
-
<h1 style="font-weight: 900; margin-bottom: 7px;
|
246 |
-
Stable Diffusion
|
247 |
</h1>
|
248 |
</div>
|
249 |
-
<p style="margin-bottom: 10px; font-size: 94
|
250 |
-
Stable Diffusion
|
|
|
251 |
access you can try
|
252 |
<a
|
253 |
href="http://beta.dreamstudio.ai/"
|
254 |
style="text-decoration: underline;"
|
255 |
target="_blank"
|
256 |
>DreamStudio Beta</a
|
257 |
-
|
258 |
</p>
|
259 |
</div>
|
260 |
"""
|
261 |
)
|
262 |
with gr.Group():
|
263 |
-
with gr.
|
264 |
-
with gr.
|
265 |
text = gr.Textbox(
|
266 |
label="Enter your prompt",
|
267 |
show_label=False,
|
268 |
max_lines=1,
|
269 |
placeholder="Enter your prompt",
|
270 |
elem_id="prompt-text-input",
|
|
|
|
|
|
|
|
|
271 |
)
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
placeholder="Enter a negative prompt",
|
277 |
-
elem_id="negative-prompt-text-input",
|
278 |
)
|
279 |
-
with gr.Column(scale=1, min_width=150):
|
280 |
-
btn = gr.Button("Generate image")
|
281 |
|
282 |
gallery = gr.Gallery(
|
283 |
label="Generated images", show_label=False, elem_id="gallery"
|
284 |
-
)
|
285 |
|
286 |
with gr.Group(elem_id="container-advanced-btns"):
|
287 |
-
|
288 |
with gr.Group(elem_id="share-btn-container"):
|
289 |
community_icon = gr.HTML(community_icon_html)
|
290 |
loading_icon = gr.HTML(loading_icon_html)
|
291 |
share_button = gr.Button("Share to community", elem_id="share-btn")
|
292 |
|
293 |
-
with gr.
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
label="Guidance Scale", minimum=0, maximum=50, value=
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
|
308 |
-
ex = gr.Examples(examples=examples, fn=infer, inputs=
|
309 |
ex.dataset.headers = [""]
|
310 |
-
|
311 |
-
text.submit(infer, inputs=
|
312 |
-
btn.click(infer, inputs=
|
313 |
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
share_button.click(
|
325 |
None,
|
326 |
[],
|
327 |
[],
|
328 |
-
|
329 |
)
|
330 |
gr.HTML(
|
331 |
"""
|
332 |
<div class="footer">
|
333 |
-
<p>Model by <a href="https://huggingface.co/stabilityai" style="text-decoration: underline;" target="_blank">
|
334 |
</p>
|
335 |
</div>
|
336 |
-
|
337 |
-
)
|
338 |
-
with gr.Accordion(label="License", open=False):
|
339 |
-
gr.HTML(
|
340 |
-
"""<div class="acknowledgments">
|
341 |
<p><h4>LICENSE</h4>
|
342 |
-
The model is licensed with a <a href="https://huggingface.co/
|
343 |
<p><h4>Biases and content acknowledgment</h4>
|
344 |
Despite how impressive being able to turn text into image is, beware to the fact that this model may output content that reinforces or exacerbates societal biases, as well as realistic faces, pornography and violence. The model was trained on the <a href="https://laion.ai/blog/laion-5b/" style="text-decoration: underline;" target="_blank">LAION-5B dataset</a>, which scraped non-curated image-text-pairs from the internet (the exception being the removal of illegal content) and is meant for research purposes. You can read more in the <a href="https://huggingface.co/CompVis/stable-diffusion-v1-4" style="text-decoration: underline;" target="_blank">model card</a></p>
|
345 |
</div>
|
346 |
-
|
347 |
-
|
348 |
|
349 |
-
block.queue().launch(max_threads=150
|
|
|
1 |
import gradio as gr
|
2 |
+
#import torch
|
3 |
+
#from torch import autocast
|
4 |
+
#from diffusers import StableDiffusionPipeline
|
5 |
from datasets import load_dataset
|
6 |
from PIL import Image
|
7 |
+
#from io import BytesIO
|
8 |
+
#import base64
|
9 |
import re
|
10 |
import os
|
11 |
import requests
|
12 |
+
|
|
|
13 |
|
14 |
from share_btn import community_icon_html, loading_icon_html, share_js
|
15 |
|
16 |
+
model_id = "CompVis/stable-diffusion-v1-4"
|
17 |
+
device = "cuda"
|
18 |
+
|
19 |
+
#If you are running this code locally, you need to either do a 'huggingface-cli login` or paste your User Access Token from here https://huggingface.co/settings/tokens into the use_auth_token field below.
|
20 |
+
#pipe = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token=True, revision="fp16", torch_dtype=torch.float16)
|
21 |
+
#pipe = pipe.to(device)
|
22 |
+
#torch.backends.cudnn.benchmark = True
|
23 |
+
|
24 |
+
#When running locally, you won`t have access to this, so you can remove this part
|
25 |
+
word_list_dataset = load_dataset("stabilityai/word-list", data_files="list.txt", use_auth_token=True)
|
26 |
word_list = word_list_dataset["train"]['text']
|
27 |
|
28 |
is_gpu_busy = False
|
29 |
+
def infer(prompt):
|
30 |
global is_gpu_busy
|
31 |
+
samples = 4
|
32 |
+
steps = 50
|
33 |
+
scale = 7.5
|
34 |
+
#When running locally you can also remove this filter
|
35 |
for filter in word_list:
|
36 |
if re.search(rf"\b{filter}\b", prompt):
|
|
|
|
|
37 |
raise gr.Error("Unsafe content found. Please try again with different prompts.")
|
38 |
|
39 |
+
#generator = torch.Generator(device=device).manual_seed(seed)
|
40 |
+
#print("Is GPU busy? ", is_gpu_busy)
|
41 |
images = []
|
42 |
+
#if(not is_gpu_busy):
|
43 |
+
# is_gpu_busy = True
|
44 |
+
# images_list = pipe(
|
45 |
+
# [prompt] * samples,
|
46 |
+
# num_inference_steps=steps,
|
47 |
+
# guidance_scale=scale,
|
48 |
+
#generator=generator,
|
49 |
+
# )
|
50 |
+
# is_gpu_busy = False
|
51 |
+
# safe_image = Image.open(r"unsafe.png")
|
52 |
+
# for i, image in enumerate(images_list["sample"]):
|
53 |
+
# if(images_list["nsfw_content_detected"][i]):
|
54 |
+
# images.append(safe_image)
|
55 |
+
# else:
|
56 |
+
# images.append(image)
|
57 |
+
#else:
|
58 |
url = os.getenv('JAX_BACKEND_URL')
|
59 |
+
payload = {'prompt': prompt}
|
|
|
60 |
images_request = requests.post(url, json = payload)
|
61 |
for image in images_request.json()["images"]:
|
62 |
+
image_b64 = (f"data:image/jpeg;base64,{image}")
|
63 |
+
images.append(image_b64)
|
|
|
|
|
64 |
|
65 |
+
return images
|
66 |
|
67 |
|
68 |
css = """
|
|
|
|
|
|
|
69 |
.gradio-container {
|
70 |
font-family: 'IBM Plex Sans', sans-serif;
|
71 |
}
|
|
|
83 |
.container {
|
84 |
max-width: 730px;
|
85 |
margin: auto;
|
86 |
+
padding-top: 1.5rem;
|
87 |
}
|
88 |
#gallery {
|
89 |
min-height: 22rem;
|
|
|
148 |
font-weight: bold;
|
149 |
font-size: 115%;
|
150 |
}
|
151 |
+
#container-advanced-btns{
|
152 |
+
display: flex;
|
153 |
+
flex-wrap: wrap;
|
154 |
+
justify-content: space-between;
|
155 |
+
align-items: center;
|
156 |
+
}
|
157 |
.animate-spin {
|
158 |
animation: spin 1s linear infinite;
|
159 |
}
|
|
|
167 |
}
|
168 |
#share-btn-container {
|
169 |
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;
|
|
|
|
|
|
|
|
|
|
|
170 |
}
|
171 |
#share-btn {
|
172 |
+
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;
|
173 |
}
|
174 |
#share-btn * {
|
175 |
all: unset;
|
176 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
.gr-form{
|
178 |
flex: 1 1 50%; border-top-right-radius: 0; border-bottom-right-radius: 0;
|
179 |
}
|
180 |
#prompt-container{
|
181 |
gap: 0;
|
182 |
}
|
|
|
|
|
|
|
|
|
183 |
"""
|
184 |
|
185 |
block = gr.Blocks(css=css)
|
|
|
187 |
examples = [
|
188 |
[
|
189 |
'A high tech solarpunk utopia in the Amazon rainforest',
|
190 |
+
# 4,
|
191 |
+
# 45,
|
192 |
+
# 7.5,
|
193 |
+
# 1024,
|
194 |
],
|
195 |
[
|
196 |
'A pikachu fine dining with a view to the Eiffel Tower',
|
197 |
+
# 4,
|
198 |
+
# 45,
|
199 |
+
# 7,
|
200 |
+
# 1024,
|
201 |
],
|
202 |
[
|
203 |
'A mecha robot in a favela in expressionist style',
|
204 |
+
# 4,
|
205 |
+
# 45,
|
206 |
+
# 7,
|
207 |
+
# 1024,
|
208 |
],
|
209 |
[
|
210 |
'an insect robot preparing a delicious meal',
|
211 |
+
# 4,
|
212 |
+
# 45,
|
213 |
+
# 7,
|
214 |
+
# 1024,
|
215 |
],
|
216 |
[
|
217 |
"A small cabin on top of a snowy mountain in the style of Disney, artstation",
|
218 |
+
# 4,
|
219 |
+
# 45,
|
220 |
+
# 7,
|
221 |
+
# 1024,
|
222 |
],
|
223 |
]
|
224 |
|
|
|
226 |
with block:
|
227 |
gr.HTML(
|
228 |
"""
|
229 |
+
<div style="text-align: center; max-width: 650px; margin: 0 auto;">
|
230 |
<div
|
231 |
style="
|
232 |
display: inline-flex;
|
|
|
268 |
<rect x="23" y="115" width="23" height="23" fill="#AEAEAE"></rect>
|
269 |
<rect x="23" y="69" width="23" height="23" fill="black"></rect>
|
270 |
</svg>
|
271 |
+
<h1 style="font-weight: 900; margin-bottom: 7px;">
|
272 |
+
Stable Diffusion Demo
|
273 |
</h1>
|
274 |
</div>
|
275 |
+
<p style="margin-bottom: 10px; font-size: 94%">
|
276 |
+
Stable Diffusion is a state of the art text-to-image model that generates
|
277 |
+
images from text.<br>For faster generation and API
|
278 |
access you can try
|
279 |
<a
|
280 |
href="http://beta.dreamstudio.ai/"
|
281 |
style="text-decoration: underline;"
|
282 |
target="_blank"
|
283 |
>DreamStudio Beta</a
|
284 |
+
>
|
285 |
</p>
|
286 |
</div>
|
287 |
"""
|
288 |
)
|
289 |
with gr.Group():
|
290 |
+
with gr.Box():
|
291 |
+
with gr.Row(elem_id="prompt-container").style(mobile_collapse=False, equal_height=True):
|
292 |
text = gr.Textbox(
|
293 |
label="Enter your prompt",
|
294 |
show_label=False,
|
295 |
max_lines=1,
|
296 |
placeholder="Enter your prompt",
|
297 |
elem_id="prompt-text-input",
|
298 |
+
).style(
|
299 |
+
border=(True, False, True, True),
|
300 |
+
rounded=(True, False, False, True),
|
301 |
+
container=False,
|
302 |
)
|
303 |
+
btn = gr.Button("Generate image").style(
|
304 |
+
margin=False,
|
305 |
+
rounded=(False, True, True, False),
|
306 |
+
full_width=False,
|
|
|
|
|
307 |
)
|
|
|
|
|
308 |
|
309 |
gallery = gr.Gallery(
|
310 |
label="Generated images", show_label=False, elem_id="gallery"
|
311 |
+
).style(grid=[2], height="auto")
|
312 |
|
313 |
with gr.Group(elem_id="container-advanced-btns"):
|
314 |
+
advanced_button = gr.Button("Advanced options", elem_id="advanced-btn")
|
315 |
with gr.Group(elem_id="share-btn-container"):
|
316 |
community_icon = gr.HTML(community_icon_html)
|
317 |
loading_icon = gr.HTML(loading_icon_html)
|
318 |
share_button = gr.Button("Share to community", elem_id="share-btn")
|
319 |
|
320 |
+
with gr.Row(elem_id="advanced-options"):
|
321 |
+
gr.Markdown("Advanced settings are temporarily unavailable")
|
322 |
+
samples = gr.Slider(label="Images", minimum=1, maximum=4, value=4, step=1)
|
323 |
+
steps = gr.Slider(label="Steps", minimum=1, maximum=50, value=45, step=1)
|
324 |
+
scale = gr.Slider(
|
325 |
+
label="Guidance Scale", minimum=0, maximum=50, value=7.5, step=0.1
|
326 |
+
)
|
327 |
+
seed = gr.Slider(
|
328 |
+
label="Seed",
|
329 |
+
minimum=0,
|
330 |
+
maximum=2147483647,
|
331 |
+
step=1,
|
332 |
+
randomize=True,
|
333 |
+
)
|
334 |
|
335 |
+
ex = gr.Examples(examples=examples, fn=infer, inputs=text, outputs=[gallery, community_icon, loading_icon, share_button], cache_examples=False)
|
336 |
ex.dataset.headers = [""]
|
337 |
+
|
338 |
+
text.submit(infer, inputs=text, outputs=[gallery], postprocess=False)
|
339 |
+
btn.click(infer, inputs=text, outputs=[gallery], postprocess=False)
|
340 |
|
341 |
+
advanced_button.click(
|
342 |
+
None,
|
343 |
+
[],
|
344 |
+
text,
|
345 |
+
_js="""
|
346 |
+
() => {
|
347 |
+
const options = document.querySelector("body > gradio-app").querySelector("#advanced-options");
|
348 |
+
options.style.display = ["none", ""].includes(options.style.display) ? "flex" : "none";
|
349 |
+
}""",
|
350 |
+
)
|
351 |
share_button.click(
|
352 |
None,
|
353 |
[],
|
354 |
[],
|
355 |
+
_js=share_js,
|
356 |
)
|
357 |
gr.HTML(
|
358 |
"""
|
359 |
<div class="footer">
|
360 |
+
<p>Model by <a href="https://huggingface.co/CompVis" style="text-decoration: underline;" target="_blank">CompVis</a> and <a href="https://huggingface.co/stabilityai" style="text-decoration: underline;" target="_blank">Stability AI</a> - backend running JAX on TPUs due to generous support of <a href="https://sites.research.google/trc/about/" style="text-decoration: underline;" target="_blank">Google TRC program</a> - Gradio Demo by π€ Hugging Face
|
361 |
</p>
|
362 |
</div>
|
363 |
+
<div class="acknowledgments">
|
|
|
|
|
|
|
|
|
364 |
<p><h4>LICENSE</h4>
|
365 |
+
The model is licensed with a <a href="https://huggingface.co/spaces/CompVis/stable-diffusion-license" style="text-decoration: underline;" target="_blank">CreativeML Open RAIL-M</a> license. The authors claim no rights on the outputs you generate, you are free to use them and are accountable for their use which must not go against the provisions set in this license. The license forbids you from sharing any content that violates any laws, produce any harm to a person, disseminate any personal information that would be meant for harm, spread misinformation and target vulnerable groups. For the full list of restrictions please <a href="https://huggingface.co/spaces/CompVis/stable-diffusion-license" target="_blank" style="text-decoration: underline;" target="_blank">read the license</a></p>
|
366 |
<p><h4>Biases and content acknowledgment</h4>
|
367 |
Despite how impressive being able to turn text into image is, beware to the fact that this model may output content that reinforces or exacerbates societal biases, as well as realistic faces, pornography and violence. The model was trained on the <a href="https://laion.ai/blog/laion-5b/" style="text-decoration: underline;" target="_blank">LAION-5B dataset</a>, which scraped non-curated image-text-pairs from the internet (the exception being the removal of illegal content) and is meant for research purposes. You can read more in the <a href="https://huggingface.co/CompVis/stable-diffusion-v1-4" style="text-decoration: underline;" target="_blank">model card</a></p>
|
368 |
</div>
|
369 |
+
"""
|
370 |
+
)
|
371 |
|
372 |
+
block.queue(concurrency_count=40, max_size=20).launch(max_threads=150)
|
requirements.txt
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
python-dotenv
|
|
|
|
1 |
+
python-dotenv
|
2 |
+
https://gradio-builds.s3.amazonaws.com/queue-disconnect/v3/gradio-3.4b2-py3-none-any.whl
|
share_btn.py
CHANGED
@@ -22,18 +22,22 @@ share_js = """async () => {
|
|
22 |
const url = await response.text();
|
23 |
return url;
|
24 |
}
|
|
|
25 |
const gradioEl = document.querySelector('body > gradio-app');
|
26 |
const imgEls = gradioEl.querySelectorAll('#gallery img');
|
27 |
const promptTxt = gradioEl.querySelector('#prompt-text-input input').value;
|
28 |
const shareBtnEl = gradioEl.querySelector('#share-btn');
|
29 |
const shareIconEl = gradioEl.querySelector('#share-btn-share-icon');
|
30 |
const loadingIconEl = gradioEl.querySelector('#share-btn-loading-icon');
|
|
|
31 |
if(!imgEls.length){
|
32 |
return;
|
33 |
};
|
|
|
34 |
shareBtnEl.style.pointerEvents = 'none';
|
35 |
shareIconEl.style.display = 'none';
|
36 |
loadingIconEl.style.removeProperty('display');
|
|
|
37 |
const files = await Promise.all(
|
38 |
[...imgEls].map(async (imgEl) => {
|
39 |
const res = await fetch(imgEl.src);
|
@@ -43,17 +47,21 @@ share_js = """async () => {
|
|
43 |
return new File([blob], fileName, { type: 'image/jpeg' });
|
44 |
})
|
45 |
);
|
|
|
46 |
const urls = await Promise.all(files.map((f) => uploadFile(f)));
|
47 |
const htmlImgs = urls.map(url => `<img src='${url}' width='400' height='400'>`);
|
48 |
const descriptionMd = `<div style='display: flex; flex-wrap: wrap; column-gap: 0.75rem;'>
|
49 |
${htmlImgs.join(`\n`)}
|
50 |
</div>`;
|
|
|
51 |
const params = new URLSearchParams({
|
52 |
title: promptTxt,
|
53 |
description: descriptionMd,
|
54 |
});
|
|
|
55 |
const paramsStr = params.toString();
|
56 |
window.open(`https://huggingface.co/spaces/stabilityai/stable-diffusion/discussions/new?${paramsStr}`, '_blank');
|
|
|
57 |
shareBtnEl.style.removeProperty('pointer-events');
|
58 |
shareIconEl.style.removeProperty('display');
|
59 |
loadingIconEl.style.display = 'none';
|
|
|
22 |
const url = await response.text();
|
23 |
return url;
|
24 |
}
|
25 |
+
|
26 |
const gradioEl = document.querySelector('body > gradio-app');
|
27 |
const imgEls = gradioEl.querySelectorAll('#gallery img');
|
28 |
const promptTxt = gradioEl.querySelector('#prompt-text-input input').value;
|
29 |
const shareBtnEl = gradioEl.querySelector('#share-btn');
|
30 |
const shareIconEl = gradioEl.querySelector('#share-btn-share-icon');
|
31 |
const loadingIconEl = gradioEl.querySelector('#share-btn-loading-icon');
|
32 |
+
|
33 |
if(!imgEls.length){
|
34 |
return;
|
35 |
};
|
36 |
+
|
37 |
shareBtnEl.style.pointerEvents = 'none';
|
38 |
shareIconEl.style.display = 'none';
|
39 |
loadingIconEl.style.removeProperty('display');
|
40 |
+
|
41 |
const files = await Promise.all(
|
42 |
[...imgEls].map(async (imgEl) => {
|
43 |
const res = await fetch(imgEl.src);
|
|
|
47 |
return new File([blob], fileName, { type: 'image/jpeg' });
|
48 |
})
|
49 |
);
|
50 |
+
|
51 |
const urls = await Promise.all(files.map((f) => uploadFile(f)));
|
52 |
const htmlImgs = urls.map(url => `<img src='${url}' width='400' height='400'>`);
|
53 |
const descriptionMd = `<div style='display: flex; flex-wrap: wrap; column-gap: 0.75rem;'>
|
54 |
${htmlImgs.join(`\n`)}
|
55 |
</div>`;
|
56 |
+
|
57 |
const params = new URLSearchParams({
|
58 |
title: promptTxt,
|
59 |
description: descriptionMd,
|
60 |
});
|
61 |
+
|
62 |
const paramsStr = params.toString();
|
63 |
window.open(`https://huggingface.co/spaces/stabilityai/stable-diffusion/discussions/new?${paramsStr}`, '_blank');
|
64 |
+
|
65 |
shareBtnEl.style.removeProperty('pointer-events');
|
66 |
shareIconEl.style.removeProperty('display');
|
67 |
loadingIconEl.style.display = 'none';
|
unsafe.png
ADDED