Skip to content

Commit ee95e86

Browse files
committedSep 10, 2023
Add embeddings
1 parent c7b586e commit ee95e86

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed
 

‎README.md

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ envsubst < script/download-weights > $MODEL_NAME/script/download-weights
4444
sudo chmod +x $MODEL_NAME/script/download-weights
4545
envsubst < cog.yaml > $MODEL_NAME/cog.yaml
4646

47+
# download negative embeddings
48+
mkdir embeddings/ && cd embeddings/ && wget -O FastNegativeV2.pt "https://civitai.com/api/download/models/94057?type=Model&format=PickleTensor" && wget -O BadDream.pt "https://civitai.com/api/download/models/77169?type=Model&format=PickleTensor" && wget -O UnrealisticDream.pt "https://civitai.com/api/download/models/77173?type=Model&format=PickleTensor" && wget -O EasyNegative.pt "https://civitai.com/api/download/models/9536?type=Model&format=PickleTensor&size=full&fp=fp16" && wget -O ng_deepnegative_v1_75t.pt "https://civitai.com/api/download/models/5637?type=Model&format=PickleTensor&size=full&fp=fp16" && wget -O negative_hand-neg.pt "https://civitai.com/api/download/models/60938?type=Negative&format=Other" && wget -O realisticvision-negative-embedding.pt "https://civitai.com/api/download/models/42247?type=Model&format=Other"
49+
50+
4751
# cog login
4852
cd $MODEL_NAME
4953
git clone https://huggingface.co/pagebrain/$MODEL_NAME model

‎predict.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ def from_config(config):
4242
"KLMS": LMSDiscreteScheduler,
4343
}
4444

45+
EMBEDDINGS = [(x.split(".")[0], "/embeddings/"+x) for x in os.listdir("/embeddings/")]
46+
EMBEDDING_TOKENS = [x[0] for x in EMBEDDINGS]
47+
EMBEDDING_PATHS = [x[1] for x in EMBEDDINGS]
4548

46-
47-
MODEL_ID = "pagebrain/$MODEL_NAME"
49+
MODEL_ID = "pagebrain/realistic-vision-v5-1"
4850
MODEL_CACHE = "diffusers-cache"
4951
SAFETY_MODEL_ID = "CompVis/stable-diffusion-safety-checker"
5052

@@ -67,23 +69,24 @@ def run_safety_checker(self, image):
6769
def setup(self):
6870
"""Load the model into memory to make running multiple predictions efficient"""
6971
self.safety_checker = StableDiffusionSafetyChecker.from_pretrained(
70-
"./model/safety_checker",
72+
"/model/safety_checker",
7173
# cache_dir=MODEL_CACHE,
7274
local_files_only=True,
7375
torch_dtype=torch.float16,
7476
).to("cuda")
7577

76-
self.feature_extractor = CLIPImageProcessor.from_pretrained("./model/feature_extractor")
78+
self.feature_extractor = CLIPImageProcessor.from_pretrained("/model/feature_extractor")
7779

7880
print("Loading txt2img pipeline...")
7981
self.txt2img_pipe = StableDiffusionPipeline.from_pretrained(
80-
"./model/",
82+
"/model/",
8183
# cache_dir=MODEL_CACHE,
8284
local_files_only=True,
8385
use_safetensors=True,
8486
safety_checker=None,
8587
requires_safety_checker=False
8688
)
89+
self.txt2img_pipe.load_textual_inversion(EMBEDDING_PATHS, token=EMBEDDING_TOKENS, local_files_only=True)
8790
self.txt2img_pipe.to("cuda")
8891

8992
print("Loading img2img pipeline...")
@@ -124,7 +127,7 @@ def predict(
124127
default=None,
125128
),
126129
negative_prompt: str = Input(
127-
description="Specify things to not see in the output",
130+
description="Specify things to not see in the output. Supported embeddings: " + ", ".join(EMBEDDING_TOKENS),
128131
default=None,
129132
),
130133
image: Path = Input(

‎script/download-weights

+9-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ from diffusers.pipelines.stable_diffusion.safety_checker import (
88
)
99
import torch
1010

11+
EMBEDDINGS = [(x.split(".")[0], "/embeddings/"+x) for x in os.listdir("/embeddings/")]
12+
EMBEDDING_TOKENS = [x[0] for x in EMBEDDINGS]
13+
EMBEDDING_PATHS = [x[1] for x in EMBEDDINGS]
14+
print(EMBEDDING_TOKENS, EMBEDDING_PATHS)
15+
1116
MODEL_ID = "pagebrain/$MODEL_NAME"
1217
MODEL_CACHE = "diffusers-cache"
1318

@@ -16,15 +21,17 @@ MODEL_CACHE = "diffusers-cache"
1621
# os.makedirs(MODEL_CACHE, exist_ok=True)
1722

1823
saftey_checker = StableDiffusionSafetyChecker.from_pretrained(
19-
"./model/safety_checker",
24+
"/model/safety_checker",
2025
# cache_dir=MODEL_CACHE,
2126
# use_safetensors=True
2227
torch_dtype=torch.float16,
2328
)
2429

2530
pipe = StableDiffusionPipeline.from_pretrained(
26-
"./model",
31+
"/model",
2732
# cache_dir=MODEL_CACHE,
2833
use_safetensors=True,
2934
safety_checker=None
3035
)
36+
37+
pipe.load_textual_inversion(EMBEDDING_PATHS, token=EMBEDDING_TOKENS, local_files_only=True)

0 commit comments

Comments
 (0)
Please sign in to comment.