Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
•
9132934
1
Parent(s):
a6e6764
Testing a max queue size of 10
Browse filesAnd some comments and text changing
app.py
CHANGED
@@ -10,17 +10,22 @@ import re
|
|
10 |
model_id = "CompVis/stable-diffusion-v1-4"
|
11 |
device = "cuda"
|
12 |
|
|
|
13 |
pipe = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token=True, revision="fp16", torch_dtype=torch.float16)
|
14 |
pipe = pipe.to(device)
|
|
|
15 |
word_list_dataset = load_dataset("stabilityai/word-list", data_files="list.txt", use_auth_token=True)
|
16 |
word_list = word_list_dataset["train"]['text']
|
17 |
|
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"):
|
25 |
images_list = pipe(
|
26 |
[prompt] * samples,
|
@@ -160,7 +165,7 @@ examples = [
|
|
160 |
1024,
|
161 |
],
|
162 |
[
|
163 |
-
"A small cabin on top of a snowy mountain in the style of
|
164 |
4,
|
165 |
45,
|
166 |
7,
|
@@ -300,4 +305,4 @@ Despite how impressive being able to turn text into image is, beware to the fact
|
|
300 |
"""
|
301 |
)
|
302 |
|
303 |
-
block.queue(max_size=
|
|
|
10 |
model_id = "CompVis/stable-diffusion-v1-4"
|
11 |
device = "cuda"
|
12 |
|
13 |
+
#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.
|
14 |
pipe = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token=True, revision="fp16", torch_dtype=torch.float16)
|
15 |
pipe = pipe.to(device)
|
16 |
+
#When running locally, you won`t have access to this, so you can remove this part
|
17 |
word_list_dataset = load_dataset("stabilityai/word-list", data_files="list.txt", use_auth_token=True)
|
18 |
word_list = word_list_dataset["train"]['text']
|
19 |
|
20 |
def infer(prompt, samples, steps, scale, seed):
|
21 |
+
#When running locally you can also remove this filter
|
22 |
for filter in word_list:
|
23 |
if re.search(rf"\b{filter}\b", prompt):
|
24 |
raise gr.Error("Unsafe content found. Please try again with different prompts.")
|
25 |
|
26 |
generator = torch.Generator(device=device).manual_seed(seed)
|
27 |
+
|
28 |
+
#If you are running locally with CPU, you can remove the `with autocast("cuda")`
|
29 |
with autocast("cuda"):
|
30 |
images_list = pipe(
|
31 |
[prompt] * samples,
|
|
|
165 |
1024,
|
166 |
],
|
167 |
[
|
168 |
+
"A small cabin on top of a snowy mountain in the style of Disney, artstation",
|
169 |
4,
|
170 |
45,
|
171 |
7,
|
|
|
305 |
"""
|
306 |
)
|
307 |
|
308 |
+
block.queue(max_size=10).launch()
|