Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
·
3454951
1
Parent(s):
e6c770e
Update app.py
Browse files
app.py
CHANGED
|
@@ -29,15 +29,17 @@ pipe = DiffusionPipeline.from_pretrained(repo_id, torch_dtype=torch.float16, rev
|
|
| 29 |
pipe = pipe.to(device)
|
| 30 |
pipe.enable_xformers_memory_efficient_attention()
|
| 31 |
|
| 32 |
-
#If you have duplicated this Space or is running locally, you can remove this
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
| 36 |
def infer(prompt, samples, steps, scale, seed):
|
| 37 |
-
#If you have duplicated this Space or is running locally, you can remove this
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
| 41 |
generator = torch.Generator(device=device).manual_seed(seed)
|
| 42 |
images = pipe(prompt, width=768, height=768, num_inference_steps=steps, guidance_scale=scale, num_images_per_prompt=samples, generator=generator).images
|
| 43 |
images_watermarked = []
|
|
|
|
| 29 |
pipe = pipe.to(device)
|
| 30 |
pipe.enable_xformers_memory_efficient_attention()
|
| 31 |
|
| 32 |
+
#If you have duplicated this Space or is running locally, you can remove this snippet
|
| 33 |
+
if "HUGGING_FACE_HUB_TOKEN" in os.environ:
|
| 34 |
+
word_list_dataset = load_dataset("stabilityai/word-list", data_files="list.txt", use_auth_token=True)
|
| 35 |
+
word_list = word_list_dataset["train"]['text']
|
| 36 |
+
|
| 37 |
def infer(prompt, samples, steps, scale, seed):
|
| 38 |
+
#If you have duplicated this Space or is running locally, you can remove this snippet
|
| 39 |
+
if "HUGGING_FACE_HUB_TOKEN" in os.environ:
|
| 40 |
+
for filter in word_list:
|
| 41 |
+
if re.search(rf"\b{filter}\b", prompt):
|
| 42 |
+
raise gr.Error("Unsafe content found. Please try again with different prompts.")
|
| 43 |
generator = torch.Generator(device=device).manual_seed(seed)
|
| 44 |
images = pipe(prompt, width=768, height=768, num_inference_steps=steps, guidance_scale=scale, num_images_per_prompt=samples, generator=generator).images
|
| 45 |
images_watermarked = []
|