File size: 12,576 Bytes
90ff9b8
f59cabb
 
 
 
 
 
 
90ff9b8
f59cabb
5bde2c8
f59cabb
 
 
 
 
 
 
 
5bde2c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f59cabb
528532c
 
 
a5ad31b
528532c
 
 
 
 
a5ad31b
 
528532c
 
 
 
 
 
 
 
 
 
 
 
 
a5ad31b
 
 
528532c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a5ad31b
 
528532c
 
5bde2c8
 
528532c
 
5bde2c8
528532c
5bde2c8
 
528532c
 
 
 
 
 
 
a5ad31b
528532c
 
 
 
 
 
 
 
 
 
 
 
a5ad31b
528532c
 
5bde2c8
528532c
 
a5ad31b
 
528532c
 
a5ad31b
 
 
 
 
528532c
a5ad31b
f59cabb
 
528532c
 
f59cabb
5bde2c8
 
 
 
 
 
 
 
 
 
f59cabb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5bde2c8
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
---
license: unlicense
language:
- en
library_name: diffusers
pipeline_tag: text-generation
tags:
- art
---
# REM sleep priming anime
A Python script that will generates the prompt unconditionally to increase the variation without any LLM bias; by my custom-made PCG64 PRNG. Iterated and tested with [cagliostrolab/animagine-xl-3.1](https://huggingface.co/spaces/cagliostrolab/animagine-xl-3.1) spaces. Not all the generated detail in the prompt works, this is due to the model lacking the dataset to understand it. And, not the script is not working. To use it, run the script and copy the printed output.  
Examples:
```
1girl, early, creative, lifting, red-purple bangs haircut, green wolf eyes, earrings, navy blue and tan outfit, crewneck, flare jeans, high-angle shot, colonies on other planets, crepuscular rays
```

### Code
```py
import functools
import time


class PCG64:
	# https://www.pcg-random.org/download.html#id1
	# Less biased than MT19937 or `random.randint`!
	def __init__(self, seed=time.time_ns()):
		self._state = seed

	def random(self):
		old_state = self._state
		self._state = (self._state * 6364136223846793005) & 0xffffffffffffffff
		xorshifted = (((old_state >> 18) ^ old_state) >> 27) & 0xffffffffffffffff
		rot = old_state >> 59
		result = (xorshifted >> rot) | (xorshifted << (-rot & 31))
		return result & 0xffffffffffffffff

	def randint(self, begin, end):
		return self.random() % (1 + end - begin) + begin


class REMSleepPrmAnime:
	def __init__(self):
		# Time
		self.year_ranges = {"both": {"newest", "recent", "mid", "early", "oldest"}}

		# --- Subject
		# Head
		self.haircuts = {"both": {"bob", "pixie", "cut", "shaggy", "layers", "mullet", "afro", "fringe", "bangs", "quiff", "undercut", "braids", "knot", "ponytail", "curls", "blunt", "perm", "fade", "crop", "bowl", "curtain", "top", "balayage", "shag", "bang", "waves"},
				"male": {"mohawk", "dreadlocks"}}
		self.eye_colors = {"both": {"blue", "red", "yellow", "green", "orange", "red-orange", "yellow-orange", "yellow-green", "blue-green"} \
				| {"gray", "amber", "hazel", "gold", "silver"},
				"female": {"pink", "purple", "red-purple", "blue-purple"}}
		self.eye_shapes = {"both": {"normal", "large", "moe", "realistic", "cat", "wolf", "dog", "bird", "no irises", "heterochromia", "glowing", "small", "starburst pupils", "googly", "tearful", "chibi"}, "female": {"shoujo"}}
		self.blush = {"female": {"blush"}}
		self.eyebrow_shapes = {"both": {"straight", "curved", "angular", "thick", "thin", "high arched", "low arched", "rounded", "uneven"}}
		self.lips_shapes = {"both": {"small", "wide", "round"}}
		self.nose_shapes = {"both": {"aquiline", "straight", "bulbous", "button", "hooked", "flat", "snub", "roman", "turned up", "pointy"}}
		self.earrings = {"both": {"earrings"}}

		# Outfit
		self.outfit_colors = {"both": {"orange and white", "pale lilac and medium lavender", "hunter green and medium brown", "red and green", "navy blue and mustard yellow", "dark green and tan", "navy and white", "burgundy and gray", "burgundy and light brown", "navy blue and tan", "golden yellow and medium blue", "red and mustard yellow", "yellow and white", "maroon and gray", "black and white", "seal brown and tan", "charcoal gray and white", "blue-green and coral", "sky blue and charcoal gray", "red and light blue", "medium blue and chocolate brown", "medium green and white", "red and taupe", "red and mint green", "slate blue and warm white", "beige and maroon", "yellow and blue", "blue and orange", "pastel blue and yellow-orange", "bright blue and soft gray", "red and gray", "red and cyan", "red and yellow", "cerulean and neon green", "neon green and neon yellow", "navy blue and red", "sherbet orange and cool gray", "olive green and yellow", "yellow and deep sky blue", "dark brown and light blue", "magenta and charcoal", "red and white", "yellow and forest green", "light blue and navy blue", "orange and yellow", "charcoal grey and light blue", "pale coral and tan", "mauve-gray and olive", "yellow-orange and burnt orange", "orange and brown", "navy and light blue", "red and orange", "green and yellow", "gray and black", "green and blue", "teal and navy blue", "magenta and yellow", "yellow and brown", "red and black", "orange and green", "clay red and cerulean", "bright red and army green", "black and gray", "orange and black", "sage green and tan", "blue and turquoise", "beige and brown", "red and earthy browns", "dark green and gray", "blue and cyan", "olive green and navy blue", "olive green and maroon", "yellow and warm gray", "green and earthy browns", "burgundy and light blue", "khaki and pastel yellow", "taupe and white", "sky blue and royal blue", "orange and gray", "olive green and beige", "beige and blue", "burnt orange and hunter green", "blue and red", "navy blue and khaki"},
				"female": {"blush pink and white", "pink and red", "pink and orange", "gray and light pink", "dark green and pink", "pink and warm black", "pink and blue", "medium pink and red", "rose pink and periwinkle", "yellow and pink", "purple and pink", "pink and turquoise", "pink and green", "navy blue and pink", "purple and charcoal gray", "turquoise and purple", "purple and yellow", "electric purple and black", "purple and orange", "green and purple", "red and purple"}}
		self.tops = {"female": {"t-shirts", "blouses", "tunics", "camisoles", "tank tops", "crewneck", "v-neck", "cardigan", "turtleneck", "pullovers", "henleys", "crop tops", "off-the-shoulder tops", "cold shoulder tops", "peplum tops"}}
		self.bottoms = {"both": {"shorts", "chinos", "cargo pants"},
				"female": {"skinny jeans", "straight jeans", "bootcut jeans", "flare jeans", "wide-leg jeans", "bermuda shorts", "hotpants", "A-line skirts", "pencil skirts", "maxi skirts", "midi skirts", "mini skirts", "dress pants", "linen pants", "capris"} \
				| {"stockings", "tights", "fishnets", "leggings", "yoga pants"}}
		self.one_pieces = {"female": {"jumpsuits", "rompers", "swimsuits", "bodysuits"}}

		# Personality
		self.personality_traits = {"both": {"creative", "determined", "enthusiastic", "friendly", "generous", "humorous", "intelligent", "kind", "loyal", "motivated", "optimistic", "persistent", "resilient", "sincere", "thoughtful", "trustworthy", "versatile", "compassionate", "ambitious", "confident", "honest", "brave", "patient", "reliable", "adventurous", "charismatic", "gracious", "insightful", "perceptive", "resourceful", "selfless", "talented", "witty", "zealous"}}

		# Actions
		self.actions = {"both": {"walking", "running", "squatting", "crawling", "riding", "speaking", "dancing", "waving", "listening", "reading", "pulling", "carrying", "studying", "bending", "writing", "lifting", "sleeping", "lying down", "pushing", "drinking", "clapping", "playing", "typing", "reaching", "working", "climbing", "jumping", "swimming", "kneeling", "watching", "standing", "eating"}}
		# ---

		# Camera angles
		self.camera_angels = {"both": {"low-angle", "eye level", "high-angle", "hip level", "knee level", "ground level", "shoulder level", "dutch angle", "overhead", "aerial"}}

		# Places and eras
		self.places = {"both": {"school", "skyscrapers", "neon lights", "crowded streets", "medieval kingdoms", "magical forests", "post-apocalyptic wastelands", "spaceships", "colonies on other planets", "vinland saga", "haunted houses", "cursed islands", "mystical dimensions", "training grounds", "stadiums", "arenas"}}
		self.eras = {"both": {"meiji period", "edo period"}}

		# Styles
		self.resolutions = {"both": {"sharp focus", "8k"}}
		self.lightings = {"both": {"rim lighting", "flat lighting", "cinematic lighting", "crepuscular rays"}}

	def main(self):
		rng = PCG64()

		def get_random_x(x, gender=["both"]):
			concat = sum([list(x.get(ge, [])) for ge in gender], [])
			return concat[rng.randint(0, len(concat) - 1)] if len(concat) else ""

		rand50 = lambda: rng.randint(1, 100) <= 50
		rand75 = lambda: rng.randint(1, 100) <= 75

		gender = "1girl" if rand50() else "1boy"
		gender_selection = ["both"] + ["female" if gender == "1girl" else "male"]
		get_random_x_by_gender = functools.partial(get_random_x, gender=gender_selection)

		commands = (
			# You must put trailing comma to convert a parenthesized expression into a tuple
			(self.year_ranges,),
			(self.personality_traits if rand50() else None,),
			(self.actions,),

			(self.eye_colors, self.haircuts, "haircut",),
			(self.eye_colors, self.eye_shapes, "eyes",),
			(self.blush if rand50() else None,),
			# (self.eyebrow_shapes, "eyebrows",), # Diffusers are bad at drawing eyebrows
			# (self.lips_shapes, "lips",), # Diffusers are bad at drawing lips
			# (self.nose_shapes, "nose",), # Diffusers are bad at drawing nose
			(self.earrings if rand50() else None,),

			(self.outfit_colors, "outfit",),
			*(((self.one_pieces,),) if rand50() else ((self.tops,), (self.bottoms,))),

			(self.camera_angels, "shot",),
			((self.places,) if rand75() else (self.eras,)),

			# ("masterpiece",), ("best quality",), ("very aesthetic",), ("absurdres",), # Already prepended
			(self.resolutions if rand50() else None,),
			(self.lightings if rand50() else None,),
		)

		output = [gender] + [" ".join(
			get_random_x_by_gender(elem) if isinstance(elem, dict) else elem
			for elem in cmd
			if elem is not None and isinstance(elem, (str, dict))
		) for cmd in commands]

		return ", ".join(filter(lambda s: s != "", output))

if __name__ == "__main__":
	prompt_generator = REMSleepPrmAnime()
	[print(prompt_generator.main()) for _ in range(1)]
```
### Contributing
I prefer every new strings/keywords are stored per line, or stored in CSV or JSON; don't send me binary files.  
A file (fruits.csv) per variable CSV example:
```
color,fruit
orange,orange,mandarins,papaya
red,apple,strawberries,tomatoes
purple,grape,plums,blackberries
```
### Examples
![image/png](https://cdn-uploads.huggingface.co/production/uploads/6557be93e0a6202d3613b651/sP7PGb0S75jRvP5HAki2G.png)
```json
{
  "prompt": "1girl, newest, resourceful, sleeping, pink bowl haircut, yellow eyes, earrings, blue-green and coral outfit, pullovers, hotpants, eye level shot, colonies on other planets, 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]",
  "resolution": "896 x 1152",
  "guidance_scale": 7,
  "num_inference_steps": 12,
  "seed": 1085670190,
  "sampler": "Euler a",
  "sdxl_style": "(None)",
  "add_quality_tags": true,
  "quality_tags": "Standard v3.1",
  "use_upscaler": null,
  "model": "Animagine XL 3.1"
}
```

![image/png](https://cdn-uploads.huggingface.co/production/uploads/6557be93e0a6202d3613b651/FMnCBT9DsP9b3tFB8ql3D.png)
```json
{
  "prompt": "1girl, recent, lying down, yellow bob haircut, red-orange dog eyes, earrings, red and light blue outfit, crewneck, maxi skirts, shoulder level shot, haunted houses, sharp focus, crepuscular rays, 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]",
  "resolution": "896 x 1152",
  "guidance_scale": 7,
  "num_inference_steps": 12,
  "seed": 1000102344,
  "sampler": "Euler a",
  "sdxl_style": "(None)",
  "add_quality_tags": true,
  "quality_tags": "Standard v3.1",
  "use_upscaler": null,
  "model": "Animagine XL 3.1"
}
```

![image/png](https://cdn-uploads.huggingface.co/production/uploads/6557be93e0a6202d3613b651/QRqAwhRVPGUNcWZN8taqt.png)
```json
{
  "prompt": "1girl, recent, honest, lifting, green crop haircut, silver eyes, green and blue outfit, swimsuits, eye level shot, mystical dimensions, crepuscular rays, 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]",
  "resolution": "896 x 1152",
  "guidance_scale": 5,
  "num_inference_steps": 12,
  "seed": 2033092933,
  "sampler": "Euler a",
  "sdxl_style": "(None)",
  "add_quality_tags": true,
  "quality_tags": "Standard v3.1",
  "use_upscaler": null,
  "model": "Animagine XL 3.1"
}
```