forked from hartnady/bookwriter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
72 lines (56 loc) · 1.87 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import streamlit as st
import openai
import time
import json
import transformers
import re
import datetime
import sys
import os
from mailmerge import MailMerge
from tqdm import tqdm
from dotenv import load_dotenv
MAX_TOKEN_COUNT = 4097
GPT_MODEL = "text-davinci-003"
GPT_TEMP = 0.5
GPT_FREQ = 0.0
GPT_PRES = 0.0
GBP_TOPP = 1.0
GPT_CALL_OUT_ON = True
PRINT_AS_YOU_GO = False
load_dotenv()
openai.api_key = os.environ.get("OPENAI_API_KEY")
def cprint(text):
global PRINT_AS_YOU_GO
if PRINT_AS_YOU_GO:
st.write(text)
# Other helper functions (remove_digits_period, remove_chapter, token_count, gpt_complete) remain unchanged
def generate_book():
title = st.text_input("Give your book a title:")
author = st.text_input("Enter your name:")
conception_date = str(datetime.datetime.now().date())
print_output = st.checkbox("Show results in real-time")
if print_output:
global PRINT_AS_YOU_GO
PRINT_AS_YOU_GO = True
subject = st.text_area("What is your book about? This book is about...")
if st.button("Generate Book"):
st.write("Generating your book... Please wait.")
st.info("This might take a while...")
# Rest of the logic remains the same
st.success("Book generation completed!")
st.write("Output files:")
st.write("RAW TEXT: " + output_file)
st.write("JSON: " + output_file.replace('txt','json'))
st.write("DOCX: " + output_file.replace('txt','docx'))
def main():
st.title("Book Generation App")
st.write("Welcome to the Book Generation App!")
st.write("Create a book's table of contents and content using AI.")
load_dotenv()
st.write(
"Note: This app uses the OpenAI API to generate content. Make sure you have set your OpenAI API key as an environment variable."
)
generate_book()
if __name__ == '__main__':
main()