Update app.py
Browse files
app.py
CHANGED
@@ -100,32 +100,8 @@ def get_conversation_chain():
|
|
100 |
|
101 |
|
102 |
return rag_chain
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
def main():
|
115 |
-
st.set_page_config(page_title="Chat with multiple PDFs", page_icon=":books:")
|
116 |
-
st.write(css, unsafe_allow_html=True)
|
117 |
-
|
118 |
-
st.header("Chat with multiple PDFs :books:")
|
119 |
-
|
120 |
-
vectorstore = None
|
121 |
-
conversation = None
|
122 |
-
|
123 |
-
|
124 |
-
if user_question := st.text_input("Ask a question about your documents:"):
|
125 |
-
handle_userinput(user_question, vectorstore, conversation)
|
126 |
-
|
127 |
-
|
128 |
|
|
|
129 |
with st.sidebar:
|
130 |
st.subheader("Your documents")
|
131 |
pdf_docs = st.file_uploader("For Chatbot to get alive, upload your PDFs here and click on 'Process'", accept_multiple_files=True)
|
@@ -138,18 +114,42 @@ def main():
|
|
138 |
# get pdf text
|
139 |
raw_text = get_pdf_text(pdf_docs)
|
140 |
|
141 |
-
|
142 |
text_chunks = get_text_chunks(raw_text)
|
143 |
|
144 |
# create vector store
|
145 |
vectorstore = get_vectorstore(text_chunks)
|
146 |
|
147 |
-
|
148 |
conversation = get_conversation_chain()
|
149 |
|
150 |
st.success("Files have been processed into a vector store.")
|
151 |
|
152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
|
154 |
|
155 |
|
@@ -176,11 +176,8 @@ def handle_userinput(user_question,vectorstore,conversation ):
|
|
176 |
|
177 |
retriever = vectorstore.as_retriever(search_type = 'mmr', search_kwargs={"k": 7})
|
178 |
docs = retriever.invoke(user_question)
|
179 |
-
|
180 |
-
|
181 |
-
with st.spinner("Processing"):
|
182 |
-
for doc in docs:
|
183 |
-
st.write(f"Document: {doc}")
|
184 |
|
185 |
doc_txt = [doc.page_content for doc in docs]
|
186 |
|
@@ -196,11 +193,10 @@ def handle_userinput(user_question,vectorstore,conversation ):
|
|
196 |
st.write(bot_template.replace(
|
197 |
"{{MSG}}", message['content']), unsafe_allow_html=True)
|
198 |
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
# st.write(doc.page_content)
|
204 |
|
205 |
|
206 |
|
|
|
100 |
|
101 |
|
102 |
return rag_chain
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
+
def sidebar():
|
105 |
with st.sidebar:
|
106 |
st.subheader("Your documents")
|
107 |
pdf_docs = st.file_uploader("For Chatbot to get alive, upload your PDFs here and click on 'Process'", accept_multiple_files=True)
|
|
|
114 |
# get pdf text
|
115 |
raw_text = get_pdf_text(pdf_docs)
|
116 |
|
117 |
+
|
118 |
text_chunks = get_text_chunks(raw_text)
|
119 |
|
120 |
# create vector store
|
121 |
vectorstore = get_vectorstore(text_chunks)
|
122 |
|
123 |
+
|
124 |
conversation = get_conversation_chain()
|
125 |
|
126 |
st.success("Files have been processed into a vector store.")
|
127 |
|
128 |
+
return vectorstore , conversation
|
129 |
+
|
130 |
+
|
131 |
+
|
132 |
+
|
133 |
+
|
134 |
+
|
135 |
+
|
136 |
+
|
137 |
+
|
138 |
+
|
139 |
+
|
140 |
+
def main():
|
141 |
+
st.set_page_config(page_title="Chat with multiple PDFs", page_icon=":books:")
|
142 |
+
st.write(css, unsafe_allow_html=True)
|
143 |
+
|
144 |
+
st.header("Chat with multiple PDFs :books:")
|
145 |
+
|
146 |
+
vectorstore , conversation = sidebar()
|
147 |
+
|
148 |
+
|
149 |
+
if user_question := st.text_input("Ask a question about your documents:"):
|
150 |
+
handle_userinput(user_question, vectorstore, conversation)
|
151 |
+
|
152 |
+
|
153 |
|
154 |
|
155 |
|
|
|
176 |
|
177 |
retriever = vectorstore.as_retriever(search_type = 'mmr', search_kwargs={"k": 7})
|
178 |
docs = retriever.invoke(user_question)
|
179 |
+
|
180 |
+
|
|
|
|
|
|
|
181 |
|
182 |
doc_txt = [doc.page_content for doc in docs]
|
183 |
|
|
|
193 |
st.write(bot_template.replace(
|
194 |
"{{MSG}}", message['content']), unsafe_allow_html=True)
|
195 |
|
196 |
+
st.subheader("Your documents")
|
197 |
+
|
198 |
+
for doc in docs:
|
199 |
+
st.write(f"Document: {doc}")
|
|
|
200 |
|
201 |
|
202 |
|