Update app.py
Browse files
app.py
CHANGED
|
@@ -22,8 +22,6 @@ with st.sidebar:
|
|
| 22 |
else:
|
| 23 |
st.warning('API key is required to proceed.')
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
st.markdown(
|
| 28 |
"Experience the future of document interaction with the revolutionary"
|
| 29 |
)
|
|
@@ -93,40 +91,22 @@ def main():
|
|
| 93 |
pdf = st.file_uploader("Upload your PDF", type="pdf")
|
| 94 |
|
| 95 |
if pdf is not None:
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
if st.button("Ask") or (query and query != st.session_state.get('last_input', '')):
|
| 99 |
-
st.session_state['last_input'] = query # Save the current query as the last input
|
| 100 |
-
st.session_state['chat_history'].append(("User", query, "new"))
|
| 101 |
-
|
| 102 |
-
loading_message = st.empty()
|
| 103 |
-
loading_message.text('Bot is thinking...')
|
| 104 |
-
|
| 105 |
-
VectorStore = load_pdf(pdf)
|
| 106 |
-
chain = load_chatbot()
|
| 107 |
-
docs = VectorStore.similarity_search(query=query, k=3)
|
| 108 |
-
with get_openai_callback() as cb:
|
| 109 |
-
response = chain.run(input_documents=docs, question=query)
|
| 110 |
|
| 111 |
-
st.
|
|
|
|
|
|
|
| 112 |
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
loading_message.empty()
|
| 123 |
-
|
| 124 |
-
# Clear the input field by setting the query variable to an empty string
|
| 125 |
-
query = ""
|
| 126 |
-
|
| 127 |
-
# Mark all messages as old after displaying
|
| 128 |
-
st.session_state['chat_history'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history']]
|
| 129 |
|
|
|
|
| 130 |
|
| 131 |
# Display new messages at the bottom
|
| 132 |
new_messages = st.session_state['chat_history'][-2:]
|
|
@@ -145,6 +125,5 @@ def main():
|
|
| 145 |
# Mark all messages as old after displaying
|
| 146 |
st.session_state['chat_history'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history']]
|
| 147 |
|
| 148 |
-
|
| 149 |
if __name__ == "__main__":
|
| 150 |
main()
|
|
|
|
| 22 |
else:
|
| 23 |
st.warning('API key is required to proceed.')
|
| 24 |
|
|
|
|
|
|
|
| 25 |
st.markdown(
|
| 26 |
"Experience the future of document interaction with the revolutionary"
|
| 27 |
)
|
|
|
|
| 91 |
pdf = st.file_uploader("Upload your PDF", type="pdf")
|
| 92 |
|
| 93 |
if pdf is not None:
|
| 94 |
+
query = st.text_input("Ask questions about your PDF file (in any preferred language):")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
+
if st.button("Ask") or (query and query != st.session_state.get('last_input', '')):
|
| 97 |
+
st.session_state['last_input'] = query # Save the current query as the last input
|
| 98 |
+
st.session_state['chat_history'].append(("User", query, "new"))
|
| 99 |
|
| 100 |
+
loading_message = st.empty()
|
| 101 |
+
loading_message.text('Bot is thinking...')
|
| 102 |
+
|
| 103 |
+
VectorStore = load_pdf(pdf)
|
| 104 |
+
chain = load_chatbot()
|
| 105 |
+
docs = VectorStore.similarity_search(query=query, k=3)
|
| 106 |
+
with get_openai_callback() as cb:
|
| 107 |
+
response = chain.run(input_documents=docs, question=query)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
+
st.session_state['chat_history'].append(("Bot", response, "new"))
|
| 110 |
|
| 111 |
# Display new messages at the bottom
|
| 112 |
new_messages = st.session_state['chat_history'][-2:]
|
|
|
|
| 125 |
# Mark all messages as old after displaying
|
| 126 |
st.session_state['chat_history'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history']]
|
| 127 |
|
|
|
|
| 128 |
if __name__ == "__main__":
|
| 129 |
main()
|