Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/code-spirit-369/dream-tales-ai
This application allows users to generate stories using Gemini AI. It also generates images for the story using Stable Diffusion model via the Replicate platform.
https://github.com/code-spirit-369/dream-tales-ai
geminiai mongodb nextjs14 replicate stable-diffusion tailwindcss typescript vercel-ai-sdk
Last synced: 5 days ago
JSON representation
This application allows users to generate stories using Gemini AI. It also generates images for the story using Stable Diffusion model via the Replicate platform.
- Host: GitHub
- URL: https://github.com/code-spirit-369/dream-tales-ai
- Owner: code-spirit-369
- Created: 2024-08-20T18:08:21.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-20T19:46:04.000Z (5 months ago)
- Last Synced: 2024-11-15T07:15:02.547Z (2 months ago)
- Topics: geminiai, mongodb, nextjs14, replicate, stable-diffusion, tailwindcss, typescript, vercel-ai-sdk
- Language: TypeScript
- Homepage:
- Size: 209 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## π Table of Contents
1. π€ [Introduction](#introduction)
2. βοΈ [Tech Stack](#tech-stack)
3. π [Features](#features)
4. π€Έ [Quick Start](#quick-start)
5. πΈοΈ [Snippets (Code to Copy)](#snippets)## π¨ Tutorial
This repository contains the code corresponding to an in-depth tutorial available on our YouTube channel, Code Spirit.
- React.js
- Next.js
- Typescript
- ShadCN
- Gemini AI
- Stable Diffusion (via Replicate)
- MongoDB
- Vercel AI SDKThis web application allows users to generate unique children's stories using the power of Gemini AI. It also generates corresponding story cover images using the Stable Diffusion model via the Replicate platform. All generated stories and images are stored in MongoDB, making it easy to retrieve and display them within the app.
π AI-powered story generation tailored for children
π Image generation using the Stable Diffusion model
π Integration with Gemini AI through the Vercel AI SDK
π MongoDB storage for all generated stories and images
Follow these steps to set up the project locally on your machine.
**Prerequisites**
Make sure you have the following installed on your machine:
- [Git](https://git-scm.com/)
- [Node.js](https://nodejs.org/en)
- [npm](https://www.npmjs.com/) (Node Package Manager)**Cloning the Repository**
```bash
git clone https://github.com/code-spirit-369/dream-tales-ai.git
cd dream-tales-ai
```**Installation**
Install the project dependencies using npm:
```bash
npm install
```**Set Up Environment Variables**
Create a new file named `.env.local` in the root of your project and add the following content:
```env
GOOGLE_GENERATIVE_AI_API_KEY=MONGODB_URI=
REPLICATE_API_TOKEN=
```Get your Gemini AI API key from [Google AI Studio](https://aistudio.google.com/app/apikey).
Get your Replicate API key from [Replicate](https://replicate.com/).**Running the Project**
```bash
npm run dev
```Open [http://localhost:3000](http://localhost:3000) in your browser to view the project.
types.ts
```typescript
interface StoryPage {
page_number: number;
page_content: string;
page_image: string;
}interface Story {
story_title: string;
number_of_pages: number;
pages: StoryPage[];
cover_img: string;
}interface StoryDoc {
_id: string;
story: Story;
imageUrl: string;
createdAt: Date;
updatedAt: Date;
}
```
/api/generate/route.ts
```typescript
const final_prompt = `Generate a children's story with each page containing 70-100 words. The story should be engaging, simple, and appropriate for young children, incorporating themes of friendship, adventure, and learning. The story should be unique, original, and suitable for children aged 3-6 years old. It should be fun to read, easy to understand, and follow, with a clear beginning, middle, and end. The story should be written in English and free from any copyrighted material. The final story should be in JSON format with the following structure; story_title: The title of the story, number_of_pages: The total number of pages in the story. pages: An array of objects, each containing, page_number: The page number. page_content: The content of the page, with paragraph breaks where appropriate and page_image: A prompt to generate an image for the page content, following the style of children's storybook illustrations. Finally cover_img: A prompt to generate a cover image for the story, using children's storybook cover art style. Use this user prompt to generate the story: ${user_prompt}`;
```