multimodalart HF staff commited on
Commit
8d4a7ac
1 Parent(s): 3fbb33c

Stable Diffusion 2 demo

Browse files
Files changed (7) hide show
  1. README.md +6 -8
  2. app.py +0 -372
  3. index.html +13 -0
  4. requirements.txt +0 -2
  5. share_btn.py +0 -68
  6. style.css +28 -0
  7. unsafe.png +0 -0
README.md CHANGED
@@ -1,12 +1,10 @@
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
 
 
1
  ---
2
+ title: Stable Diffusion 2
3
+ emoji: 🔮
4
+ colorFrom: gray
5
+ colorTo: pink
6
+ sdk: static
7
+ pinned: true
 
 
8
  license: mit
9
  ---
10
 
app.py DELETED
@@ -1,372 +0,0 @@
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
- }
72
- .gr-button {
73
- color: white;
74
- border-color: black;
75
- background: black;
76
- }
77
- input[type='range'] {
78
- accent-color: black;
79
- }
80
- .dark input[type='range'] {
81
- accent-color: #dfdfdf;
82
- }
83
- .container {
84
- max-width: 730px;
85
- margin: auto;
86
- padding-top: 1.5rem;
87
- }
88
- #gallery {
89
- min-height: 22rem;
90
- margin-bottom: 15px;
91
- margin-left: auto;
92
- margin-right: auto;
93
- border-bottom-right-radius: .5rem !important;
94
- border-bottom-left-radius: .5rem !important;
95
- }
96
- #gallery>div>.h-full {
97
- min-height: 20rem;
98
- }
99
- .details:hover {
100
- text-decoration: underline;
101
- }
102
- .gr-button {
103
- white-space: nowrap;
104
- }
105
- .gr-button:focus {
106
- border-color: rgb(147 197 253 / var(--tw-border-opacity));
107
- outline: none;
108
- box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
109
- --tw-border-opacity: 1;
110
- --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
111
- --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
112
- --tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
113
- --tw-ring-opacity: .5;
114
- }
115
- #advanced-btn {
116
- font-size: .7rem !important;
117
- line-height: 19px;
118
- margin-top: 12px;
119
- margin-bottom: 12px;
120
- padding: 2px 8px;
121
- border-radius: 14px !important;
122
- }
123
- #advanced-options {
124
- display: none;
125
- margin-bottom: 20px;
126
- }
127
- .footer {
128
- margin-bottom: 45px;
129
- margin-top: 35px;
130
- text-align: center;
131
- border-bottom: 1px solid #e5e5e5;
132
- }
133
- .footer>p {
134
- font-size: .8rem;
135
- display: inline-block;
136
- padding: 0 10px;
137
- transform: translateY(10px);
138
- background: white;
139
- }
140
- .dark .footer {
141
- border-color: #303030;
142
- }
143
- .dark .footer>p {
144
- background: #0b0f19;
145
- }
146
- .acknowledgments h4{
147
- margin: 1.25em 0 .25em 0;
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
- }
160
- @keyframes spin {
161
- from {
162
- transform: rotate(0deg);
163
- }
164
- to {
165
- transform: rotate(360deg);
166
- }
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)
186
-
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
-
225
-
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;
233
- align-items: center;
234
- gap: 0.8rem;
235
- font-size: 1.75rem;
236
- "
237
- >
238
- <svg
239
- width="0.65em"
240
- height="0.65em"
241
- viewBox="0 0 115 115"
242
- fill="none"
243
- xmlns="http://www.w3.org/2000/svg"
244
- >
245
- <rect width="23" height="23" fill="white"></rect>
246
- <rect y="69" width="23" height="23" fill="white"></rect>
247
- <rect x="23" width="23" height="23" fill="#AEAEAE"></rect>
248
- <rect x="23" y="69" width="23" height="23" fill="#AEAEAE"></rect>
249
- <rect x="46" width="23" height="23" fill="white"></rect>
250
- <rect x="46" y="69" width="23" height="23" fill="white"></rect>
251
- <rect x="69" width="23" height="23" fill="black"></rect>
252
- <rect x="69" y="69" width="23" height="23" fill="black"></rect>
253
- <rect x="92" width="23" height="23" fill="#D9D9D9"></rect>
254
- <rect x="92" y="69" width="23" height="23" fill="#AEAEAE"></rect>
255
- <rect x="115" y="46" width="23" height="23" fill="white"></rect>
256
- <rect x="115" y="115" width="23" height="23" fill="white"></rect>
257
- <rect x="115" y="69" width="23" height="23" fill="#D9D9D9"></rect>
258
- <rect x="92" y="46" width="23" height="23" fill="#AEAEAE"></rect>
259
- <rect x="92" y="115" width="23" height="23" fill="#AEAEAE"></rect>
260
- <rect x="92" y="69" width="23" height="23" fill="white"></rect>
261
- <rect x="69" y="46" width="23" height="23" fill="white"></rect>
262
- <rect x="69" y="115" width="23" height="23" fill="white"></rect>
263
- <rect x="69" y="69" width="23" height="23" fill="#D9D9D9"></rect>
264
- <rect x="46" y="46" width="23" height="23" fill="black"></rect>
265
- <rect x="46" y="115" width="23" height="23" fill="black"></rect>
266
- <rect x="46" y="69" width="23" height="23" fill="black"></rect>
267
- <rect x="23" y="46" width="23" height="23" fill="#D9D9D9"></rect>
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)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
index.html ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width" />
6
+ <title>Stable Diffusion 2</title>
7
+ <link rel="stylesheet" href="style.css" />
8
+
9
+ </head>
10
+ <body style="margin: 0; padding:0">
11
+ <iframe width="100%" style="border: 0; height: 200vh" src="https://c6ecfa3eb57c0d76.gradio.app/?__theme=system"></iframe>
12
+ </body>
13
+ </html>
requirements.txt DELETED
@@ -1,2 +0,0 @@
1
- python-dotenv
2
- https://gradio-builds.s3.amazonaws.com/queue-disconnect/v3/gradio-3.4b2-py3-none-any.whl
 
 
 
share_btn.py DELETED
@@ -1,68 +0,0 @@
1
- community_icon_html = """<svg id="share-btn-share-icon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32">
2
- <path d="M20.6081 3C21.7684 3 22.8053 3.49196 23.5284 4.38415C23.9756 4.93678 24.4428 5.82749 24.4808 7.16133C24.9674 7.01707 25.4353 6.93643 25.8725 6.93643C26.9833 6.93643 27.9865 7.37587 28.696 8.17411C29.6075 9.19872 30.0124 10.4579 29.8361 11.7177C29.7523 12.3177 29.5581 12.8555 29.2678 13.3534C29.8798 13.8646 30.3306 14.5763 30.5485 15.4322C30.719 16.1032 30.8939 17.5006 29.9808 18.9403C30.0389 19.0342 30.0934 19.1319 30.1442 19.2318C30.6932 20.3074 30.7283 21.5229 30.2439 22.6548C29.5093 24.3704 27.6841 25.7219 24.1397 27.1727C21.9347 28.0753 19.9174 28.6523 19.8994 28.6575C16.9842 29.4379 14.3477 29.8345 12.0653 29.8345C7.87017 29.8345 4.8668 28.508 3.13831 25.8921C0.356375 21.6797 0.754104 17.8269 4.35369 14.1131C6.34591 12.058 7.67023 9.02782 7.94613 8.36275C8.50224 6.39343 9.97271 4.20438 12.4172 4.20438H12.4179C12.6236 4.20438 12.8314 4.2214 13.0364 4.25468C14.107 4.42854 15.0428 5.06476 15.7115 6.02205C16.4331 5.09583 17.134 4.359 17.7682 3.94323C18.7242 3.31737 19.6794 3 20.6081 3ZM20.6081 5.95917C20.2427 5.95917 19.7963 6.1197 19.3039 6.44225C17.7754 7.44319 14.8258 12.6772 13.7458 14.7131C13.3839 15.3952 12.7655 15.6837 12.2086 15.6837C11.1036 15.6837 10.2408 14.5497 12.1076 13.1085C14.9146 10.9402 13.9299 7.39584 12.5898 7.1776C12.5311 7.16799 12.4731 7.16355 12.4172 7.16355C11.1989 7.16355 10.6615 9.33114 10.6615 9.33114C10.6615 9.33114 9.0863 13.4148 6.38031 16.206C3.67434 18.998 3.5346 21.2388 5.50675 24.2246C6.85185 26.2606 9.42666 26.8753 12.0653 26.8753C14.8021 26.8753 17.6077 26.2139 19.1799 25.793C19.2574 25.7723 28.8193 22.984 27.6081 20.6107C27.4046 20.212 27.0693 20.0522 26.6471 20.0522C24.9416 20.0522 21.8393 22.6726 20.5057 22.6726C20.2076 22.6726 19.9976 22.5416 19.9116 22.222C19.3433 20.1173 28.552 19.2325 27.7758 16.1839C27.639 15.6445 27.2677 15.4256 26.746 15.4263C24.4923 15.4263 19.4358 19.5181 18.3759 19.5181C18.2949 19.5181 18.2368 19.4937 18.2053 19.4419C17.6743 18.557 17.9653 17.9394 21.7082 15.6009C25.4511 13.2617 28.0783 11.8545 26.5841 10.1752C26.4121 9.98141 26.1684 9.8956 25.8725 9.8956C23.6001 9.89634 18.2311 14.9403 18.2311 14.9403C18.2311 14.9403 16.7821 16.496 15.9057 16.496C15.7043 16.496 15.533 16.4139 15.4169 16.2112C14.7956 15.1296 21.1879 10.1286 21.5484 8.06535C21.7928 6.66715 21.3771 5.95917 20.6081 5.95917Z" fill="#FF9D00"></path>
3
- <path d="M5.50686 24.2246C3.53472 21.2387 3.67446 18.9979 6.38043 16.206C9.08641 13.4147 10.6615 9.33111 10.6615 9.33111C10.6615 9.33111 11.2499 6.95933 12.59 7.17757C13.93 7.39581 14.9139 10.9401 12.1069 13.1084C9.29997 15.276 12.6659 16.7489 13.7459 14.713C14.8258 12.6772 17.7747 7.44316 19.304 6.44221C20.8326 5.44128 21.9089 6.00204 21.5484 8.06532C21.188 10.1286 14.795 15.1295 15.4171 16.2118C16.0391 17.2934 18.2312 14.9402 18.2312 14.9402C18.2312 14.9402 25.0907 8.49588 26.5842 10.1752C28.0776 11.8545 25.4512 13.2616 21.7082 15.6008C17.9646 17.9393 17.6744 18.557 18.2054 19.4418C18.7372 20.3266 26.9998 13.1351 27.7759 16.1838C28.5513 19.2324 19.3434 20.1173 19.9117 22.2219C20.48 24.3274 26.3979 18.2382 27.6082 20.6107C28.8193 22.9839 19.2574 25.7722 19.18 25.7929C16.0914 26.62 8.24723 28.3726 5.50686 24.2246Z" fill="#FFD21E"></path>
4
- </svg>"""
5
-
6
- loading_icon_html = """<svg id="share-btn-loading-icon" style="display:none;" class="animate-spin"
7
- style="color: #ffffff;
8
- "
9
- xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" fill="none" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><circle style="opacity: 0.25;" cx="12" cy="12" r="10" stroke="white" stroke-width="4"></circle><path style="opacity: 0.75;" fill="white" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg>"""
10
-
11
- share_js = """async () => {
12
- async function uploadFile(file){
13
- const UPLOAD_URL = 'https://huggingface.co/uploads';
14
- const response = await fetch(UPLOAD_URL, {
15
- method: 'POST',
16
- headers: {
17
- 'Content-Type': file.type,
18
- 'X-Requested-With': 'XMLHttpRequest',
19
- },
20
- body: file, /// <- File inherits from Blob
21
- });
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);
44
- const blob = await res.blob();
45
- const imgId = Date.now() % 200;
46
- const fileName = `diffuse-the-rest-${{imgId}}.jpg`;
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';
68
- }"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
style.css ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ body {
2
+ padding: 2rem;
3
+ font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
4
+ }
5
+
6
+ h1 {
7
+ font-size: 16px;
8
+ margin-top: 0;
9
+ }
10
+
11
+ p {
12
+ color: rgb(107, 114, 128);
13
+ font-size: 15px;
14
+ margin-bottom: 10px;
15
+ margin-top: 5px;
16
+ }
17
+
18
+ .card {
19
+ max-width: 620px;
20
+ margin: 0 auto;
21
+ padding: 16px;
22
+ border: 1px solid lightgray;
23
+ border-radius: 16px;
24
+ }
25
+
26
+ .card p:last-child {
27
+ margin-bottom: 0;
28
+ }
unsafe.png DELETED
Binary file (29.6 kB)