This is a proof of concept that uses OpenAI's GPT-3.5 to modernize books.
For example, given this passage from Mary Shelley's The Last Man:
I visited Naples in the year 1818. On the 8th of December of that year, my companion and I crossed the Bay, to visit the antiquities which are scattered on the shores of Baiæ. The translucent and shining waters of the calm sea covered fragments of old Roman villas, which were interlaced by sea-weed, and received diamond tints from the chequering of the sun-beams; the blue and pellucid element was such as Galatea might have skimmed in her car of mother of pearl; or Cleopatra, more fitly than the Nile, have chosen as the path of her magic ship. Though it was winter, the atmosphere seemed more appropriate to early spring; and its genial warmth contributed to inspire those sensations of placid delight, which are the portion of every traveller, as he lingers, loath to quit the tranquil bays and radiant promontories of Baiæ.
GPT-3.5 modernizes it to:
I visited Naples in 1818. On December 8 of that year, my companion and I crossed the Bay to visit the ancient ruins scattered along the shores of Baiæ. The clear and sparkling waters of the calm sea covered remnants of old Roman villas, intertwined with seaweed and reflecting the sun's rays like diamonds. The blue and transparent element was so beautiful, it reminded me of the sea that Galatea might have skimmed in her mother-of-pearl chariot, or the path Cleopatra would have chosen for her magical ship, more fitting than the Nile. Despite it being winter, the atmosphere felt more like early spring, and its warm and pleasant temperature filled me with a serene delight as I hesitated to leave the peaceful bays and beautiful cliffs of Baiæ.
- Copy the code
- Install the requirements with
pip install -r requirements.txt
- Run with
streamlit run book_modernizer.py
- Enter your OpenAI API key, upload book text, and click "Modernize"
- Optionally: Modify the system prompt, such as to specify a particular flavor of output, like "modern science fiction"
As mentioned above, this is a proof of concept. So, take note:
- Processing a whole book will take a long time. This is because the code doesn't use asynchronous processing. Also, I haven't tested what happens when you try to process an entire book; it could break something.
- Improvement: Use asynchronous processing. Be sure to add rate-limiting to avoid exceeding OpenAI's rate limites.
- I haven't validated the token and cost estimation. So, use it at your own risk. Perhaps validate it on a small part of a book before running it on an entire book.
- Improvement: Validate the token and cost estimation.
- It only works with GPT-3.5. I've hard-coded this in.
- Improvement: Allow use with other models. This includes GPT-4, but also open source models, either locally or via an API. Note that this will affect token and cost estimation.