dahara1 commited on
Commit
b2ab2f7
·
verified ·
1 Parent(s): dc6aefd

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +252 -0
README.md CHANGED
@@ -11,3 +11,255 @@ base_model:
11
  see [webbigdata/FanFic-Illustrator](https://huggingface.co/webbigdata/FanFic-Illustrator).
12
 
13
  later, I will add sample script.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  see [webbigdata/FanFic-Illustrator](https://huggingface.co/webbigdata/FanFic-Illustrator).
12
 
13
  later, I will add sample script.
14
+
15
+
16
+ ```
17
+ python launch.py --api --no-half-vae --medvram --xformers &
18
+ ```
19
+
20
+
21
+ ```
22
+ ./llama.cpp/build/bin/llama-server -m FanFic-Illustrator-Q6_K-f16.gguf -c 5000
23
+ ```
24
+
25
+
26
+
27
+ sample client_script.py
28
+ ```
29
+ import transformers
30
+ from PIL import Image
31
+ import io
32
+ import base64
33
+ import requests
34
+ import json
35
+ from transformers import AutoTokenizer
36
+ tokenizer = AutoTokenizer.from_pretrained("webbigdata/FanFic-Illustrator")
37
+
38
+ COMMON_QUALITY_PROMPT = ", masterpiece, high score, great score, absurdres"
39
+ COMMON_NEGATIVE_PROMPT = "lowres, bad anatomy, bad hands, text, error, missing finger, extra digits, fewer digits, cropped, worst quality, low quality, low score, bad score, average score, signature, watermark, username, blurry"
40
+
41
+
42
+ def generate_image(prompt, negative_prompt, output_path):
43
+ url = "http://localhost:7860/sdapi/v1/txt2img"
44
+
45
+ prompt = prompt.replace("(", "\\(").replace(")", "\\)")
46
+
47
+ payload = {
48
+ "prompt": prompt,
49
+ "negative_prompt": negative_prompt,
50
+ "steps": 28,
51
+ "cfg_scale": 5,
52
+ "width": 832,
53
+ "height": 1216,
54
+ "sampler_name": "Euler a",
55
+ "sampler_index": "Euler a",
56
+ "override_settings": {
57
+ "sd_model_checkpoint": "animagine-xl-4.0-opt.safetensors",
58
+ "sd_vae": "sdxl_vae.safetensors"
59
+ },
60
+ "enable_hr": False,
61
+ "batch_size": 1,
62
+ "do_not_save_samples": True,
63
+ "seed": -1,
64
+ }
65
+
66
+ response = requests.post(url=url, json=payload)
67
+ response.raise_for_status()
68
+ r = response.json()
69
+
70
+ image = Image.open(io.BytesIO(base64.b64decode(r['images'][0])))
71
+ image.save(output_path)
72
+
73
+ return True
74
+
75
+
76
+ def get_novel_data():
77
+ return """Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, "and what is the use of a book," thought Alice "without pictures or conversations?"
78
+ So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her.
79
+ There was nothing so very remarkable in that; nor did Alice think it so very much out of the way to hear the Rabbit say to itself, "Oh dear! Oh dear! I shall be late!" (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually took a watch out of its waistcoat-pocket, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge.
80
+ In another moment down went Alice after it, never once considering how in the world she was to get out again.
81
+ The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that Alice had not a moment to think about stopping herself before she found herself falling down a very deep well."""
82
+
83
+ if __name__ == "__main__":
84
+
85
+ novel_text = get_novel_data()
86
+ category = "general"
87
+ series_name = "alice in wonderland"
88
+ series_description = "A fantasy novel written by Lewis Carroll (Charles Lutwidge Dodgson) in 1865. The story follows a young girl named Alice who falls through a rabbit hole into a fantastical world populated by peculiar anthropomorphic creatures. The tale plays with logic, giving the story lasting popularity with adults as well as children. It is considered one of the best examples of the literary nonsense genre and its narrative, structure, characters, and imagery have been enormously influential in both popular culture and literature."
89
+ character_name = "alice (alice in wonderland)"
90
+ character_description = "A curious, polite, and logical seven-year-old girl with an imagination and a sense of wonder. Alice finds herself in a world that challenges her perceptions of reality and proper behavior. Throughout her journey in Wonderland, she encounters absurd situations and characters that test her patience and understanding. Despite her confusion, Alice maintains her rational thinking and often attempts to apply real-world logic to the nonsensical Wonderland. She is characterized by her curiosity, bravery, and her struggle to maintain her identity in a world where nothing makes sense."
91
+
92
+ system_prompt = "あなたは文章の一説を指定ジャンル・キャラクターが登場するシーンに書き換え、そのシーンに合った挿絵を作成するために画像生成AI用プロンプ���を作成する優秀なプロンプトエンジニアです"
93
+
94
+ user_prompt = f"""### 小説のコンテキストを補足する情報
95
+ content category: {category}
96
+ series name: {series_name}
97
+ series description: {series_description}
98
+ character name: {character_name}
99
+ character description: {character_description}
100
+
101
+ ### 小説データ
102
+ {novel_text}
103
+
104
+ まず<think>内で以下のように思考を整理します。
105
+
106
+ <think>
107
+ concept: イラストのコンセプトを考えます。小説の内容から主題、設定、雰囲気を理解し、どのようなイラストが最も適切か、全体の構成を考えます
108
+ - 人数: 挿絵の中に登場させる人数を考えます。作品に登場する人物の数や重要性を考慮し、メインで描くべき人物やサブキャラクターについても検討してください
109
+ - キャラクター名/シリーズ名: 既存作品のキャラクター/シリーズか、オリジナル作品かを考えます。既存作品の場合は、原作の設定や特徴を尊重した表現方法も考慮してください
110
+ - ポーズ/構図: ポーズ/構図指定に使うタグを考えます。物語の場面において、キャラクターがどのような体勢/状況にあるのか、どのアングルから描くと効果的かを検討してください
111
+ - 背景/環境: 背景/環境指定に使うタグを考えます。物語の舞台設定や時間帯、天候など、雰囲気を表現するために必要な背景要素を詳しく考えてください
112
+ - 描画スタイル/テクニック: 描画スタイル/テクニックに使うタグを考えます。物語のジャンルや雰囲気に合わせて、どのような画風や技法が適しているかを検討してください
113
+ - 身体的特徴/画面上の物体: 身体的特徴/画面上の物体に関連するタグを考えます。キャラクターの外見的特徴や、シーンに必要な小道具、アイテムなどを詳細に考えてください
114
+ </think>
115
+
116
+ 改行の場所も含めて、この順序と書式を厳密に守ってください。
117
+ 各項目は上記の順序と書式で記述してください。具体的かつ詳細に説明し、十分な長さで考察してください(<think>タグ全体で600-800文字程度が望ましいです)
118
+
119
+ その後、思考結果に基づき<prompt>内に英単語を18単語ほどカンマで区切って出力してください。キャラクター名/シリーズ名は指定されていたら必ず含めます
120
+ 日本語は使用しないでください。 最も重要で適切なタグを選び、有効なプロンプトとなるよう考慮してください
121
+
122
+ ### 使用可能な英単語
123
+ 出力時には以下のタグを優先して使用し、足りない場合は一般的な英単語で補足します
124
+ masterpiece, best quality, highresなどの品質に関連するタグは後工程で付与するのでつけてはいけません
125
+
126
+ **人数/性別**:
127
+ - 風景や動物を中心に描画する時: no_human
128
+ - 女性の人数: 1girl, 2girls, 3girls, multiple girls
129
+ - 男性の人数: 1boy, 2boys, 3boys, multiple boys
130
+ - 1girlや1boy指定時にキャラクター中心の構図にするために追加で指定: solo
131
+
132
+ **ポーズ/構図**:
133
+ - 視点: from above, from behind, from below, looking at viewer, straight-on, looking at another, looking back, out of frame, on back, from side, looking to the side, feet out of frame, sideways, three quarter view, looking up, looking down, looking ahead, dutch angle, high up, from outside, pov, vanishing point
134
+ - 姿勢/行動: battle, chasing, fighting, leaning, running, sitting, squatting, standing, walking, arm up, arms up, against wall, against tree, holding, spread legs, lying, straddling, flying, holding weapon, clothes lift, hand on own cheek, scar on cheek, hand on another's cheek, kissing cheek, cheek-to-cheek, bandaid on cheek, finger to cheek, hands on another's cheeks, hand on own hip, hand over face, v, kneeling, arabesque (pose), body roll, indian style, standing on one leg, hugging own legs, seiza, nuzzle, unsheathing, holding weapon, holding sword, holding gun, trembling
135
+
136
+ **背景/環境**:
137
+ - 構図/芸術ジャンル: landscape, portrait, still life, group shot, cowboy shot, upper body, full body, detailed face, depth of field, intricate details, cinematic lighting, detailed background, detailed, extremely detailed, perfect composition, detailed face, solo focus, detailed face and body, character focus, intricate, sharp focus, male focus
138
+ - 色彩/装飾: greyscale, sepia, blue theme, flat color, high contrast, limited palette, border, cinematic, scenery, rendered, contrast, rich contrast, volumetric lighting, high contrast, glowing
139
+ - 背景/風景: checkered background, simple background, indoors, outdoors, jungle, mountain, beach, forest, city, school, cafe, white background, sky
140
+ - 時間帯: day, night, twilight, morning, sunset, dawn, dusk
141
+ - 天気: sunny, rain, snow, cloud, storm, wind, fogg
142
+
143
+ **描画スタイル/テクニック**:
144
+ - 技法: 3D, oekaki, pixel art, sketch, watercolor, oil painting, digital art, illustration, photorealistic, anime, monochrome, retro color, source anime, cg, realistic
145
+ - 表現手法: animalization, personification, science fiction, cyberpunk, steampunk, fantasy, dark novel style, anime style, realistic style, graphic novel style, comic, concept art
146
+ - 媒体/伝統的技法: traditional media, marker (medium), watercolor (medium), graphite (medium), official art, sketch, artbook, cover
147
+ - 絵柄の年代(指定された時のみ利用): newest, year 1980, year 2000, year 2010, year 1990, year 2020
148
+
149
+ **身体的特徴/画面上の物体**:
150
+ - キャラクター属性/職業/クラス: student, teacher, soldier, knight, wizard, ninja, doctor, artist, musician, athlete, virtual youtuber, chibi, maid, miko
151
+ - 表情: angry, blush stickers, drunk, grin, aroused, happy, sad, smile, laugh, crying, surprised, worried, nervous, serious, drunk, blush, aroused, :d, tongue out, sweatdrop, tongue out, :o, tears, tearing up, scared
152
+
153
+ - 身体的特徴: {{'髪型/髪色': ['long hair', 'short hair', 'twintails', 'ponytail', 'braid', 'bun', 'curly hair', 'straight hair', 'messy hair', 'blonde hair', 'black hair', 'brown hair', 'red hair', 'blue hair', 'green hair', 'white hair', 'purple hair', 'grey hair', 'ahoge', 'sidelocks', 'side ponytail', 'perfect hair', 'tail', 'multicolored hair', 'wavy hair', 'bangs', 'blunt bangs', 'twintails', 'hair between eyes', 'very long hair', 'braid', 'curly hair', 'braided ponytail', 'hand in own hair', 'hair over one eye', 'hair flower', 'two-tone hair', 'streaked hair', 'two side up'], '目の色': ['blue eyes', 'brown eyes', 'green eyes', 'red eyes', 'black eyes', 'purple eyes', 'yellow eyes', 'heterochromia', 'detailed eyes', 'glowing eyes', 'beatiful eyes', 'closed eyes', 'one eye closed'], '身体部位': ['bare shoulders', 'bare arms', 'bare legs', 'barefoot', 'abs', 'flat chest', 'small breasts', 'medium breasts', 'asymmetrical breasts', 'pointy breasts', 'sagging breasts', 'clenched teeth', 'pointy ears', 'perfect anatomy', 'closed mouth', 'long sleeves', 'open mouth', 'pale skin', 'collarbone', 'midriff', 'perfect anatomy', 'bare arms', 'thighs', 'parted lips', 'tongue', 'tanlines', 'dot nose', 'goggles on head', 'armpits', 'nail polish', 'mole', 'feet', 'lips', 'dark-skinned female', 'zettai ryouiki', 'shiny skin'], '身体部位(獣人、擬人化時のみ使用)': ['animal ears', 'cat ears', 'horse ears', 'horse girl', 'fang', 'teeth', 'horns', 'tail'], '服装/装飾品': ['uniform', 'suit', 'dress', 'casual wear', 'formal wear', 'belt', 'detached sleeves', 'swimsuit', 'kimono', 'armor', 'hat', 'glasses', 'white shirt', 'shirt', 'jewelry', 'necklace', 'earrings', 'bracelet', 'watch', 'ribbon', 'hair ribbon', 'scarf', 'gloves', 'boots', 'high heels', 'hair ornament', 'jacket', 'glasses', 'skirt', 'long sleeves', 'short sleeves', 'thighhighs', 'underwear', 'school uniform', 'swimsuit', 'panties', 'hair bow', 'bikini', 'miniskirt', 'fingerless gloves', 'bowtie', 'serafuku', 'japanese clothes', 'choker', 'pants', 'wings', 'open clothes', 'pantyhose', 'pleated skirt', 'frills', 'necktie', 'shorts', 'miko', 'collared shirt', 'leather armor', 'hairband', 'shoes', 'sleeveless', 'alternate costume', 'socks', 'fingering', 'denim shorts', 'epaulettes', 'santa costume', 'ribbon-trimmed sleeves', 'black bowtie', 'gym uniform', 'white bra', 'angel wings', 'crossdressing', 'cuffs', 'halo', 'high heels', 'apron', 'red bow', 'vest', 'open jacket', 'white panties', 'leotard', 'coat', 'black jacket', 'high heels', 'black pantyhose', 'see-through', 'miniskirt', 'elbow gloves', 'wide sleeves', 'white thighhighs', 'fur trim', 'plaid', 'one-piece swimsuit', 'maid headdress', 'ascot', 'high-waist skirt']}}
154
+ - 体液: blood, saliva, sweat, tears
155
+ - 前景/持ち物/操作物: sword, katana, sheath, gun, book, phone, bag, umbrella, instrument, vehicle, food, drink, guitar, piano, violin, drums, flute, car, bicycle, motorcycle, airplane, ship, flower, weapon, heart, speech bubble, carriage, locomotive, shovel
156
+ - 生物: dog, cat, horse, bird, fish, crab, dragon, unicorn, monster, fox, wolf, bear, tiger, lion, dragon, fairy, ghost, zombie, vampire
157
+
158
+ **性的表現(sensitive, nsfw, explicitのいずれかを指定した時のみ使用可)**:
159
+ - 身体部位女性専用: cleavage, backboob, sideboob, underboob, navel, huge breasts, large breasts
160
+ - 身体部位男性専用: topless male, necktie between pectorals, loose necktie, bare pectorals, male underwear, fundoshi
161
+ - 身体部位共通: open shirt, unbuttoned shirt, seductive smile, bare back, groin, groin tendon, midriff
162
+
163
+ ### 出力
164
+ """
165
+ messages = [
166
+ {"role": "system", "content": system_prompt},
167
+ {"role": "user", "content": user_prompt},
168
+ ]
169
+
170
+ prompt = tokenizer.apply_chat_template(
171
+ messages,
172
+ add_generation_prompt=True,
173
+ tokenize=False
174
+ )
175
+
176
+ payload = {
177
+ "prompt": prompt,
178
+ "n_predict": 280
179
+ }
180
+
181
+ url = "http://localhost:8080/completion"
182
+ headers = {
183
+ "Content-Type": "application/json"
184
+ }
185
+
186
+ response = requests.post(url, headers=headers, data=json.dumps(payload))
187
+ if response.status_code != 200:
188
+ print(f"Error: {response.text}")
189
+
190
+ model_response = response.json().get('content', '').strip()
191
+ print(f"model_response: {model_response}")
192
+
193
+ # モデルが生成したメッセージ部分だけを抽出
194
+ model_markers = ["assistant\n", "assistant:\n", "assitant\n"]
195
+
196
+ for marker in model_markers:
197
+ if marker in model_response:
198
+ model_response = model_response.split(marker)[-1].strip()
199
+ break
200
+
201
+ # 思考過程とプロンプトの抽出
202
+ thinking = ""
203
+ prompt_text = ""
204
+
205
+ if "<think>" in model_response and "</think>" in model_response:
206
+ thinking = model_response.split("<think>")[1].split("</think>")[0].strip()
207
+
208
+ def clean_prompt_text(text):
209
+ # 削除するタグのリスト
210
+ tags_to_remove = [
211
+ "masterpiece", "high score", "great score", "absurdres",
212
+ "highres", "original character", "original series",
213
+ "general", "sensitive", "nsfw", "explicit"
214
+ ]
215
+
216
+ # テキストを単語に分割して処理
217
+ words = []
218
+ current_words = text.split(',')
219
+
220
+ # 各単語をトリムして処理
221
+ for word in current_words:
222
+ word = word.strip()
223
+ # 空の単語はスキップ
224
+ if not word:
225
+ continue
226
+ # 削除対象のタグかチェック
227
+ if any(tag == word.lower() for tag in tags_to_remove):
228
+ continue
229
+ # まだ追加されていない単語のみ追加(重複排除)
230
+ if word not in words:
231
+ words.append(word)
232
+
233
+ # カンマで結合して返す
234
+ return ', '.join(words)
235
+
236
+ if "<prompt>" in model_response:
237
+ if "</prompt>" in model_response:
238
+ prompt_text = model_response.split("<prompt>")[1].split("</prompt>")[0].strip()
239
+ else:
240
+ prompt_text = model_response.split("<prompt>")[1].strip()
241
+
242
+ prompt_text = clean_prompt_text(prompt_text)
243
+ else:
244
+ prompt_text = f"1girl, {character_name}, {series_name}, anime style, highres"
245
+
246
+ prompt_text = prompt_text + f", {category}{COMMON_QUALITY_PROMPT}"
247
+
248
+ print(f"prompt for image: {prompt_text}")
249
+ generate_image(prompt_text, COMMON_NEGATIVE_PROMPT, "./test_image.png")
250
+
251
+ ```
252
+
253
+ ```
254
+ model_response: <think>
255
+ concept: アリスがワホットで落とられて、洞窟の中で呆然と立ち尽くしている場面。驚きと恐怖で表情を浮かべている。
256
+ - 人数: 1girl
257
+ - キャラクター名/シリーズ名: alice (alice in wonderland), alice in wonderland
258
+ - ポーズ/構図: standing, surprised, looking at viewer
259
+ - 背景/環境: indoors, cave, dark
260
+ - 描画スタイル/テクニック: anime
261
+ - 身体的特徴/画面上の物体: long hair, dress, worried, book
262
+ </think>
263
+ <prompt>1girl, alice (alice in wonderland), alice in wonderland, standing, surprised, looking at viewer, indoors, cave, dark, anime, long hair, dress, worried, book, general</prompt>
264
+ ```
265
+