add another book: almanac of naval
Browse files
app.py
CHANGED
@@ -9,10 +9,12 @@ from langchain import OpenAI
|
|
9 |
from langchain import PromptTemplate
|
10 |
|
11 |
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
14 |
|
15 |
-
st.set_page_config(page_title="Talk2Book: 1984", page_icon="π")
|
16 |
st.title(f"Talk2Book: {BOOK_NAME}")
|
17 |
st.markdown(f"#### Have a conversation with {BOOK_NAME} by {AUTHOR_NAME} π")
|
18 |
|
@@ -23,18 +25,18 @@ st.markdown(f"#### Have a conversation with {BOOK_NAME} by {AUTHOR_NAME} π")
|
|
23 |
@st.experimental_singleton(show_spinner=False)
|
24 |
def load_vectorstore():
|
25 |
# download from hugging face
|
26 |
-
|
|
|
27 |
repo_type="dataset",
|
28 |
revision="main",
|
29 |
-
allow_patterns="
|
30 |
-
cache_dir=
|
31 |
)
|
32 |
|
33 |
-
|
34 |
-
target_dir = "vectorstore"
|
35 |
|
36 |
# Walk through the directory tree recursively
|
37 |
-
for root, dirs, files in os.walk(
|
38 |
# Check if the target directory is in the list of directories
|
39 |
if target_dir in dirs:
|
40 |
# Get the full path of the target directory
|
@@ -124,6 +126,13 @@ def get_answer(question):
|
|
124 |
|
125 |
##### sidebar ####
|
126 |
with st.sidebar:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
api_key = st.text_input(label = "Paste your OpenAI API key here to get started",
|
128 |
type = "password",
|
129 |
help = "This isn't saved π"
|
|
|
9 |
from langchain import PromptTemplate
|
10 |
|
11 |
|
12 |
+
st.set_page_config(page_title="Talk2Book", page_icon="π")
|
13 |
+
|
14 |
+
# set later in the sidebar section
|
15 |
+
BOOK_NAME = st.empty()
|
16 |
+
AUTHOR_NAME = st.empty()
|
17 |
|
|
|
18 |
st.title(f"Talk2Book: {BOOK_NAME}")
|
19 |
st.markdown(f"#### Have a conversation with {BOOK_NAME} by {AUTHOR_NAME} π")
|
20 |
|
|
|
25 |
@st.experimental_singleton(show_spinner=False)
|
26 |
def load_vectorstore():
|
27 |
# download from hugging face
|
28 |
+
cache_dir=f"{BOOK_NAME}_cache"
|
29 |
+
snapshot_download(repo_id="calmgoose/book-embeddings",
|
30 |
repo_type="dataset",
|
31 |
revision="main",
|
32 |
+
allow_patterns=f"books/{BOOK_NAME}/*",
|
33 |
+
cache_dir=cache_dir,
|
34 |
)
|
35 |
|
36 |
+
target_dir = f"books/{BOOK_NAME}/*"
|
|
|
37 |
|
38 |
# Walk through the directory tree recursively
|
39 |
+
for root, dirs, files in os.walk(cache_dir):
|
40 |
# Check if the target directory is in the list of directories
|
41 |
if target_dir in dirs:
|
42 |
# Get the full path of the target directory
|
|
|
126 |
|
127 |
##### sidebar ####
|
128 |
with st.sidebar:
|
129 |
+
book = st.radio("Choose book: ",
|
130 |
+
["1984 - George Orwell", "The Almanac of Naval Ravikant - Eric Jorgenson"]
|
131 |
+
)
|
132 |
+
# update st.empty() variables from earlier
|
133 |
+
BOOK_NAME = book.replace.split("-")[0][:-1] # "1984 - George Orwell" -> "1984"
|
134 |
+
AUTHOR_NAME = book.replace.split("-")[1][1:] # "1984 - George Orwell" -> "George Orwell"
|
135 |
+
|
136 |
api_key = st.text_input(label = "Paste your OpenAI API key here to get started",
|
137 |
type = "password",
|
138 |
help = "This isn't saved π"
|