AI-eBook-Generator

This project generates an eBook based on user input using the Cohere AI model

View on GitHub

AI eBook Generator

AI eBook Generator

Overview

This project generates an eBook based on user input using the Cohere AI model. The eBook content is formatted in Markdown, converted to HTML using a selected template, and then rendered as a PDF. The workflow includes generating content, converting it to HTML, embedding it in a chosen template, and converting the final HTML to a styled PDF.

Requirements

Platforms

AI Ebook Generator is compatible with the following platforms:

Prerequisites

Before running the app, ensure that you have Python installed on your system along with the necessary dependencies:

Installation

  1. Install Python Packages:

Ensure you have the required Python packages installed:

pip install -r requirements.txt
  1. Install wkhtmltopdf:

add_wkhtmltopdf-to-path.bat Script:

If you are using Windows, run the add_wkhtmltopdf-to-path.bat script to automatically add wkhtmltopdf to your PATH. You can find this script in the project directory.

Make sure to adjust the path in the script to match where wkhtmltopdf is installed on your system.

  1. Prepare Configuration:

Create a file named config.py and replace your-cohere-api-key with your actual Cohere API key:

# config.py
COHERE_API_KEY = 'your-cohere-api-key'

Usage

  1. Templates:

HTML templates are present in the templates folder:

These are the default templates that comes with this app. but you can make your own template too.

Each template should have the following structure, with `` as a placeholder for the eBook content:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>eBook - Classic</title>
    <style>
        body {
            font-family: 'Times New Roman', serif;
            line-height: 1.8;
            margin: 0;
            padding: 30px;
            background-color: #f5f5f5;
        }
        h1, h2, h3, h4, h5, h6 {
            color: #333;
        }
        p {
            margin: 15px 0;
        }
        code {
            background-color: #f4f4f4;
            padding: 4px 6px;
            border-radius: 4px;
        }
        pre {
            background-color: #f4f4f4;
            padding: 12px;
            border-radius: 4px;
            overflow-x: auto;
        }
    </style>
</head>
<body>
    <markdown>
        
    </markdown>
    <script src="https://cdn.jsdelivr.net/npm/showdown/dist/showdown.min.js"></script>
</body>
</html>


  1. Run the Script:

Execute the main.py script:

python main.py

Follow the prompts to:

The script will:

Example

Running the script:

python  main.py

The script will produce ebook.pdf with the generated content styled according to the chosen template.

Files

Project Structure

eBook-Generator/
	├── main.py
	├── config.py
	├── requirements.txt
	├── add_wkhtmltopdf-to-path.bat
	├── templates/
	│ ├── classic.html
	│ ├── modern.html
	│ ├── minimalist.html
	│ ├── elegant.html
	│ ├── dark.html

By following this guide, you should be able to generate an eBook in PDF format using different templates provided in the templates folder.

Contribution

We welcome contributions to enhance this project! Please refer to our Contributing Guidelines for detailed instructions on how to contribute.

Code of Conduct

We expect all contributors to adhere to our Code of Conduct. Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [your-email@example.com]. All complaints will be reviewed and investigated promptly and fairly.