forked from cloneofsimo/paint-with-words-sd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.py
81 lines (68 loc) · 2.57 KB
/
runner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import math
import dotenv
from PIL import Image
from paint_with_words import paint_with_words
EXAMPLE_SETTING_1 = {
"color_context": {
(0, 0, 0): "cat,1.0",
(255, 255, 255): "dog,1.0",
(13, 255, 0): "tree,1.5",
(90, 206, 255): "sky,0.2",
(74, 18, 1): "ground,0.2",
},
"color_map_img_path": "contents/example_input.png",
"input_prompt": "realistic photo of a dog, cat, tree, with beautiful sky, on sandy ground",
"output_img_path": "contents/output_cat_dog.png",
}
EXAMPLE_SETTING_2 = {
"color_context": {
(0, 0, 0): "dog,1.0",
(255, 255, 255): "cat,1.0",
(13, 255, 0): "tree,1.5",
(90, 206, 255): "sky,0.2",
(74, 18, 1): "ground,0.2",
},
"color_map_img_path": "contents/example_input.png",
"input_prompt": "realistic photo of a dog, cat, tree, with beautiful sky, on sandy ground",
"output_img_path": "contents/output_dog_cat.png",
}
EXAMPLE_SETTING_3 = {
"color_context": {
(7, 9, 182): "aurora,0.5",
(136, 178, 92): "full moon,1.5",
(51, 193, 217): "mountains,0.4",
(61, 163, 35): "a half-frozen lake,0.3",
(89, 102, 255): "boat,2.0",
},
"color_map_img_path": "contents/aurora_2.png",
"input_prompt": "A digital painting of a half-frozen lake near mountains under a full moon and aurora. A boat is in the middle of the lake. Highly detailed.",
"output_img_path": "contents/aurora_2_output.png",
}
EXAMPLE_SETTING_4 = {
"color_context": {
(7, 9, 182): "aurora,0.5",
(136, 178, 92): "full moon,1.5",
(51, 193, 217): "mountains,0.4",
(61, 163, 35): "a half-frozen lake,0.3",
(89, 102, 255): "boat,2.0",
},
"color_map_img_path": "contents/aurora_1.png",
"input_prompt": "A digital painting of a half-frozen lake near mountains under a full moon and aurora. A boat is in the middle of the lake. Highly detailed.",
"output_img_path": "contents/aurora_1_output.png",
}
if __name__ == "__main__":
dotenv.load_dotenv()
settings = EXAMPLE_SETTING_3
color_map_image = Image.open(settings["color_map_img_path"]).convert("RGB")
color_context = settings["color_context"]
input_prompt = settings["input_prompt"]
img = paint_with_words(
color_context=color_context,
color_map_image=color_map_image,
input_prompt=input_prompt,
num_inference_steps=30,
guidance_scale=7.5,
device="cuda:0",
weight_function=lambda w, sigma, qk: 0.4 * w * math.log(1 + sigma) * qk.max(),
)
img.save(settings["output_img_path"])