-
Notifications
You must be signed in to change notification settings - Fork 0
Home
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.
-
Python 3.x
-
cohere
Python package -
pdfkit
Python package -
markdown
Python package -
wkhtmltopdf
installed on your system
AI Ebook Generator is compatible with the following platforms:
-
Windows
-
Mac
-
Linux
Before running the app, ensure that you have Python installed on your system along with the necessary dependencies:
- Python 3.x
- Install Python Packages:
Ensure you have the required Python packages installed:
pip install -r requirements.txt
- Install wkhtmltopdf:
-
For Windows: Download and install from wkhtmltopdf.org and make sure it's added to your system's PATH. Use the provided
add_wkhtmltopdf-to-path.bat
script to set up the PATH variable. -
For macOS: Use Homebrew:
brew install wkhtmltopdf
. -
For Linux: Use your package manager, e.g.,
sudo apt-get 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.
- 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'
- Templates:
HTML templates are present in the templates
folder:
-
classic.html
-
modern.html
-
minimalist.html
-
elegant.html
-
dark.html
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 {{MARKDOWN_CONTENT}}
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_CONTENT}}
</markdown>
<script src="https://cdn.jsdelivr.net/npm/showdown/dist/showdown.min.js"></script>
</body>
</html>
- Run the Script:
python main.py
-
Enter the eBook topic.
-
Specify the number of chapters.
-
Choose a template from the provided options.
-
Generate the eBook content.
-
Convert the content to HTML.
-
Embed the HTML content into the selected template.
-
Convert the final HTML to a PDF.
Running the script:
python main.py
-
Enter the eBook topic: "The Future of AI"
-
Enter the number of chapters: 5
-
Choose a template (1-5): 2 (Modern)
The script will produce ebook.pdf
with the generated content styled according to the chosen template.
-
add_wkhtmltopdf-to-path.bat
: A batch script to addwkhtmltopdf
to the systemPATH
on Windows. -
config.py
: Contains the API Key. -
main.py
: The Main Program -
requirements.txt
: The Project Requirements. -
templates/
: this folder contains all default templates
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.
We welcome contributions to enhance this project! Please refer to our Contributing Guidelines for detailed instructions on how to contribute.
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.