Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,7 +12,8 @@ import os
|
|
| 12 |
|
| 13 |
# Sidebar contents
|
| 14 |
with st.sidebar:
|
| 15 |
-
|
|
|
|
| 16 |
# API key input (this will not display the entered text)
|
| 17 |
api_key = st.text_input('Enter your OpenAI API Key:', type='password')
|
| 18 |
|
|
@@ -22,7 +23,7 @@ with st.sidebar:
|
|
| 22 |
st.warning('API key is required to proceed.')
|
| 23 |
|
| 24 |
|
| 25 |
-
|
| 26 |
st.markdown(
|
| 27 |
"Experience the future of document interaction with the revolutionary"
|
| 28 |
)
|
|
@@ -88,7 +89,6 @@ def main():
|
|
| 88 |
st.write("<!-- End Spacer -->", unsafe_allow_html=True)
|
| 89 |
|
| 90 |
new_messages_placeholder = st.empty()
|
| 91 |
-
loading_message = st.empty()
|
| 92 |
|
| 93 |
pdf = st.file_uploader("Upload your PDF", type="pdf")
|
| 94 |
|
|
@@ -98,9 +98,10 @@ def main():
|
|
| 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.markdown("<div style='background-color: #FFA07A; padding: 10px; border-radius: 10px; margin: 10px;'>Bot is thinking...</div>", unsafe_allow_html=True)
|
| 103 |
|
|
|
|
|
|
|
|
|
|
| 104 |
VectorStore = load_pdf(pdf)
|
| 105 |
chain = load_chatbot()
|
| 106 |
docs = VectorStore.similarity_search(query=query, k=3)
|
|
@@ -127,5 +128,24 @@ def main():
|
|
| 127 |
st.session_state['chat_history'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history']]
|
| 128 |
|
| 129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
if __name__ == "__main__":
|
| 131 |
main()
|
|
|
|
| 12 |
|
| 13 |
# Sidebar contents
|
| 14 |
with st.sidebar:
|
| 15 |
+
st.title(':orange_book: BinDoc GmbH')
|
| 16 |
+
|
| 17 |
# API key input (this will not display the entered text)
|
| 18 |
api_key = st.text_input('Enter your OpenAI API Key:', type='password')
|
| 19 |
|
|
|
|
| 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 |
)
|
|
|
|
| 89 |
st.write("<!-- End Spacer -->", unsafe_allow_html=True)
|
| 90 |
|
| 91 |
new_messages_placeholder = st.empty()
|
|
|
|
| 92 |
|
| 93 |
pdf = st.file_uploader("Upload your PDF", type="pdf")
|
| 94 |
|
|
|
|
| 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)
|
|
|
|
| 128 |
st.session_state['chat_history'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history']]
|
| 129 |
|
| 130 |
|
| 131 |
+
|
| 132 |
+
# Display new messages at the bottom
|
| 133 |
+
new_messages = st.session_state['chat_history'][-2:]
|
| 134 |
+
for chat in new_messages:
|
| 135 |
+
background_color = "#FFA07A" if chat[2] == "new" else "#acf" if chat[0] == "User" else "#caf"
|
| 136 |
+
new_messages_placeholder.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{chat[0]}: {chat[1]}</div>", unsafe_allow_html=True)
|
| 137 |
+
|
| 138 |
+
# Scroll to the latest response using JavaScript
|
| 139 |
+
st.write("<script>document.getElementById('response').scrollIntoView();</script>", unsafe_allow_html=True)
|
| 140 |
+
|
| 141 |
+
loading_message.empty()
|
| 142 |
+
|
| 143 |
+
# Clear the input field by setting the query variable to an empty string
|
| 144 |
+
query = ""
|
| 145 |
+
|
| 146 |
+
# Mark all messages as old after displaying
|
| 147 |
+
st.session_state['chat_history'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history']]
|
| 148 |
+
|
| 149 |
+
|
| 150 |
if __name__ == "__main__":
|
| 151 |
main()
|