Update app.py
Browse files
app.py
CHANGED
@@ -17,7 +17,6 @@ from loguru import logger
|
|
17 |
|
18 |
st.set_page_config(page_title="Talk2Book", page_icon="π")
|
19 |
|
20 |
-
|
21 |
#### sidebar section 1 ####
|
22 |
with st.sidebar:
|
23 |
book = st.radio("Choose a book: ",
|
@@ -27,7 +26,6 @@ with st.sidebar:
|
|
27 |
BOOK_NAME = book.split("-")[0][:-1] # "1984 - George Orwell" -> "1984"
|
28 |
AUTHOR_NAME = book.split("-")[1][1:] # "1984 - George Orwell" -> "George Orwell"
|
29 |
|
30 |
-
|
31 |
st.title(f"Talk2Book: {BOOK_NAME}")
|
32 |
st.markdown(f"#### Have a conversation with {BOOK_NAME} by {AUTHOR_NAME} π")
|
33 |
|
@@ -64,7 +62,6 @@ def load_vectorstore():
|
|
64 |
|
65 |
return docsearch
|
66 |
|
67 |
-
|
68 |
@st.experimental_memo(show_spinner=False)
|
69 |
def load_prompt(book_name, author_name):
|
70 |
prompt_template = f"""You're an AI version of {AUTHOR_NAME}'s book '{BOOK_NAME}' and are supposed to answer quesions people have for the book. Thanks to advancements in AI people can now talk directly to books.
|
@@ -85,7 +82,6 @@ def load_prompt(book_name, author_name):
|
|
85 |
|
86 |
return PROMPT
|
87 |
|
88 |
-
|
89 |
@st.experimental_singleton(show_spinner=False)
|
90 |
def load_chain():
|
91 |
llm = OpenAI(temperature=0.2)
|
@@ -101,7 +97,6 @@ def load_chain():
|
|
101 |
|
102 |
return chain
|
103 |
|
104 |
-
|
105 |
def get_answer(question):
|
106 |
chain = load_chain()
|
107 |
result = chain({"query": question})
|
@@ -136,22 +131,21 @@ def get_answer(question):
|
|
136 |
with st.sidebar:
|
137 |
api_key = st.text_input(label = "And paste your OpenAI API key here to get started",
|
138 |
type = "password",
|
139 |
-
help = "This isn't saved π"
|
140 |
-
|
|
|
141 |
# os.environ["OPENAI_API_KEY"] = api_key
|
142 |
|
143 |
st.markdown("---")
|
144 |
|
145 |
st.info("Based on [Talk2Book](https://github.com/batmanscode/Talk2Book)")
|
146 |
|
147 |
-
|
148 |
##### main ####
|
149 |
# user_input = st.text_input("Your question", "Who are you?", key="input")
|
150 |
|
151 |
_ = """Bitcoin, when used properly, allows anyone to transact privately. Big brother won't be able to watch anyone. Could the people in your book use Bitcoin as a tool to escape oppression? And how do you think the state will respond?"""
|
152 |
user_input = st.text_input("Your question", _, key="input")
|
153 |
|
154 |
-
|
155 |
col1, col2 = st.columns([10, 1])
|
156 |
|
157 |
# show question
|
|
|
17 |
|
18 |
st.set_page_config(page_title="Talk2Book", page_icon="π")
|
19 |
|
|
|
20 |
#### sidebar section 1 ####
|
21 |
with st.sidebar:
|
22 |
book = st.radio("Choose a book: ",
|
|
|
26 |
BOOK_NAME = book.split("-")[0][:-1] # "1984 - George Orwell" -> "1984"
|
27 |
AUTHOR_NAME = book.split("-")[1][1:] # "1984 - George Orwell" -> "George Orwell"
|
28 |
|
|
|
29 |
st.title(f"Talk2Book: {BOOK_NAME}")
|
30 |
st.markdown(f"#### Have a conversation with {BOOK_NAME} by {AUTHOR_NAME} π")
|
31 |
|
|
|
62 |
|
63 |
return docsearch
|
64 |
|
|
|
65 |
@st.experimental_memo(show_spinner=False)
|
66 |
def load_prompt(book_name, author_name):
|
67 |
prompt_template = f"""You're an AI version of {AUTHOR_NAME}'s book '{BOOK_NAME}' and are supposed to answer quesions people have for the book. Thanks to advancements in AI people can now talk directly to books.
|
|
|
82 |
|
83 |
return PROMPT
|
84 |
|
|
|
85 |
@st.experimental_singleton(show_spinner=False)
|
86 |
def load_chain():
|
87 |
llm = OpenAI(temperature=0.2)
|
|
|
97 |
|
98 |
return chain
|
99 |
|
|
|
100 |
def get_answer(question):
|
101 |
chain = load_chain()
|
102 |
result = chain({"query": question})
|
|
|
131 |
with st.sidebar:
|
132 |
api_key = st.text_input(label = "And paste your OpenAI API key here to get started",
|
133 |
type = "password",
|
134 |
+
help = "This isn't saved π")
|
135 |
+
logger.debug(f"sidebar api_key provided {api_key} ")
|
136 |
+
|
137 |
# os.environ["OPENAI_API_KEY"] = api_key
|
138 |
|
139 |
st.markdown("---")
|
140 |
|
141 |
st.info("Based on [Talk2Book](https://github.com/batmanscode/Talk2Book)")
|
142 |
|
|
|
143 |
##### main ####
|
144 |
# user_input = st.text_input("Your question", "Who are you?", key="input")
|
145 |
|
146 |
_ = """Bitcoin, when used properly, allows anyone to transact privately. Big brother won't be able to watch anyone. Could the people in your book use Bitcoin as a tool to escape oppression? And how do you think the state will respond?"""
|
147 |
user_input = st.text_input("Your question", _, key="input")
|
148 |
|
|
|
149 |
col1, col2 = st.columns([10, 1])
|
150 |
|
151 |
# show question
|