Coder Social home page Coder Social logo

bookgpt's Introduction

BookGPT (Beta)

This program uses the ChatGPT API to generate books based on your specified parameters.

Installation

To install this program, simply follow these steps:

  1. Clone this repository to your local machine by running the following command in your terminal:
git clone https://github.com/mikavehns/BookGPT.git
  1. Navigate to the root directory of the repository using cd BookGPT
  2. Install the required dependencies by running the following command:
pip install -r requirements.txt

Prerequisites

In order to use this program, you must have a ChatGPT API key. The API Key must then be inserted into the config.json file.

Usage

To use this program, simply run the following command in your terminal:

python run.py

You will then be prompted to enter the following information:

  • Chapter Amount: The amount of chapters you want the book to have.
  • Chapter Length: The amount of words you want each chapter to have.
  • Topic: The topic you want the book to be about.
  • Category: The type of book you want to generate. (Science, Biography, etc.)

The program will then generate a Title and Chapter Titles + Content. You will get a detailed structure of the book. The generated books will then be saved as book.md in BookGPT/src.

Examples

Here are some examples:

  • Generate book with 5 chapters and 300 words per chapter, with quotes as chapter title, with the topic "success":
the_path_to_success.mp4
  • You can see all examples in the examples/ directory.

Notes

  • The run.py file is just one example on how to use the book generator. You can also implement it into a website, discord bot, desktop app, etc.
  • The program may take some time to run, depending on the specified parameters and the performance of the ChatGPT API. Please be patient while the book is being generated.
  • The program may not always generate the wished amount of words for each chapter. This can happen, if there is not enough data available for the specified topic.
  • Currently, it is only possible to generate Non-Fiction books.
  • Since this is a really early version (v0.8.0), there are many missing features, that will be added by time

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

  • If you are interested in contributing to BookGPT, I welcome any suggestions or pull requests. Please feel free to open an issue or submit a pull request on the GitHub repository.
  • You can also submit your books, which I will then add to the examples folder. Just open a pull request with the book in the examples folder.

bookgpt's People

Contributors

mikavehns avatar robthepcguy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bookgpt's Issues

Misspelled Language

Describe the bug
If you misspell the Language, then it will crash
Eg. for English I used accidentally Enflish

To Reproduce
Steps to reproduce the behavior:
Run the program
Give Enflish as a language
A clear and concise description of what you expected to happen.
It can be auto correct or only accept only expected.
Screenshots
Generating a book with 2 chapters, 1000 words per chapter, topic "Visit to Wales" and category "Travel" in Enflish.
Initializing..
Traceback (most recent call last):
File "C:\Development\Python\BookGPT\src\run.py", line 121, in
main()
File "C:\Development\Python\BookGPT\src\run.py", line 93, in main
book = Book(chapters, words, topic, category, language)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Development\Python\BookGPT\src\book.py", line 60, in init
self.structure = self.get_structure()
^^^^^^^^^^^^^^^^^^^^
File "C:\Development\Python\BookGPT\src\book.py", line 171, in get_structure
word_count = paragraph.split('---')[1]
~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
.

Windows 11
Python 11

Move keys to .env

Right now the openai key is put in a json doc. A more failsafe pattern is to store it in a .env file, .gitignore it, and use the dotenv package or pipenv to load the value & then check os.environ["KEY"] for the key. This is an extremely common pattern and there are many tutorials and tools specifically for this scenario.

When you accidentally check in your key, (or people who fork this do) you'll have to delete your key and regenerate new ones because git still shows keys in history.

Word length of outputted novel is long if too many chapter x word count are selected

If you try to generate a novel with 33 chapters, each of which is 3333 words, the expected length should be around 1,099,989 words. The program in its current state outputs 8993 words.

I'm sure this is a ChatGPT restriction, or one placed internally in the source code, but more information should be outputted to the user to inform them of expected word length vs outputted word length, why it didn't generate as many words as it would like, and other useful information an end user might want to know. This is a partial feature request, I can do a pull request if you're willing to integrate the feature into the app.

Rate limit reached

Describe the bug
When running the application it runs into exceeding the openai rate limit. This happens on the free plan (with 18 USD grant).
It's also not clear at which point precisely it breaks off, and which limit precisely is exceeded.
In one try it ended after 4 requests using 1746 tokens, and on the 2nd try it ran for 10 requests and 4186 tokens.

To Reproduce
Steps to reproduce the behavior:
Start a new book. (on a free plan)
The book should have had 5 chapters with 300 words each in english.
Start creation of the book
Wait for the error to be thrown

Expected behavior
Catching the Exception, and "slowing down" the requests / avoid exceeding the rate limit.

Desktop (please complete the following information):

  • OS: Windows 10, Python 3.10.6

Additional context
Thanks for the Project! I am working on something similar, trying to have GPT write longer fiction stories. Still did not figure out, how to keep it close to the "story"line.

PDF Format Saver, MP3 Saver

There should be a way of saving as pdf and mp3. A user must be able to save in multiple file format also. Thus it will become more useful

Word input at BookGPT

Hello good evening

Now the generation of the books works for me.
However, the interface looks different from the video in the tutorial.
My question: Why can you enter only 5 chapters and the word length 300.
It would be great if you could choose how many chapters you want to have from 5 to 50 chapters or so. And the words from 300 to 2000 words. Hope you understand what I mean ?
If you enter 10 chapters, then comes an Erorr message.
I thought chatGPT is free, why do you need these stupid tokens ?
Hope you can change this soon ?

But a great idea from you, then no need to make it cumbersome with chatGPT. THANKS A LOT

Thanks a lot and all the best
Greetings Michael

getting error when generating the book

Generating a book with 2 chapters, 200 words per chapter, topic "How can I stay motivated" and category "SelfImprovement" in english.
Initializing..
Traceback (most recent call last):
File "C:\Users\adria\BookGPT\src\run.py", line 121, in
main()
File "C:\Users\adria\BookGPT\src\run.py", line 93, in main
book = Book(chapters, words, topic, category, language)
File "C:\Users\adria\BookGPT\src\book.py", line 56, in init
self.structure = self.get_structure()
File "C:\Users\adria\BookGPT\src\book.py", line 167, in get_structure
word_count = paragraph.split('---')[1]
IndexError: list index out of range

Add images (generated or research)

Is your feature request related to a problem? Please describe.
I would like it to be possible to generate books with images generated from Dalle or images related to the subject found on a free library.

We could add a question during the launch: do you want images?

If the person answers yes then we add images.

For image generation we would take the last x words to generate an image.

To look for an image on a free bookstore we would do a search with the title of the book or we ask gpt3 to tell us directly which image would be good to schematize the subject. (we would add below the image in the final result the link to the source)

Additional context
I will try to develop this feature, I will make a pull request!

# add a 20-second delay between API calls for free account users

Is your feature request related to a problem? Please describe.
openai.error.RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-xxx on requests per min. Limit: 3 / min. Please try again in 20s. Contact [email protected] if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method.

Describe the solution you'd like
I would like to allow free-account users to try and enjoy this program.

Describe alternatives you've considered
book.py

@staticmethod
def get_response(prompt):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-0301",
messages=prompt
)["choices"][0]["message"]["content"]
time.sleep(20) # add a 20-second delay between API calls
return response

This has worked well for me. The generation becomes really slow, but it could be a good fix.

Maybe we can add a condition beforehand to let players choose if they use a free or premium account? And hide the waiting time from those who have premium plans.

Additional context
Add any other context or screenshots about the feature request here.

Installing requirements.txt

I get this error message every time I use the command " pip install -r requirements.txt "

I might just be doing something wrong, but maybe some one smarter than me knows what I'm doing wrong :)

ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'

Slight issue in documentation regarding how to install packages

Describe the bug

pip install -r requirements.txt doesn't work if you are in the BookGPT/src folder, instead need to use pip install -r ../requirements.txt or a similar workaround (would installing from BookGPT root folder work? I'm not that familiar with python yet).

Not a big deal, but ensures beginners install their packages successfully in case they don't know what they're doing (such as non coders who want to take advantage of this repository).

"No such file or directory" run.py

Hello all. Can someone please help me ?
I keep getting this error message "PS C:\Users\micha\BookGPT> python run.py.
C:\Users\micha\AppData\Local\Programs\Python\Python311\python.exe: can't open file 'C:\Users\micha\BookGPT\run.py': [Errno 2] No such file or directory
PS C:\Users\micha\BookGPT> " . I cannot start the program.

The file run.py is not in the src folder !

The above error is gone. Now there is a new error
PS C:\Users\micha\BookGPT> python run.py
Traceback (most recent call last):
File "C:\Users\micha\BookGPT\run.py", line 3, in
from book import Book
ModuleNotFoundError: No module named 'book'.
I had to install an older version of Plython.

Hope someone can help me ? I appreciate it very much.

Thanks a lot and all the best
Greetings Michael

Problems running the python run.py

When I use my terminal to execute the command python run.py, this returns. I have tried fixing it myself, but nothing really seems to work. Maybe I'm just doing something wrong? Or maybe it's a bug I don't know.

Does anyone know a fix to this problem?

Traceback (most recent call last): File "C:\Users.....\BookGPT\src\run.py", line 3, in from book import Book File "C:\Users.....\BookGPT\src\book.py", line 1, in import openai ModuleNotFoundError: No module named 'openai'

TypeError: 'type' object is not subscriptable

Describe the bug
TypeError when loading selfimprovement.py

To Reproduce
Steps to reproduce the behavior:

  1. Clone repository git clone https://github.com/mikavehns/BookGPT.git
  2. Install requirements pip install -r requirements.txt
  3. Run python run.py
  4. See error

Expected behavior
Interactive menu/CLI should appear.

Severity
Program does not work at all.

Error Logs
Traceback (most recent call last):
File "run.py", line 3, in <module>
from book import Book
File "/home/noa/Documents/BookGPT/src/book.py", line 3, in <module>
from categories import *
File "/home/noa/Documents/BookGPT/src/categories/__init__.py", line 1, in <module>
from .selfimprovement import SelfImprovement
File "/home/noa/Documents/BookGPT/src/categories/selfimprovement.py", line 6, in <module>
class SelfImprovement:
File "/home/noa/Documents/BookGPT/src/categories/selfimprovement.py", line 69, in SelfImprovement
def get_structure(self, title: str, chapters: list[str]):
TypeError: 'type' object is not subscriptable
image

Desktop info

  • OS: Zorin OS 16.2 x86_64
  • Kernel: 5.15.0-46-generic
  • Python Version: Python 3.8.10

Additional info
Using python-is-python3, which means running python run.py actually runs python3 run.py. Ran the screenshot with python3 directly in case that module was at fault.

First book work, second fail (just title when I saved)

Describe the bug
I generated a first book and everything went well (12 chapters and 5000 words). When I tried to generate a second book, it runs for x time and after when it asks me to save I chose .md and it saves me only the title. I first thought of a credit problem but I did not exceed my quota at all.

To Reproduce
Steps to reproduce the behavior:

  1. Generate first book
  2. Try to generate a second book

Screenshots
image
Uploading image.png…

Desktop (please complete the following information):

  • OS: Windows 10

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.