roman-bachmann commited on
Commit
704a12b
1 Parent(s): 96d0584

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -0
app.py CHANGED
@@ -15,10 +15,14 @@ import spaces
15
  from diffusers import StableDiffusionXLPipeline, DiffusionPipeline
16
  import anthropic
17
  import base64
 
18
 
19
  device = "cuda" if torch.cuda.is_available() else "cpu"
20
  print(device)
21
 
 
 
 
22
  bnb_config = BitsAndBytesConfig(
23
  load_in_4bit=True,
24
  bnb_4bit_use_double_quant=True,
@@ -464,6 +468,12 @@ def api_fn(api):
464
  def generate(prompt, vp_pos, vp_neg, slider, example_prompt, gallery):
465
  if vp_pos == "" and vp_neg == "":
466
  slider = 0
 
 
 
 
 
 
467
 
468
  print(f"prompt: {prompt}")
469
  image = pipe(prompt=prompt,
 
15
  from diffusers import StableDiffusionXLPipeline, DiffusionPipeline
16
  import anthropic
17
  import base64
18
+ from datasets import load_dataset
19
 
20
  device = "cuda" if torch.cuda.is_available() else "cpu"
21
  print(device)
22
 
23
+ word_list_dataset = load_dataset("EPFL-VILAB/4m-wordlist", data_files="list.txt", use_auth_token=True)
24
+ word_list = word_list_dataset["train"]['text']
25
+
26
  bnb_config = BitsAndBytesConfig(
27
  load_in_4bit=True,
28
  bnb_4bit_use_double_quant=True,
 
468
  def generate(prompt, vp_pos, vp_neg, slider, example_prompt, gallery):
469
  if vp_pos == "" and vp_neg == "":
470
  slider = 0
471
+
472
+ for filter in word_list:
473
+ if re.search(rf"\b{filter}\b", prompt):
474
+ raise gr.Error("Please try again with a different prompt")
475
+ if re.search(rf"\b{filter}\b", vp_pos) or re.search(rf"\b{filter}\b", vp_neg):
476
+ raise gr.Error("Please try again with a different visual preference")
477
 
478
  print(f"prompt: {prompt}")
479
  image = pipe(prompt=prompt,