- Introduction
- Features
- Technologies Used
- Installation
- Configuration
- Usage
- API Documentation
- Troubleshooting
- Contributing
- License
The AI Book Generator is a powerful web application that leverages AI models from OpenAI and Together to generate detailed books on a wide range of topics. Users can customize their book's content, language, and length, and then download the final product as a PDF. The application also includes features for API key management, user authentication via Firebase, and image generation using the Hugging Face API.
- Book Generation: Utilize AI models to generate comprehensive books on any topic.
- Language Customization: Choose the language for your book's content.
- Word Count Control: Specify the target word count for your book.
- PDF Download: Save and download your generated book as a PDF.
- API Key Management: Generate and manage API keys for secure access to the book generation API.
- User Authentication: Secure user registration and login using Firebase.
- Image Generation: Generate images based on text prompts using the Hugging Face API.
- Flask: A lightweight WSGI web application framework in Python.
- OpenAI API: Provides access to advanced AI models for text generation.
- Together API: Another AI service for text generation.
- Hugging Face API: Used for generating images from text prompts.
- Firebase: For secure user authentication and management.
- SQLite: A lightweight, serverless database used for storing PDF metadata and API keys.
- ReportLab: A library for creating PDFs from dynamic data.
- aiohttp: An asynchronous HTTP client/server for Python.
- asyncio: Python library for writing single-threaded concurrent code using coroutines.
- Python 3.7+
- pip (Python package installer)
- Virtualenv (optional but recommended)
-
Clone the repository:
git clone https://github.com/your-repo/ai-book-generator.git cd ai-book-generator
-
Set up a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Set environment variables: Create a
.env
file in the root directory and add the following:OPENAI_API_KEY=your_openai_api_key TOGETHER_API_KEY=your_together_api_key GETIMG_API_KEY=your_getimg_api_key
-
Initialize the database:
python >>> from app import init_db >>> init_db() >>> exit()
-
Run the application:
flask run
The application uses environment variables for configuration. Ensure that the following variables are set in your .env
file:
OPENAI_API_KEY
: Your OpenAI API key.TOGETHER_API_KEY
: Your Together API key.GETIMG_API_KEY
: Your Hugging Face API key.
-
Access the web application: Open your browser and navigate to
http://localhost:5000
. -
Navigate to the playground: Click on the "Playground" link in the navigation menu.
-
Select your preferences:
- Choose the AI model (OpenAI or Together).
- Enter the topic for your book.
- Select the language.
- Specify the target word count.
-
Generate the book: Click on the "Generate Book" button. The progress of the book generation will be displayed.
-
Once the book is generated: The content will be displayed on the screen.
-
Download the PDF: Click on the "Download PDF" button to save the book as a PDF file.
-
Navigate to the API page: Click on the "API" link in the navigation menu.
-
Generate a new API key: Click on the "Generate API Key" button. Your new API key will be displayed.
-
View and manage your API keys: Your existing API keys will be listed on the page. You can revoke or regenerate keys as needed.
-
Register a new account:
- Navigate to the "Auth" page.
- Click on the "Register" button.
- Enter your email, password, and phone number.
- Click on the "Register" button to create your account.
-
Log in to your account:
- Navigate to the "Auth" page.
- Click on the "Login" button.
- Enter your email and password.
- Click on the "Login" button to access your account.
-
Navigate to the image generation page: Click on the "Generate Image" link in the navigation menu.
-
Enter a text prompt: Type a description of the image you want to generate.
-
Generate the image: Click on the "Generate Image" button. The generated image will be displayed on the screen.
The API allows for programmatic access to the book generation functionality. Refer to the API Documentation for detailed information on available endpoints and how to use them.
- POST /generate-book: Generate a book using the specified AI model, topic, language, and word count.
- POST /generate-api-key: Generate a new API key for accessing the API.
- POST /generate-image: Generate an image based on a text prompt.
-
Generate Book:
{ "api": "openai", "model": "gpt-3.5-turbo", "topic": "Artificial Intelligence", "language": "English", "word_count": 5000 }
-
Generate API Key:
{}
-
Generate Image:
{ "prompt": "A futuristic cityscape at night" }
-
Generate Book:
{ "content": "Book content here...", "word_count": 5000 }
-
Generate API Key:
{ "api_key": "your_new_api_key" }
-
Generate Image:
{ "output": "data:image/png;base64,image_data_here" }
- API Key Issues: Ensure that your API keys are correctly set in the
.env
file and are valid. - Database Issues: If you encounter issues with the database, ensure that the SQLite database is correctly initialized and accessible.
- Authentication Issues: If you have trouble logging in or registering, ensure that your Firebase credentials are correctly configured.
Contributions are welcome! Please read the contributing guidelines before getting started.
This project is licensed under the MIT License. See the LICENSE file for details.