Spaces:
Sleeping
Sleeping
tensorkelechi
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -28,7 +28,7 @@ def initialize_resources():
|
|
28 |
)
|
29 |
return llm_gemini
|
30 |
|
31 |
-
|
32 |
def get_retriever(pdf_file):
|
33 |
with NamedTemporaryFile(suffix="pdf") as temp:
|
34 |
temp.write(pdf_file.getvalue())
|
@@ -47,9 +47,9 @@ def get_retriever(pdf_file):
|
|
47 |
)
|
48 |
documents = text_splitter.split_documents(pages)
|
49 |
vectorstore = faiss.FAISS.from_documents(documents, underlying_embeddings)
|
50 |
-
doc_retiever = vectorstore.as_retriever(
|
51 |
-
|
52 |
-
)
|
53 |
|
54 |
return doc_retiever
|
55 |
|
@@ -91,12 +91,12 @@ course_material = st.file_uploader("or Upload your own pdf", type="pdf")
|
|
91 |
if st.session_state != "":
|
92 |
try:
|
93 |
if st.button("load"):
|
94 |
-
with st.
|
95 |
doc_retriever = get_retriever(course_material)
|
96 |
|
97 |
st.success("File loading successful, vector db initialize")
|
98 |
-
except:
|
99 |
-
st.error(
|
100 |
|
101 |
# We store the conversation in the session state.
|
102 |
# This will be use to render the chat conversation.
|
|
|
28 |
)
|
29 |
return llm_gemini
|
30 |
|
31 |
+
@st.cache_data
|
32 |
def get_retriever(pdf_file):
|
33 |
with NamedTemporaryFile(suffix="pdf") as temp:
|
34 |
temp.write(pdf_file.getvalue())
|
|
|
47 |
)
|
48 |
documents = text_splitter.split_documents(pages)
|
49 |
vectorstore = faiss.FAISS.from_documents(documents, underlying_embeddings)
|
50 |
+
doc_retiever = vectorstore.as_retriever()
|
51 |
+
# search_type="mmr", search_kwargs={"k": 5, "fetch_k": 10}
|
52 |
+
#)
|
53 |
|
54 |
return doc_retiever
|
55 |
|
|
|
91 |
if st.session_state != "":
|
92 |
try:
|
93 |
if st.button("load"):
|
94 |
+
with st.spinner("loading document.."):
|
95 |
doc_retriever = get_retriever(course_material)
|
96 |
|
97 |
st.success("File loading successful, vector db initialize")
|
98 |
+
except Exception as e:
|
99 |
+
st.error(e)
|
100 |
|
101 |
# We store the conversation in the session state.
|
102 |
# This will be use to render the chat conversation.
|