AIを使って無料枠で絵本を作ろう
はじめに
Googleの画像生成AIであるImagen3を使ったサンプルがあって、勉強にと思いチャレンジしてました。
Colabを使用して絵本作成が簡単に出来る内容ですが、途中で有料で無いと出来ない箇所があって、無料枠で頑張ってる人は先に進めなくなります。
世知辛い世の中です…
Pythonで実装をするサンプルで、自動で絵本が作れる!って内容です。無料枠ユーザーでも、プロンプトだけ流用すれば絵本が作れるのでは、と考えてやってみたところ、無料枠でも絵本を作る事が出来たのでその経緯と説明です。
この記事は、サンプル記事がPythonで書いて自動で行える事を、手動で行って作る内容です。
絵本の元ネタとなる物語は用意する必要があります。ここでは
ケネス・グレアム「たのしい川べ」を元に作業を進めます。
テキストデータは以下の物を使用します。ダウンロードしておいてください。ご自身で物語を持っているのであれば、それを使用してもらっても良いと思います。
注意
Geminiでイラストを生成してもらうと、右下にGeminiのロゴマークが入ります。これはウォーターマークというそうですが、権利や商標といった難しい問題に関わる可能性があります。規約違反や法的なトラブルにつながることがありますので、ご注意下さい。
前準備
GoogleのGeminiを使用します。
ご自身のGoogleアカウントでログイン下さい。スタイルの決定
物語の内容に合う様に、スタイルもGeminiさんに決めてもらいましょう。
ダウンロードした「pg289.txt」をドラッグアンドドロップして、以下のプロンプトを入力下さい。
<プロンプト>
Can you define a art style that would fit the story?
Just give us the prompt for the art syle that will added to the furture prompts.
<回答>
A whimsical and nostalgic illustration style reminiscent of classic early 20th-century storybooks, infused with elements of Art Nouveau and British Romanticism. The color palette is rich and warm, featuring a luminous quality that captures the changing light of the seasons, from the "radiant transformation" of sunrise to the soft, silver glow of the moon over the river. The scenes should emphasize the natural world, with lush, detailed foliage, winding riverbanks, and cozy, burrowed homes. The animals are depicted with expressive, human-like qualities but retain their distinct animal forms, such as Mole with his black fur and Rat with his "thick silky hair" and "neat ears". The overall feeling should evoke a sense of peaceful adventure and serene, natural beauty, with a hint of the mysterious "Terror of the Wild
追加で、絵本を作成したいので、テキストを含まない絵だけの出力に限定して欲しい事を伝えておきます
<プロンプト>
There must be no text on the image, it should not look like a cover page.
It should be an full illustration with no borders, titles, nor description.
Stay family-friendly with uplifting colors.
主要キャラクタ画像の生成
こちらもGeminiにお願いしましょう
<プロンプト>
Can you describe the main characters (only the adults) and prepare a prompt describing them with as much details as possible (use the descriptions from the book) so Imagen can generate images of them? Each prompt should be at least 50 words.
後程使回答を使用するので、形式を整えておきたいです。追加JSON形式での出力をお願いしましょう
<プロンプト>
JSON形式としてください
ここだけ日本語で依頼しましたが、ちゃんとJSON形式で回答してくれました
[
{
"name": "Mole",
"prompt": "黒い毛皮と突き出た鼻を持つ、善良な性格の小さなモグラのイラスト。彼の表情は、新たな喜びと安らぎに満ちています。仕事で疲れていた最初の描写から、新しい環境で完全に満たされ、幸せを感じている姿が描かれるべきです。彼は臆病で少し圧倒されているように見えますが、同時に完全に満足し、幸せです。この画像は、彼の誠実で謙虚な性格を捉え、外の世界に対する彼の驚きの念を示すべきです。"
},
{
"name": "Water Rat (Ratty)",
"prompt": "茶色の顔、ひげ、小さなきちんとした耳、そして厚く絹のような毛を持つ、ハンサムで威厳のあるカワウソ。彼は川の中か、そのそばで、穏やかで落ち着いた態度で描かれるべきです。彼は思慮深く詩的な性格で、友人に対してほとんど父親のような優しさを持っています。彼の表情は、彼の全世界である川に対する深く厳粛な愛を伝えるべきです。"
},
{
"name": "Badger",
"prompt": "縞模様の頭と高い肩が特徴的な、大きく力強い姿で描かれた、孤独で重要なアナグマのイラスト。彼は社交の場、招待、ディナーパーティーを嫌う隠遁者ですが、友人にとっては「親愛なる古きアナグマ」です。画像は、彼が着ている長いドレッシングガウンと、かかとのすり減ったスリッパから、家庭的でありながらも生真面目な性格をうかがわせる、力強い存在感で彼を描くべきです。彼は父親のような優しさと、彼を知るすべての人から尊敬される権威を帯びているように見えるべきです。"
},
{
"name": "Toad",
"prompt": "自慢好きでうぬぼれ屋の、背が低くずんぐりした姿の描写。彼は贅沢な家、ヒキガエル邸にいる様子が描かれるべきです。ヒキガエル邸は、年月を経て熟成された赤レンガ造りの威厳ある古い家で、広々とした芝生が広がっています。彼の表情は、新しい流行、それがボートであろうと新しい自動車であろうと、絶えず探求する、あふれんばかりの自己満足と上機嫌さを伝えるべきです。彼は最高の動物であり、常に周りの人を楽しませます。彼の画像は、彼の豊かで派手な個性を伝え、同時に冒険への愛と子供のような不安定さのヒントも常に含んでいるべきです。"
}
]
ここまではChat形式でのやり取でしたが、ここから先はいよいよ絵を生成します。
先ほど作成したJSON形式の主要キャラクタの情報をひとつづつ切り分けて、プロンプトとしてGeminiに渡して絵を生成してもらいます。
まずはMoleさん
{
"name": "Mole",
"prompt": "黒い毛皮と突き出た鼻を持つ、善良な性格の小さなモグラのイラスト。彼の表情は、新たな喜びと安らぎに満ちています。仕事で疲れていた最初の描写から、新しい環境で完全に満たされ、幸せを感じている姿が描かれるべきです。彼は臆病で少し圧倒されているように見えますが、同時に完全に満足し、幸せです。この画像は、彼の誠実で謙虚な性格を捉え、外の世界に対する彼の驚きの念を示すべきです。"
}
safety_filter_level="BLOCK_LOW_AND_ABOVE",
person_generation="ALLOW_ADULT",
aspect_ratio="9:16"
前半は、少し前に作ってもらったJSONのコピーです。後半は、生成してもらう絵についての指示です。
Geminiさんにてスタイルを決めてもらう際に「古典的な絵本」「ノスタルジックなイラスト」「アールヌーヴォー」と回答しているので、それっぽい画像が出てきています。このへんは、違ったテイストを希望なら、それをプロンプトで注文すれば、聞いてくれますよ。
画像はダウンロードして保存しておいてください。画像を右クリックして「名前を付けて画像を保存」を選択で保存できます。
Water RatさんやBadgerさん、Toadさんも同じように作ってもらってください。
これで主要登場人物の絵が完成です。
本文の章毎のイラストを生成
最初の渡した物語のテキストファイルから、章毎に内容を描画するプロンプトをGeminiさんに作ってもらいます。こちらもJSON形式で書き出してもらいました。
<プロンプト>
Now, for each chapters of the book, give me a prompt to illustrate what happens in it. Be very descriptive, especially of the characters. Be very descriptive and remember to reuse the character prompts if they appear in the images. Each character should at least be described with 30 words.
JSON形式としてください
<回答>
[
{
"chapter": "Chapter 1: The River Bank",
"prompt": "A vibrant, full-page illustration showing Mole, a small, good-natured mole with black fur and a prominent snout, his expression one of newfound joy and peace, emerging from his underground home. He stands hesitantly at the edge of a lush, sun-dappled riverbank, wearing simple, earthy clothes that reflect his humble nature, his small eyes wide with wonder at the unfamiliar world. Facing him, Water Rat (Ratty), a handsome and dignified Water Rat with a brown face, whiskers, small neat ears, and thick silky hair, is poised in a sleek, green rowing boat. Ratty, wearing a crisp, white shirt and a blue waistcoat, gestures invitingly to Mole, his serene and composed demeanor evident. The river sparkles under a bright sky, surrounded by tall reeds and overhanging willows. The art style is whimsical and nostalgic, reminiscent of classic early 20th-century storybooks, infused with elements of Art Nouveau and British Romanticism. The color palette is rich and warm, featuring a luminous quality that captures the changing light of the seasons. The scenes emphasize the natural world, with lush, detailed foliage, winding riverbanks, and cozy, burrowed homes. The animals are depicted with expressive, human-like qualities but retain their distinct animal forms. The overall feeling evokes a sense of peaceful adventure and serene, natural beauty."
},
とっても長いので一部です。各章毎にイラストを作成するためのプロンプトを作ってくれています。あとは、先ほどの登場人物と同じですね。このプロンプトを章毎に切り出して、Geminiさんにイラストを作成してもらいます。
プロンプトは、
上記の各章毎のプロンプトに以下を追加してください
output_mime_type="image/jpeg",
safety_filter_level="BLOCK_LOW_AND_ABOVE",
person_generation="ALLOW_ADULT",
aspect_ratio="1:1"
<プロンプト>
{
"chapter": "Chapter 1: The River Bank",
"prompt": "A vibrant, full-page illustration showing Mole, a small, good-natured mole with black fur and a prominent snout, his expression one of newfound joy and peace, emerging from his underground home. He stands hesitantly at the edge of a lush, sun-dappled riverbank, wearing simple, earthy clothes that reflect his humble nature, his small eyes wide with wonder at the unfamiliar world. Facing him, Water Rat (Ratty), a handsome and dignified Water Rat with a brown face, whiskers, small neat ears, and thick silky hair, is poised in a sleek, green rowing boat. Ratty, wearing a crisp, white shirt and a blue waistcoat, gestures invitingly to Mole, his serene and composed demeanor evident. The river sparkles under a bright sky, surrounded by tall reeds and overhanging willows. The art style is whimsical and nostalgic, reminiscent of classic early 20th-century storybooks, infused with elements of Art Nouveau and British Romanticism. The color palette is rich and warm, featuring a luminous quality that captures the changing light of the seasons. The scenes emphasize the natural world, with lush, detailed foliage, winding riverbanks, and cozy, burrowed homes. The animals are depicted with expressive, human-like qualities but retain their distinct animal forms. The overall feeling evokes a sense of peaceful adventure and serene, natural beauty."
}
output_mime_type="image/jpeg",
safety_filter_level="BLOCK_LOW_AND_ABOVE",
person_generation="ALLOW_ADULT",
aspect_ratio="1:1"
<回答>
こちらも、章毎のプロンプトで、全部作ってください。
無料枠の限界
ちなみに私はこのへんで、無料枠を使い切ったメッセージが出て作業が中断しました。
3章のイラストを出力時に無料枠を使い切ったようですが、最後にはなぜかおじさんの白黒画像が出力されました。
だれ?
無料枠には制限があり、1日あたりに処理できるプロンプトや生成できる画像が決まっています。ただし1日毎の制限なので、明日になれば復活しますので、いったんここで作業を中止して、翌日以降で再開しました。
まとめ
無料枠なので、数日にわたって作業しましたが、これで登場人物と各章のイラストが出来ました。あとは組み合わせて、物語の文言を追加すれば完成ですね。
Discussion