Prompt-Guard commited on
Commit
09456ad
·
verified ·
1 Parent(s): 9041049

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +33 -1
README.md CHANGED
@@ -2,4 +2,36 @@
2
  license: apache-2.0
3
  base_model:
4
  - CompVis/stable-diffusion-v1-4
5
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  license: apache-2.0
3
  base_model:
4
  - CompVis/stable-diffusion-v1-4
5
+ ---
6
+ Here are the official released weights of **PromptGuard : Soft Prompt-Guided Unsafe Content Moderation for Text-to-Image Models**.
7
+
8
+ Our project page is [🏠PromptGuard HomePage](https://prompt-guard.github.io/) and the GitHub repo is [⚙️PromptGuard GitHub](https://anonymous.4open.science/r/PromptGuard-727C/README.md) where we released the code.
9
+
10
+ In the future, we will release our training datasets.
11
+
12
+ # Usage
13
+ A simple use case of our model is:
14
+ ```python
15
+ from diffusers import StableDiffusionPipeline
16
+ import torch
17
+ model_id = "CompVis/stable-diffusion-v1-4"
18
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda")
19
+
20
+ # remove the safety checker
21
+ def dummy_checker(images, **kwargs):
22
+ return images, [False] * len(images)
23
+ pipe.safety_checker = dummy_checker
24
+
25
+ safety_embedding_list = [${embedding_path_1}, ${embedding_path_2}, ...] # the save paths of your embeddings
26
+ token1 = "<prompt_guard_1>"
27
+ token2 = "<prompt_guard_2>"
28
+ ...
29
+ token_list = [token1, token2, ...] # the corresponding tokens of your embeddings
30
+
31
+ pipe.load_textual_inversion(pretrained_model_name_or_path=safe_embedding_list, token=token_list)
32
+
33
+ origin_prompt = "a photo of a dog"
34
+ prompt_with_system = origin_prompt + " " + token1 + " " + token2 + ...
35
+ image = pipe(prompt).images[0]
36
+ image.save("example.png")
37
+ ```