Skip to content

regolet/AiStoryBookGenerator

Repository files navigation

AI StoryBook Generator πŸŽ¨πŸ“š

Transform your stories into beautifully illustrated storybooks using AI! This application analyzes your text, breaks it into scenes, and generates stunning illustrations for each scene using multiple AI services.

Features

  • Story Analysis: Uses Google AI Studio (Gemini) to analyze stories and extract visual elements
  • Scene Detection: Automatically breaks stories into illustrated scenes
  • Character Recognition: Automatically detects character gender and assigns consistent names (Nave for male, Lia for female)
  • Smart Character Mode: Enhances prompts with character information for consistent illustrations
  • Visual Direction: Extracts facial expressions, colors, lighting, poses, and composition
  • Reference Images: Generates initial reference images using Google AI Studio
  • High-Quality Illustrations: Creates final images using Replicate.com models (Ideogram V3 Turbo default)
  • Multiple Art Styles: Supports realistic, cartoon, anime, watercolor, and oil painting styles
  • Flexible Aspect Ratios: Support for various aspect ratios (square, landscape, portrait, etc.)
  • Web Interface: User-friendly interface for story input and storybook viewing
  • HTML Export: Generates beautiful HTML storybooks for easy sharing

Prerequisites

  • Node.js 16+ and npm
  • API Keys (only 2 required!):
    • Google AI Studio API Key
    • Replicate API Token

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/AiStoryBookGenerator.git
cd AiStoryBookGenerator
  1. Install dependencies:
npm install
  1. Create a .env file from the example:
cp .env.example .env
  1. Add your API keys to the .env file:
GOOGLE_AI_STUDIO_API_KEY=your_google_ai_studio_api_key_here
REPLICATE_API_TOKEN=your_replicate_api_token_here
PORT=3000

Getting API Keys

Google AI Studio API Key

  1. Visit Google AI Studio
  2. Sign in with your Google account
  3. Go to API Keys section
  4. Generate a new API key

Replicate API Token

  1. Go to Replicate
  2. Create an account or sign in
  3. Navigate to Account Settings
  4. Find your API token

Usage

  1. Start the development server:
npm run dev
  1. Open your browser and navigate to:
http://localhost:3000
  1. Use the web interface to:

    • Paste your story text
    • Select art style and target audience
    • Configure advanced settings (optional)
    • Click "Generate StoryBook"
  2. View your generated storybook in the browser or download the HTML file

Project Structure

AiStoryBookGenerator/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ server.ts           # Express server setup
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   └── storyRoutes.ts  # API endpoints
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ storyAnalyzer.ts      # OpenAI GPT integration
β”‚   β”‚   β”œβ”€β”€ googleAIStudio.ts     # Google AI Studio integration
β”‚   β”‚   β”œβ”€β”€ replicateService.ts   # Replicate.com integration
β”‚   β”‚   └── storyBookGenerator.ts # Main generation logic
β”‚   └── types/
β”‚       └── index.ts        # TypeScript type definitions
β”œβ”€β”€ public/
β”‚   β”œβ”€β”€ index.html          # Main web interface
β”‚   β”œβ”€β”€ css/
β”‚   β”‚   └── style.css       # Styling
β”‚   └── js/
β”‚       └── app.js          # Frontend JavaScript
β”œβ”€β”€ output/                 # Generated storybooks
β”œβ”€β”€ uploads/                # Temporary file uploads
└── package.json

API Endpoints

  • POST /api/generate-storybook - Generate a complete storybook
  • POST /api/analyze-story - Analyze story without generating images
  • GET /api/storybooks - List all generated storybooks
  • GET /api/storybook/:id - Get specific storybook details
  • GET /api/health - Check API keys status

Configuration Options

Story Analysis

  • Style: realistic, cartoon, anime, watercolor, oil-painting
  • Target Audience: children, young-adult, adult

Image Generation

  • Use Google Reference: Enable/disable reference image generation
  • Image Dimensions: 512-2048 pixels
  • Inference Steps: 20-100 (higher = better quality, slower)
  • Guidance Scale: 1-20 (higher = more prompt adherence)

Replicate Models

  • Ideogram V3 Turbo (default) - Fast, high-quality, text-capable
  • Smart Character Mode - Auto-detects character gender and uses consistent naming (Nave/Lia)
  • SDXL - Traditional diffusion model
  • Stable Diffusion 2.1 - Classic option
  • OpenJourney - Artistic style

Character System

The application includes an intelligent character recognition system:

  • Automatic Gender Detection - Analyzes story content to identify main character gender
  • Consistent Naming - Uses "Nave" for male characters, "Lia" for female characters
  • Enhanced Prompts - Automatically enhances image generation prompts with character information
  • Character Continuity - Ensures consistent character appearance across all scenes

Development

Run in development mode:

npm run dev

Build for production:

npm run build

Start production server:

npm start

Example Story Input

Title: The Brave Little Robot

Once upon a time, in a futuristic city filled with towering skyscrapers and neon lights, there lived a small robot named Beep. Beep had bright blue eyes that glowed in the dark and silver metallic body that sparkled under the city lights.

One day, Beep discovered that the city's main power source was failing. The giant crystal that powered everything was losing its glow. Beep knew he had to help.

Despite being the smallest robot in the city, Beep ventured into the dangerous underground tunnels. There, he found the problem - a massive tangle of broken cables.

Working through the night, Beep carefully repaired each cable with his tiny tools. As the sun rose, the crystal began to glow again, brighter than ever.

The city celebrated Beep as a hero, proving that even the smallest among us can make the biggest difference.

Troubleshooting

API Key Issues

  • Ensure all API keys are correctly set in the .env file
  • Check the Settings tab in the web interface to verify API status
  • Restart the server after adding API keys

Image Generation Failures

  • Check your Replicate account has sufficient credits
  • Verify Google AI Studio API is enabled
  • Try reducing image dimensions or inference steps

Memory Issues

  • Reduce the number of scenes by writing shorter stories
  • Lower image resolution in advanced settings
  • Process one story at a time

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

ISC License

Acknowledgments

  • OpenAI for GPT story analysis
  • Google AI Studio for reference generation
  • Replicate for high-quality image generation
  • All the AI models and services that make this possible

Support

For issues, questions, or suggestions, please open an issue on GitHub.

About

automating children's book

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published