Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
#import torch
|
3 |
#from torch import autocast // only for GPU
|
|
|
4 |
from PIL import Image
|
5 |
|
6 |
import os
|
7 |
MY_SECRET_TOKEN=os.environ.get('HF_TOKEN_SD')
|
8 |
|
9 |
-
|
10 |
from diffusers import StableDiffusionPipeline
|
11 |
#from diffusers import StableDiffusionImg2ImgPipeline
|
12 |
|
@@ -19,7 +19,14 @@ device="cpu"
|
|
19 |
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=YOUR_TOKEN)
|
20 |
pipe.to(device)
|
21 |
|
|
|
|
|
|
|
|
|
22 |
def infer(prompt):
|
|
|
|
|
|
|
23 |
|
24 |
#image = pipe(prompt, init_image=init_image)["sample"][0]
|
25 |
image = pipe(prompt)["sample"][0]
|
|
|
1 |
import gradio as gr
|
2 |
#import torch
|
3 |
#from torch import autocast // only for GPU
|
4 |
+
from datasets import load_dataset
|
5 |
from PIL import Image
|
6 |
|
7 |
import os
|
8 |
MY_SECRET_TOKEN=os.environ.get('HF_TOKEN_SD')
|
9 |
|
|
|
10 |
from diffusers import StableDiffusionPipeline
|
11 |
#from diffusers import StableDiffusionImg2ImgPipeline
|
12 |
|
|
|
19 |
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=YOUR_TOKEN)
|
20 |
pipe.to(device)
|
21 |
|
22 |
+
#When running locally, you won`t have access to this, so you can remove this part
|
23 |
+
word_list_dataset = load_dataset("stabilityai/word-list", data_files="list.txt", use_auth_token=YOUR_TOKEN)
|
24 |
+
word_list = word_list_dataset["train"]['text']
|
25 |
+
|
26 |
def infer(prompt):
|
27 |
+
for filter in word_list:
|
28 |
+
if re.search(rf"\b{filter}\b", prompt):
|
29 |
+
raise gr.Error("Unsafe content found. Please try again with different prompts.")
|
30 |
|
31 |
#image = pipe(prompt, init_image=init_image)["sample"][0]
|
32 |
image = pipe(prompt)["sample"][0]
|