A real-time story generation application that creates illustrated children's stories using AI. The app generates structured 4-scene stories with consistent character illustrations using Google's Gemini and Imagen models.
- Real-time Story Generation: Create stories from keywords using Google Gemini
- Consistent Character Design: AI-generated illustrations maintain character consistency across all scenes
- 4-Scene Structure: Each story follows a classic narrative arc (Setup → Inciting Incident → Climax → Resolution)
- WebSocket Communication: Real-time updates between frontend and backend
- Image Generation: Automatic illustration generation using Google Imagen
- Modern UI: Beautiful, responsive interface built with Next.js and Tailwind CSS
- Frontend: Next.js 14 with TypeScript, Tailwind CSS, and WebSocket communication
- Backend: FastAPI with WebSocket support, Google ADK for AI agents
- AI Models:
- Story Generation: Google Gemini 1.5 Flash
- Image Generation: Google Imagen via Vertex AI
- Storage: Google Cloud Storage for generated images
- Docker and Docker Compose: Install here
- Google Cloud Account: Required for Vertex AI (Imagen) and GCS.
- Node.js and npm: For frontend dependency management.
This is the recommended way to run StoryGen locally. It uses Docker Compose to set up the frontend and backend services, ensuring a consistent and isolated development environment.
-
Configure Backend Environment:
- Navigate to the
backend
directory. - Create a
.env
file from the example:cp env.example .env
- Edit the
.env
file and add your Google Cloud credentials:GOOGLE_CLOUD_PROJECT_ID="your-gcp-project-id" GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/service-account.json" GENMEDIA_BUCKET="your-gcs-bucket-name"
- Important: Make sure the path to your service account JSON file is accessible from where you run Docker. A good practice is to place the key in a secure location and provide an absolute path.
- Navigate to the
-
Start the Application:
- From the project's root directory, run:
docker-compose up --build
- This command will:
- Build the Docker images for both the frontend and backend.
- Start both services.
- Enable hot-reloading, so your changes to the code are reflected instantly.
- From the project's root directory, run:
-
Access the Application:
- Frontend:
http://localhost:3000
- Backend:
http://localhost:8000
- Frontend:
-
Stopping the Application:
- Press
Ctrl + C
in the terminal wheredocker-compose
is running. - To remove the containers, run
docker-compose down
.
- Press
For deploying the application to a production environment, please refer to the instructions in DEPLOYMENT.md
. This guide provides detailed steps for deploying to Google Cloud Run.
- Open the application in your browser
- Enter keywords for your story (e.g., "cat eat fish")
- Click "Generate Story"
- Watch as the story and illustrations are generated in real-time
- View the complete 4-scene story with consistent character illustrations
storygen-main/
├── backend/
│ ├── main.py # FastAPI server with WebSocket endpoints
│ ├── story_agent/
│ │ ├── agent.py # Story generation agent
│ │ ├── direct_image_agent.py # Image generation agent
│ │ └── imagen_tool_direct.py # Imagen integration
│ └── requirements.txt
├── frontend/
│ ├── app/ # Next.js app directory
│ ├── components/ # React components
│ └── package.json
├── README.md
└── .gitignore
GET /health
- Health checkGET /
- API infoWebSocket /ws/{user_id}
- Real-time story generation
Variable | Description | Required |
---|---|---|
GOOGLE_CLOUD_PROJECT_ID |
Google Cloud Project ID | Yes |
GOOGLE_APPLICATION_CREDENTIALS |
Path to service account key | Yes |
GENMEDIA_BUCKET |
GCS bucket for image storage | Yes |
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Google Gemini and Imagen for AI capabilities
- Next.js and FastAPI for the web framework
- Tailwind CSS for styling