Update app.py
Browse files
app.py
CHANGED
|
@@ -68,7 +68,6 @@ def load_chatbot():
|
|
| 68 |
def main():
|
| 69 |
st.title("BinDocs Chat App")
|
| 70 |
|
| 71 |
-
pdf = st.file_uploader("Upload your PDF", type="pdf")
|
| 72 |
|
| 73 |
if "chat_history" not in st.session_state:
|
| 74 |
st.session_state['chat_history'] = []
|
|
@@ -82,23 +81,26 @@ def main():
|
|
| 82 |
st.write("<div style='flex: 1;'></div>", unsafe_allow_html=True)
|
| 83 |
st.write("<!-- End Spacer -->", unsafe_allow_html=True)
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
|
| 101 |
-
|
| 102 |
|
| 103 |
# Display new messages at the bottom
|
| 104 |
new_messages = st.session_state['chat_history'][-2:]
|
|
|
|
| 68 |
def main():
|
| 69 |
st.title("BinDocs Chat App")
|
| 70 |
|
|
|
|
| 71 |
|
| 72 |
if "chat_history" not in st.session_state:
|
| 73 |
st.session_state['chat_history'] = []
|
|
|
|
| 81 |
st.write("<div style='flex: 1;'></div>", unsafe_allow_html=True)
|
| 82 |
st.write("<!-- End Spacer -->", unsafe_allow_html=True)
|
| 83 |
|
| 84 |
+
|
| 85 |
+
pdf = st.file_uploader("Upload your PDF", type="pdf")
|
| 86 |
+
|
| 87 |
+
if pdf is not None:
|
| 88 |
+
query = st.text_input("Ask questions about your PDF file (in any preferred language):")
|
| 89 |
|
| 90 |
+
if st.button("Ask") or (query and query != st.session_state.get('last_input', '')):
|
| 91 |
+
st.session_state['last_input'] = query # Save the current query as the last input
|
| 92 |
+
st.session_state['chat_history'].append(("User", query, "new"))
|
| 93 |
|
| 94 |
+
loading_message = st.empty()
|
| 95 |
+
loading_message.text('Bot is thinking...')
|
| 96 |
|
| 97 |
+
VectorStore = load_pdf(pdf)
|
| 98 |
+
chain = load_chatbot()
|
| 99 |
+
docs = VectorStore.similarity_search(query=query, k=3)
|
| 100 |
+
with get_openai_callback() as cb:
|
| 101 |
+
response = chain.run(input_documents=docs, question=query)
|
| 102 |
|
| 103 |
+
st.session_state['chat_history'].append(("Bot", response, "new"))
|
| 104 |
|
| 105 |
# Display new messages at the bottom
|
| 106 |
new_messages = st.session_state['chat_history'][-2:]
|