-
Notifications
You must be signed in to change notification settings - Fork 3
/
embed_decode.py
70 lines (61 loc) · 2.14 KB
/
embed_decode.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
# This python code decodes discord sd_embeds and returns them as a payload for the stable diffusion api.
from random import randint
from prompt_parser import parse_ez_negative
async def decode(input_dict):
# parse footer
footer = input_dict["footer"]["text"]
footer_values = {}
for item in footer.split(" • "):
key, value = item.split(":")
footer_values[key.strip()] = float(value.strip())
# parse description
prompt_start = input_dict['description'].find("prompt:") + len("prompt:")
prompt_end = input_dict['description'].find("negative:")
prompt = input_dict['description'][prompt_start:prompt_end].strip()
neg_prompt_start = input_dict['description'].find(
"negative:") + len("negative:")
negative_prompt = input_dict['description'][neg_prompt_start:].strip()
# parse ez negative
if "easy_negative" in prompt:
prompt = parse_ez_negative(prompt)
# generate new seed
footer_values["seed"] = randint(0, 2 ** 32 - 1)
# create payload
payload = {
"enable_hr": False,
"denoising_strength": 0,
"firstphase_width": 0,
"firstphase_height": 0,
"hr_scale": 2,
"hr_upscaler": "",
"hr_second_pass_steps": 0,
"hr_resize_x": 0,
"hr_resize_y": 0,
"prompt": prompt,
"styles": [],
"seed": footer_values.get("seed", -1),
"subseed": -1,
"subseed_strength": 0,
"seed_resize_from_h": -1,
"seed_resize_from_w": -1,
"sampler_name": "",
"batch_size": 1,
"n_iter": 1,
"steps": footer_values.get("steps", 20),
"cfg_scale": footer_values.get("cfg_scale", 7),
"width": footer_values.get("width", 512),
"height": footer_values.get("height", 512),
"restore_faces": False,
"tiling": False,
"negative_prompt": negative_prompt,
"eta": 0,
"s_churn": 0,
"s_tmax": 0,
"s_tmin": 0,
"s_noise": 1,
"override_settings": {},
"override_settings_restore_afterwards": True,
"script_args": [],
"sampler_index": "Euler"
}
return payload