Spaces:
Runtime error
Runtime error
Your Name
commited on
Commit
•
8936f17
1
Parent(s):
a4f22dc
fuck you
Browse files- .DS_Store +0 -0
- app.py +75 -15
- requirements.txt +0 -5
.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
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
|
@@ -11,14 +11,18 @@ import os
|
|
11 |
import requests
|
12 |
|
13 |
|
14 |
-
|
|
|
15 |
device = "cuda"
|
16 |
|
17 |
#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.
|
18 |
-
pipe = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token=
|
19 |
-
pipe = pipe.to(device)
|
20 |
-
torch.backends.cudnn.benchmark = True
|
21 |
|
|
|
|
|
|
|
22 |
|
23 |
is_gpu_busy = False
|
24 |
def infer(prompt):
|
@@ -26,7 +30,10 @@ def infer(prompt):
|
|
26 |
samples = 4
|
27 |
steps = 50
|
28 |
scale = 7.5
|
29 |
-
|
|
|
|
|
|
|
30 |
|
31 |
#generator = torch.Generator(device=device).manual_seed(seed)
|
32 |
#print("Is GPU busy? ", is_gpu_busy)
|
@@ -227,11 +234,53 @@ with block:
|
|
227 |
font-size: 1.75rem;
|
228 |
"
|
229 |
>
|
230 |
-
|
231 |
-
|
232 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
233 |
</h1>
|
234 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
</p>
|
236 |
</div>
|
237 |
"""
|
@@ -262,6 +311,7 @@ with block:
|
|
262 |
|
263 |
with gr.Group(elem_id="container-advanced-btns"):
|
264 |
advanced_button = gr.Button("Advanced options", elem_id="advanced-btn")
|
|
|
265 |
|
266 |
with gr.Row(elem_id="advanced-options"):
|
267 |
gr.Markdown("Advanced settings are temporarily unavailable")
|
@@ -278,7 +328,7 @@ with block:
|
|
278 |
randomize=True,
|
279 |
)
|
280 |
|
281 |
-
ex = gr.Examples(examples=examples, fn=infer, inputs=text, outputs=[gallery], cache_examples=False)
|
282 |
ex.dataset.headers = [""]
|
283 |
|
284 |
text.submit(infer, inputs=text, outputs=[gallery], postprocess=False)
|
@@ -294,10 +344,20 @@ with block:
|
|
294 |
options.style.display = ["none", ""].includes(options.style.display) ? "flex" : "none";
|
295 |
}""",
|
296 |
)
|
297 |
-
|
298 |
gr.HTML(
|
299 |
-
|
300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
)
|
302 |
|
303 |
block.queue(concurrency_count=40, max_size=20).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
|
|
|
11 |
import requests
|
12 |
|
13 |
|
14 |
+
|
15 |
+
model_id = "CompVis/stable-diffusion-v1-4"
|
16 |
device = "cuda"
|
17 |
|
18 |
#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.
|
19 |
+
#pipe = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token=True, revision="fp16", torch_dtype=torch.float16)
|
20 |
+
#pipe = pipe.to(device)
|
21 |
+
#torch.backends.cudnn.benchmark = True
|
22 |
|
23 |
+
#When running locally, you won`t have access to this, so you can remove this part
|
24 |
+
word_list_dataset = load_dataset("stabilityai/word-list", data_files="list.txt", use_auth_token=True)
|
25 |
+
word_list = word_list_dataset["train"]['text']
|
26 |
|
27 |
is_gpu_busy = False
|
28 |
def infer(prompt):
|
|
|
30 |
samples = 4
|
31 |
steps = 50
|
32 |
scale = 7.5
|
33 |
+
#When running locally you can also remove this filter
|
34 |
+
for filter in word_list:
|
35 |
+
if re.search(rf"\b{filter}\b", prompt):
|
36 |
+
raise gr.Error("Unsafe content found. Please try again with different prompts.")
|
37 |
|
38 |
#generator = torch.Generator(device=device).manual_seed(seed)
|
39 |
#print("Is GPU busy? ", is_gpu_busy)
|
|
|
234 |
font-size: 1.75rem;
|
235 |
"
|
236 |
>
|
237 |
+
<svg
|
238 |
+
width="0.65em"
|
239 |
+
height="0.65em"
|
240 |
+
viewBox="0 0 115 115"
|
241 |
+
fill="none"
|
242 |
+
xmlns="http://www.w3.org/2000/svg"
|
243 |
+
>
|
244 |
+
<rect width="23" height="23" fill="white"></rect>
|
245 |
+
<rect y="69" width="23" height="23" fill="white"></rect>
|
246 |
+
<rect x="23" width="23" height="23" fill="#AEAEAE"></rect>
|
247 |
+
<rect x="23" y="69" width="23" height="23" fill="#AEAEAE"></rect>
|
248 |
+
<rect x="46" width="23" height="23" fill="white"></rect>
|
249 |
+
<rect x="46" y="69" width="23" height="23" fill="white"></rect>
|
250 |
+
<rect x="69" width="23" height="23" fill="black"></rect>
|
251 |
+
<rect x="69" y="69" width="23" height="23" fill="black"></rect>
|
252 |
+
<rect x="92" width="23" height="23" fill="#D9D9D9"></rect>
|
253 |
+
<rect x="92" y="69" width="23" height="23" fill="#AEAEAE"></rect>
|
254 |
+
<rect x="115" y="46" width="23" height="23" fill="white"></rect>
|
255 |
+
<rect x="115" y="115" width="23" height="23" fill="white"></rect>
|
256 |
+
<rect x="115" y="69" width="23" height="23" fill="#D9D9D9"></rect>
|
257 |
+
<rect x="92" y="46" width="23" height="23" fill="#AEAEAE"></rect>
|
258 |
+
<rect x="92" y="115" width="23" height="23" fill="#AEAEAE"></rect>
|
259 |
+
<rect x="92" y="69" width="23" height="23" fill="white"></rect>
|
260 |
+
<rect x="69" y="46" width="23" height="23" fill="white"></rect>
|
261 |
+
<rect x="69" y="115" width="23" height="23" fill="white"></rect>
|
262 |
+
<rect x="69" y="69" width="23" height="23" fill="#D9D9D9"></rect>
|
263 |
+
<rect x="46" y="46" width="23" height="23" fill="black"></rect>
|
264 |
+
<rect x="46" y="115" width="23" height="23" fill="black"></rect>
|
265 |
+
<rect x="46" y="69" width="23" height="23" fill="black"></rect>
|
266 |
+
<rect x="23" y="46" width="23" height="23" fill="#D9D9D9"></rect>
|
267 |
+
<rect x="23" y="115" width="23" height="23" fill="#AEAEAE"></rect>
|
268 |
+
<rect x="23" y="69" width="23" height="23" fill="black"></rect>
|
269 |
+
</svg>
|
270 |
+
<h1 style="font-weight: 900; margin-bottom: 7px;">
|
271 |
+
Stable Diffusion Demo
|
272 |
</h1>
|
273 |
</div>
|
274 |
+
<p style="margin-bottom: 10px; font-size: 94%">
|
275 |
+
Stable Diffusion is a state of the art text-to-image model that generates
|
276 |
+
images from text.<br>For faster generation and API
|
277 |
+
access you can try
|
278 |
+
<a
|
279 |
+
href="http://beta.dreamstudio.ai/"
|
280 |
+
style="text-decoration: underline;"
|
281 |
+
target="_blank"
|
282 |
+
>DreamStudio Beta</a
|
283 |
+
>
|
284 |
</p>
|
285 |
</div>
|
286 |
"""
|
|
|
311 |
|
312 |
with gr.Group(elem_id="container-advanced-btns"):
|
313 |
advanced_button = gr.Button("Advanced options", elem_id="advanced-btn")
|
314 |
+
|
315 |
|
316 |
with gr.Row(elem_id="advanced-options"):
|
317 |
gr.Markdown("Advanced settings are temporarily unavailable")
|
|
|
328 |
randomize=True,
|
329 |
)
|
330 |
|
331 |
+
ex = gr.Examples(examples=examples, fn=infer, inputs=text, outputs=[gallery ], cache_examples=False)
|
332 |
ex.dataset.headers = [""]
|
333 |
|
334 |
text.submit(infer, inputs=text, outputs=[gallery], postprocess=False)
|
|
|
344 |
options.style.display = ["none", ""].includes(options.style.display) ? "flex" : "none";
|
345 |
}""",
|
346 |
)
|
347 |
+
|
348 |
gr.HTML(
|
349 |
+
"""
|
350 |
+
<div class="footer">
|
351 |
+
<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
|
352 |
+
</p>
|
353 |
+
</div>
|
354 |
+
<div class="acknowledgments">
|
355 |
+
<p><h4>LICENSE</h4>
|
356 |
+
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>
|
357 |
+
<p><h4>Biases and content acknowledgment</h4>
|
358 |
+
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>
|
359 |
+
</div>
|
360 |
+
"""
|
361 |
)
|
362 |
|
363 |
block.queue(concurrency_count=40, max_size=20).launch(max_threads=150)
|
requirements.txt
CHANGED
@@ -1,8 +1,3 @@
|
|
1 |
python-dotenv
|
2 |
https://gradio-builds.s3.amazonaws.com/queue-disconnect/v3/gradio-3.4b2-py3-none-any.whl
|
3 |
|
4 |
-
torch
|
5 |
-
|
6 |
-
diffusers
|
7 |
-
|
8 |
-
transformers
|
|
|
1 |
python-dotenv
|
2 |
https://gradio-builds.s3.amazonaws.com/queue-disconnect/v3/gradio-3.4b2-py3-none-any.whl
|
3 |
|
|
|
|
|
|
|
|
|
|