Spaces:
Sleeping
Sleeping
File size: 6,837 Bytes
b5de3c9 |
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
from typing import Dict, List, Tuple, Union
quality_prompt_list = [
{
"name": "(None)",
"prompt": "{prompt}",
"negative_prompt": "nsfw, lowres",
},
{
"name": "Standard v3.0",
"prompt": "{prompt}, masterpiece, best quality",
"negative_prompt": "nsfw, lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, artist name",
},
{
"name": "Standard v3.1",
"prompt": "{prompt}, masterpiece, best quality, very aesthetic, absurdres",
"negative_prompt": "nsfw, lowres, (bad), text, error, fewer, extra, missing, worst quality, jpeg artifacts, low quality, watermark, unfinished, displeasing, oldest, early, chromatic aberration, signature, extra digits, artistic error, username, scan, [abstract]",
},
{
"name": "Light v3.1",
"prompt": "{prompt}, (masterpiece), best quality, very aesthetic, perfect face",
"negative_prompt": "nsfw, (low quality, worst quality:1.2), very displeasing, 3d, watermark, signature, ugly, poorly drawn",
},
{
"name": "Heavy v3.1",
"prompt": "{prompt}, (masterpiece), (best quality), (ultra-detailed), very aesthetic, illustration, disheveled hair, perfect composition, moist skin, intricate details",
"negative_prompt": "nsfw, longbody, lowres, bad anatomy, bad hands, missing fingers, pubic hair, extra digit, fewer digits, cropped, worst quality, low quality, very displeasing",
},
]
style_list = [
{
"name": "(None)",
"prompt": "{prompt}",
"negative_prompt": "",
},
{
"name": "Cinematic",
"prompt": "{prompt}, cinematic still, emotional, harmonious, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy",
"negative_prompt": "nsfw, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured",
},
{
"name": "Photographic",
"prompt": "{prompt}, cinematic photo, 35mm photograph, film, bokeh, professional, 4k, highly detailed",
"negative_prompt": "nsfw, drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly",
},
{
"name": "Anime",
"prompt": "{prompt}, anime artwork, anime style, key visual, vibrant, studio anime, highly detailed",
"negative_prompt": "nsfw, photo, deformed, black and white, realism, disfigured, low contrast",
},
{
"name": "Manga",
"prompt": "{prompt}, manga style, vibrant, high-energy, detailed, iconic, Japanese comic style",
"negative_prompt": "nsfw, ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, Western comic style",
},
{
"name": "Digital Art",
"prompt": "{prompt}, concept art, digital artwork, illustrative, painterly, matte painting, highly detailed",
"negative_prompt": "nsfw, photo, photorealistic, realism, ugly",
},
{
"name": "Pixel art",
"prompt": "{prompt}, pixel-art, low-res, blocky, pixel art style, 8-bit graphics",
"negative_prompt": "nsfw, sloppy, messy, blurry, noisy, highly detailed, ultra textured, photo, realistic",
},
{
"name": "Fantasy art",
"prompt": "{prompt}, ethereal fantasy concept art, magnificent, celestial, ethereal, painterly, epic, majestic, magical, fantasy art, cover art, dreamy",
"negative_prompt": "nsfw, photographic, realistic, realism, 35mm film, dslr, cropped, frame, text, deformed, glitch, noise, noisy, off-center, deformed, cross-eyed, closed eyes, bad anatomy, ugly, disfigured, sloppy, duplicate, mutated, black and white",
},
{
"name": "Neonpunk",
"prompt": "{prompt}, neonpunk style, cyberpunk, vaporwave, neon, vibes, vibrant, stunningly beautiful, crisp, detailed, sleek, ultramodern, magenta highlights, dark purple shadows, high contrast, cinematic, ultra detailed, intricate, professional",
"negative_prompt": "nsfw, painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured",
},
{
"name": "3D Model",
"prompt": "{prompt}, professional 3d model, octane render, highly detailed, volumetric, dramatic lighting",
"negative_prompt": "nsfw, ugly, deformed, noisy, low poly, blurry, painting",
},
]
_style_dict = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
_quality_dict = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in quality_prompt_list}
def preprocess_prompt(
positive: str,
negative: str = "",
style_dict: Dict[str, dict] = _quality_dict,
style_name: str = "Standard v3.1", # "Heavy v3.1"
add_style: bool = True,
) -> Tuple[str, str]:
p, n = style_dict.get(style_name, style_dict["(None)"])
if add_style and positive.strip():
formatted_positive = p.format(prompt=positive)
else:
formatted_positive = positive
combined_negative = n
if negative.strip():
if combined_negative:
combined_negative += ", " + negative
else:
combined_negative = negative
return formatted_positive, combined_negative
def preprocess_prompts(
positives: List[str],
negatives: List[str] = None,
style_dict = _style_dict,
style_name: str = "Manga", # "(None)"
quality_dict = _quality_dict,
quality_name: str = "Standard v3.1", # "Heavy v3.1"
add_style: bool = True,
add_quality_tags = True,
) -> Tuple[List[str], List[str]]:
if negatives is None:
negatives = ['' for _ in positives]
positives_ = []
negatives_ = []
for pos, neg in zip(positives, negatives):
pos, neg = preprocess_prompt(pos, neg, quality_dict, quality_name, add_quality_tags)
pos, neg = preprocess_prompt(pos, neg, style_dict, style_name, add_style)
positives_.append(pos)
negatives_.append(neg)
return positives_, negatives_
def print_prompts(
positives: Union[str, List[str]],
negatives: Union[str, List[str]],
has_background: bool = False,
) -> None:
if isinstance(positives, str):
positives = [positives]
if isinstance(negatives, str):
negatives = [negatives]
for i, prompt in enumerate(positives):
prefix = ((f'Prompt{i}' if i > 0 else 'Background Prompt')
if has_background else f'Prompt{i + 1}')
print(prefix + ': ' + prompt)
for i, prompt in enumerate(negatives):
prefix = ((f'Negative Prompt{i}' if i > 0 else 'Background Negative Prompt')
if has_background else f'Negative Prompt{i + 1}')
print(prefix + ': ' + prompt)
|