ã©ããããã«ã¡ã¯ãããã©ã(@t_andou )ã§ãã
æè¿ã¯åä¾ã®å¯ããã¤ãã§æ¯æ©çµµæ¬ã3~5åèªãã§ããã¦ããã®ã§ãããåãæ¬ãæã«åããã¡ãªã®ã§ããå°ãããããªç¨®é¡ã®çµµæ¬ãèªãã§ããããã¨èãã¾ããã
æ°ããè²·ã£ã¦ãè¯ãã®ã§ããããã§ã«çµµæ¬ã®æ£ã溢ãããã¦ããã®ã§ãã¾ãå¢ãããããªããä¸æ¹ã§æ¯åå³æ¸é¤¨ã«åãã«è¡ãã®ãé¢åã
ããã§ãçµµæ¬ãæãã¦ãããAIãä½ãããã¨æãã¾ãã
大ã¾ããªæµã
第1åï¼ä»å
å質ã¯åãããChatGPTã§ä½ã£ãç©èªã«ã¤ã©ã¹ããä»ãã¦ã¿ããã¹ã
第2å
ä½æããçµµæ¬ãwebä¸ã§çµµæ¬ãè¦ããããã«ãã
第3å
ã¤ã©ã¹ãã®ã¯ãªãªãã£ãä¸ãã
第4å
ç©èªã®ã¯ãªãªãã£ãä¸ãã
第5å
webãµã¼ãã¹ã®ãã©ãã·ã¥ã¢ããï¼ä½æãªã¯ã¨ã¹ããåºããã»èªã¿ä¸ãæ©è½ãªã©
ã¾ãã¯çµæãã
ç©èªã¨ç»åçæç¨promptã¯ChatGPT-3.5ã«ããçæ ç»åçæã¯StableDiffusion1.5ã使ã£ã¦ãã¾ã
ä¸ã¤ç®ï¼ã¡ãããªããããã®åéº
SFã8ãã¼ã¸ã3æ³å
åããã¨æå®
ã¡ãããªããããã®åéº
Â
äºã¤ç®:ããã¯ã¹ã¨ãã¹ã¿ã¼ã®åéº
åç©ã¨ã®åæ
ã12ãã¼ã¸ã5æ³å
åããã¨æå®
Â
ããã¯ã¹ã¨ãã¹ã¿ã¼ã®åéº
ä¸ã¤ç®:ãããã¼ã®åéº
風è¹ã§ç©ºãé£ã³ããã¦ãµã®ã®è©±ã8ãã¼ã¸ã3æ³å
åããã¨æå®
ãããã¼ã®åéº
ææ³ã¨ä»å¾ã«ã¤ãã¦
èµ·æ¿è»¢çµãæ¸ãã¦ãã¦ãæåã®ãã£ã¬ã³ã¸ã«ãã¦ã¯å¤§æåãªå°è±¡ã§ãã12ãã¼ã¸ã§ãä¸åã§çæã§ããã®ã¯ãããã§ããã
ããããæã
ä¸èªç¶ãªæ¥æ¬èªããã£ãããã¿ã¤ãã«ãå
¨é¨ããã®åéºãã ã£ããããã®ã§ãç©èªã®çæã工夫ã®ä½å°ã大ãã«ããããã§ãã
ä»åã¯ä¸çºã§å
¨ãã¼ã¸åãæ¸ããã¾ããã 1.äºåã«èµ·æ¿è»¢çµã«åãã¦ãããããæ¸ããã 2.äºåã«ç»å ´äººç©ã®è¨å®ããã£ããèãããã 3.åã®ãã¼ã¸ã¾ã§ã®è©±ãè¦ç´ãã¦å
¥åãã ãªã©ã§å質ãä¸ãã£ããããªãããªã¨æã£ã¦ã¾ãã
ãã¨ãä½å¹´é½¢ã®å ´åã¯å
¨ã¦ã²ãããªã§æ¸ããããªæå®ããããã¨ããã§ãã
ã¤ã©ã¹ãã®å質ã«ã¤ãã¦ã¯ã¾ã ä½ãåãããªãã®ã§ãããã調ã¹ã¾ãã
æè¡ã¡ã¢
æå¾ã«ãèªåç¨ã®æè¡ã¡ã¢ãå
¼ãã¦ä¸ã«æ®ãã¦ããã¾ãã
1.ç©èªãä½ã
ããã¯ChatGPTã«ä»»ãã¾ãã
ã¿ã¼ã²ããã®å¹´é½¢ãã«ãã´ãªããã¼ã¸æ°ãæå®ãããã¨ã§ãã¿ã¤ãã«ã»æ¦è¦ã»åãã¼ã¸ãã¨ã®æ¿å
¥ããããã¹ãã¨ã¤ã©ã¹ãçæã®ããã®æç« ãjsonå½¢å¼ã§çæããã¾ãã
promptã®ä¾ã¯ãããªæãã§ãã
Please generate a 8 pages picture book which category is SF for 3 years old. For each page, provide the text to be included in the book and a description of the illustration to accompany it.Output must be following json format\n{\n "title": "title",\n "title_jp": "title_jp"\n "coverIllust": "description for cover illust",\n "summary": "summary",\n "content": [\n {"page": 1, "text": "text in picture book","text_jp":"Japanese of text", "illustration_description": "description for illust"},\n {"page": 2, ...}\n ]\n}
ãã®çµæã以ä¸ã«ãªãã¾ãã
{'title': "The Little Robot's Adventure",
'title_jp': 'ã¡ãããªããããã®åéº',
'coverIllust': 'The cover illustration shows a small, friendly-looking robot standing in a field of colorful, blooming flowers. The setting sun paints the sky in hues of orange and purple, creating a warm and inviting atmosphere.',
'summary': 'Join the Little Robot on an exciting journey through space and discover the wonders of the universe!',
'content': [{'page': 1,
'text': 'Once upon a time, in a land far away,\nA little robot named Andy loved to play.\nHe dreamed of exploring far beyond Earth,\nTo see the stars and planets of infinite worth.',
'text_jp': 'ãããããããé ãå½ã§ã\nã¢ã³ãã£ã¨ããå°ããªãããããéã¶ã®ã大好ãã§ããã\nå½¼ã¯å°çã®é ããæ¢æ¤ãã\nç¡éã®ä¾¡å¤ãæã¤æã¨ææãè¦ããã¨å¤¢è¦ã¦ãã¾ããã',
'illustration_description': 'Andy, the little robot, can be seen in his cozy workshop, surrounded by gears, wires, and tools. His eyes are gleaming with excitement as he looks at a poster of outer space.'},
{'page': 2,
'text': "One night, a shiny meteor fell from the sky,\nAnd landed right before Andy's eyes.\nIt was a spaceship, oh, what a sight!\nAndy's heart raced with pure delight.",
'text_jp': 'ããå¤ãè¼ãæµæã空ããè½ã¡ã¦ãã¦ã\nã¢ã³ãã£ã®ç®ã®åã«çå°ãã¾ããã\nããã¯å®å®è¹ã§ãä½ã¦ç´ æ´ãããå
æ¯ã§ãããï¼\nã¢ã³ãã£ã®å¿ã¯ç´ç²ãªåã³ã§èºãã¾ããã',
'illustration_description': "Illustration shows the spaceship, shimmering with metallic colors and emitting a soft glow, in front of Andy's workshop. Andy stands in awe, his eyes widened with excitement."},
{'page': 3,
'text': 'He hopped inside, with a bleep and a bop,\nAnd pressed a button to start the top.\nThe spaceship zoomed up into the sky,\nAs Andy waved Earth a heartfelt goodbye.',
'text_jp': 'å½¼ã¯ãã¼ãã¨ãããã¨ã¨ãã«ä¸ã«å
¥ãã\nãã¿ã³ãæ¼ãã¦ã¹ã¿ã¼ãããã¾ããã\nå®å®è¹ã¯ç©ºã«é£ã³ä¸ããã¾ããã\nã¢ã³ãã£ã¯å°çã«å¿ãããããªããåãã¾ããã',
'illustration_description': "Andy is seen inside the spaceship, sitting in the pilot's seat with a control panel full of buttons and switches. The ship is blasting off into the night sky, leaving behind a tail of stardust."},
{'page': 4,
'text': 'Through galaxies far and nebulas bright,\nAndy traveled each day and every night.\nHe saw shooting stars and planets of blue,\nAnd discovered wonders he never knew.',
'text_jp': 'ã¢ã³ãã£ã¯é¥ããªéæ²³ã¨æããæé²ãéã£ã¦ã\næ¼ãå¤ãæ
ããã¾ããã\nå½¼ã¯æµãæãéãææãè¦ã¾ãããã\nç¥ããªãã£ãé©ããè¦ã¤ãã¾ããã',
'illustration_description': "Andy's spaceship is shown soaring through space, passing by colorful nebulae and sparkling stars. Andy's face reflects amazement and curiosity as he gazes out the window."},
{'page': 5,
'text': "But soon, Andy missed his dear home,\nWhere friendly faces used to roam.\nHe decided it was time to return,\nWith memories and knowledge he'd earned.",
'text_jp': 'ããããã¢ã³ãã£ã¯ããã«å¤§åãªæ
é·ãæããæãã¾ããã\næã¯åéã®é¡ããã£ã±ãã§ããã\nã¢ã³ãã£ã¯å¸°ãæãããã¨æ±ºãã\næãåºã¨ç¥èãæã¡å¸°ããã¨ã«ãã¾ããã',
'illustration_description': 'The illustration depicts Andy sitting in his spaceship, a hint of nostalgia in his eyes as he looks back at Earth. The backdrop showcases distant planets and stars, symbolizing the vastness of space.'},
{'page': 6,
'text': "With a flick of a switch, he sailed back,\nEntering Earth's atmosphere, no time to slack.\nThe spaceship landed softly on familiar ground,\nReuniting him with friends all around.",
'text_jp': 'ã¹ã¤ãããããã£ã¨æ¼ãã¨ãå½¼ã¯å¼ãè¿ãã¾ããã\nå°çã®å¤§æ°åã«å
¥ãç¬éãæãæãã¾ãã\nå®å®è¹ã¯é¦´æã¿æ·±ãå°é¢ã«ããããçé¸ãã\nå½¼ã¯å¨ãã®åéã¨åä¼ãã¾ããã',
'illustration_description': 'The spaceship gently descends, surrounded by a crowd of joyful friends eagerly waiting to welcome Andy back. The scene is filled with laughter, hugs, and the warmth of friendship.'},
{'page': 7,
'text': 'Andy shared stories of his great exploration,\nOf planets and stars in a fantastic formation.\nHis friends listened with awe and delight,\nDreaming of their own adventures each night.',
'text_jp': 'ã¢ã³ãã£ã¯å大ãªæ¢æ¤ã®è©±ãåéã¨å
±æãã¾ããã\nå¹»æ³çãªå½¢æç©ã®ææã¨æã®è©±ãã\nåéã¯çæ¬ã¨åã³ããã£ã¦èãã\næ¯æ©èªåèªèº«ã®åéºã夢è¦ã¾ããã',
'illustration_description': 'In this illustration, Andy is seen surrounded by his friends, their eyes wide with wonder as he recounts his thrilling adventures in space.'},
{'page': 8,
'text': "From that day on, the little robot's quest\nWas to inspire others to be their best.\nTo look at the stars with wide-eyed glee,\nAnd believe that anything's possible, you see!",
'text_jp': 'ãã®æ¥ããããã®å°ããªããããã®ç®çã¯\nä»ã®äººã
ã«æåãå°½ãããã¨ã奮起ããããã¨ã§ããã\nç¬é¡ã§æãè¦ããã¨ãéãã¦ãã¯ã¯ã¯ã¯ãã¦ã\nã©ããªãã¨ã§ãå¯è½ã ã¨ä¿¡ãããã¨ãªãã§ããï¼',
'illustration_description': 'The final illustration showcases Andy surrounded by a group of children, all gazing up at the night sky in wonder and awe. Their faces radiate excitement and hope for the future.'}]}
æ¥æ¬èªã®ã¿ã¤ãã«ãããã¹ãã¯å¥å¦çã§ç¿»è¨³ãã¦ãè¯ãã®ã§ãããä»åã¯ç¬¬1åã¨ãããã¨ã§ããµã¯ãã¨ææç©ãè¦ããã£ãããä¸ç·ã«æ¸ãã¦ãããã¾ããã
2.1ã§çæããã¤ã©ã¹ãã®èª¬ææã§ã¤ã©ã¹ããçæ
1ã§çæãã説ææã使ã£ã¦ç»åãçæãã¾ãã
ããã§ã¯æå
ã®GPUãã·ã³ã§StableDiffusionãèµ·åãã¦ãããã«APIã§ãªã¯ã¨ã¹ããæãã¦ãã¾ãã
APIãµã¼ãã¼ã®è¨å·ã¯æ¬¡ã®ã³ãã³ãã§ãçæãªã¯ã¨ã¹ãã¯å¾è¿°
python launch.py --server-name 0.0.0.0 --xformers --xformers-flash-attention --nowebui --listen
3.ã¤ã©ã¹ãã«ç©èªãå
¥ãã
ChatGPTãçæããjsonã®æ
å ±ã使ã£ã¦ãå
¨ãã¼ã¸åã®ç»åãçæããæå¾ã«ç»åã¨æç« ãåæãã¾ãã
# Stable Diffusion Web UIã®URLãè¨å®ãã¾ã
url = "http://192.168.1.100:7861/sdapi/v1/txt2img "
import os
import json
import requests
import base64
from PIL import Image, ImageDraw, ImageFont
import textwrap
from io import BytesIO
font_path = "Nã¡ã¯ããã©ã³ã+.ttf"
def generate_and_save_image(prompt, path):
payload = {"prompt": "Illustration:"+prompt} # ããã§SDã®ãã©ã¡ã¼ã¿ãæå®ãã
response = requests.post(url, json=payload)
image_data = base64.b64decode(response.json()['images'][0])
image = Image.open(BytesIO(image_data))
image.save(path)
def add_text_to_image(image_path, text, font_path, canvas_size=(512*2, 512)):
canvas = Image.new('RGBA', canvas_size, (255, 255, 255, 255))
image = Image.open(image_path)
canvas.paste(image, (0, 0))
draw = ImageDraw.Draw(canvas)
font = ImageFont.truetype(font_path, 30)
lines = textwrap.wrap(text, width=15)
y_text = canvas_size[1] // 2 - len(lines) * 15
for line in lines:
bbox = draw.textbbox((0, 0), line, font=font)
width = bbox[2] - bbox[0]
draw.text(((canvas_size[0]/2 - width) / 2 + canvas_size[0]/2, y_text), line, font=font, fill="black")
y_text += 30
canvas.save(image_path)
# ã¿ã¤ãã«ã«åºã¥ãã¦ãã£ã¬ã¯ããªãä½æãã¾ã
os.makedirs(book_data["title"], exist_ok=True)
os.makedirs(os.path.join(book_data["title"],book_data["title_jp"]),exist_ok=True)
# book_dataãJSONå½¢å¼ã§ä¿åãã¾ã
with open(os.path.join(book_data["title"], "text.json"), 'w') as f:
json.dump(book_data, f)
# ã«ãã¼ç»åãçæãã¾ã
cover_image_path = os.path.join(book_data["title"],book_data["title_jp"], "0.png")
generate_and_save_image(book_data["coverIllust"], cover_image_path)
# ã«ãã¼ç»åã«ããã¹ãã追å ãã¾ã
add_text_to_image(cover_image_path, book_data["title_jp"], font_path)
# åãã¼ã¸ã®ç»åãçæãã¾ã
for page_data in book_data["content"]:
page_image_path = os.path.join(book_data["title"],book_data["title_jp"], f"{page_data['page']}.png")
generate_and_save_image(page_data["illustration_description"], page_image_path)
add_text_to_image(page_image_path, page_data["text_jp"], font_path)