Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -162,10 +162,9 @@ def main():
|
|
162 |
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
163 |
is_cloud_button_pressed = st.text_input("Cloud Button Pressed", value="", type="hidden")
|
164 |
|
165 |
-
|
166 |
# Main content
|
167 |
st.title("Welcome to BinDocs ChatBot! 🤖")
|
168 |
-
|
169 |
# Directly specifying the path to the PDF file
|
170 |
pdf_path = pdf_file_path
|
171 |
if not os.path.exists(pdf_path):
|
@@ -186,53 +185,44 @@ def main():
|
|
186 |
if pdf_path is not None:
|
187 |
query = st.text_input("Ask questions about your PDF file (in any preferred language):")
|
188 |
|
189 |
-
# Replace st.button() with the cloud-shaped button using markdown
|
190 |
st.markdown("""
|
191 |
<button class="cloud-button" onclick="document.querySelector('input[type=\"hidden\"]').value = 'Was genau ist ein Belegarzt?';">
|
192 |
<span>Was genau ist ein Belegarzt?</span>
|
193 |
</button>
|
194 |
""", unsafe_allow_html=True)
|
195 |
-
if st.button("Wofür wird die Alpha-ID verwendet?"):
|
196 |
-
query = "Wofür wird die Alpha-ID verwendet?"
|
197 |
|
|
|
|
|
198 |
|
199 |
-
|
200 |
-
|
201 |
-
if is_cloud_button_pressed:
|
202 |
query = is_cloud_button_pressed
|
203 |
-
loading_message = st.empty()
|
204 |
-
loading_message.text('Bot is thinking...')
|
205 |
-
|
206 |
-
# Use the chatbot and PDF data from the session state
|
207 |
-
docs = st.session_state.pdf_data.similarity_search(query=query, k=3)
|
208 |
-
with get_openai_callback() as cb:
|
209 |
-
response = st.session_state.chatbot_instance.run(input_documents=docs, question=query)
|
210 |
|
|
|
|
|
|
|
|
|
|
|
211 |
|
212 |
-
|
213 |
-
chain = load_chatbot()
|
214 |
-
docs = VectorStore.similarity_search(query=query, k=3)
|
215 |
-
with get_openai_callback() as cb:
|
216 |
-
response = chain.run(input_documents=docs, question=query)
|
217 |
|
218 |
-
|
|
|
|
|
|
|
|
|
219 |
|
220 |
-
|
221 |
-
|
222 |
-
for chat in new_messages:
|
223 |
-
background_color = "#FFA07A" if chat[2] == "new" else "#acf" if chat[0] == "User" else "#caf"
|
224 |
-
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)
|
225 |
|
226 |
-
|
227 |
-
st.write("<script>document.getElementById('response').scrollIntoView();</script>", unsafe_allow_html=True)
|
228 |
|
229 |
-
|
|
|
230 |
|
231 |
-
|
232 |
-
|
233 |
|
234 |
-
# Mark all messages as old after displaying
|
235 |
-
st.session_state['chat_history'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history']]
|
236 |
|
237 |
|
238 |
|
|
|
162 |
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
163 |
is_cloud_button_pressed = st.text_input("Cloud Button Pressed", value="", type="hidden")
|
164 |
|
|
|
165 |
# Main content
|
166 |
st.title("Welcome to BinDocs ChatBot! 🤖")
|
167 |
+
|
168 |
# Directly specifying the path to the PDF file
|
169 |
pdf_path = pdf_file_path
|
170 |
if not os.path.exists(pdf_path):
|
|
|
185 |
if pdf_path is not None:
|
186 |
query = st.text_input("Ask questions about your PDF file (in any preferred language):")
|
187 |
|
|
|
188 |
st.markdown("""
|
189 |
<button class="cloud-button" onclick="document.querySelector('input[type=\"hidden\"]').value = 'Was genau ist ein Belegarzt?';">
|
190 |
<span>Was genau ist ein Belegarzt?</span>
|
191 |
</button>
|
192 |
""", unsafe_allow_html=True)
|
|
|
|
|
193 |
|
194 |
+
if st.button("Wofür wird die Alpha-ID verwendet?"):
|
195 |
+
query = "Wofür wird die Alpha-ID verwendet?"
|
196 |
|
197 |
+
if st.button("Ask") or is_cloud_button_pressed or (not st.session_state['chat_history'] and query) or (st.session_state['chat_history'] and query != st.session_state['chat_history'][-1][1]):
|
198 |
+
if is_cloud_button_pressed:
|
|
|
199 |
query = is_cloud_button_pressed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
|
201 |
+
loading_message = st.empty()
|
202 |
+
loading_message.text('Bot is thinking...')
|
203 |
+
docs = st.session_state.pdf_data.similarity_search(query=query, k=3)
|
204 |
+
with get_openai_callback() as cb:
|
205 |
+
response = st.session_state.chatbot_instance.run(input_documents=docs, question=query)
|
206 |
|
207 |
+
st.session_state['chat_history'].append(("Bot", response, "new"))
|
|
|
|
|
|
|
|
|
208 |
|
209 |
+
# Display new messages at the bottom
|
210 |
+
new_messages = st.session_state['chat_history'][-2:]
|
211 |
+
for chat in new_messages:
|
212 |
+
background_color = "#FFA07A" if chat[2] == "new" else "#acf" if chat[0] == "User" else "#caf"
|
213 |
+
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)
|
214 |
|
215 |
+
# Scroll to the latest response using JavaScript
|
216 |
+
st.write("<script>document.getElementById('response').scrollIntoView();</script>", unsafe_allow_html=True)
|
|
|
|
|
|
|
217 |
|
218 |
+
loading_message.empty()
|
|
|
219 |
|
220 |
+
# Clear the input field by setting the query variable to an empty string
|
221 |
+
query = ""
|
222 |
|
223 |
+
# Mark all messages as old after displaying
|
224 |
+
st.session_state['chat_history'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history']]
|
225 |
|
|
|
|
|
226 |
|
227 |
|
228 |
|