Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -261,9 +261,7 @@ def page1():
|
|
| 261 |
if st.button("Was bedeutet die Vorhaltefinanzierung?"):
|
| 262 |
query = "Was bedeutet die Vorhaltefinanzierung?"
|
| 263 |
|
| 264 |
-
|
| 265 |
if query:
|
| 266 |
-
# Generiere das 'full_query' direkt ohne separate Funktion
|
| 267 |
standard_prompt = ("Schreibe immer höflich und auf antworte immer in der Sprache, "
|
| 268 |
"in der der User auch schreibt. Formuliere immer ganze freundliche "
|
| 269 |
"ganze Sätze und biete, wenn möglich, auch mehr Informationen "
|
|
@@ -271,32 +269,32 @@ def page1():
|
|
| 271 |
"frage nach - gerade wenn es um Jahre geht, frage nur nach Jahren, "
|
| 272 |
"wenn du zu dem Thema auch Daten zu bestimmten Jahren hast.")
|
| 273 |
full_query = standard_prompt + " " + query
|
| 274 |
-
|
| 275 |
-
# Kombiniere die gesamte Session-Historie mit der aktuellen Anfrage
|
| 276 |
combined_query = combine_history_with_query(full_query, st.session_state['chat_history_page1'])
|
| 277 |
-
|
| 278 |
with st.spinner('Bot is thinking...'):
|
| 279 |
chain = load_chatbot()
|
| 280 |
docs = VectorStore.similarity_search(query=combined_query, k=5)
|
| 281 |
with get_openai_callback() as cb:
|
| 282 |
response = chain.run(input_documents=docs, question=combined_query)
|
| 283 |
response = handle_no_answer(response)
|
| 284 |
-
|
| 285 |
-
#
|
| 286 |
st.session_state['chat_history_page1'].append(("User", query))
|
| 287 |
st.session_state['chat_history_page1'].append(("Bot", response))
|
| 288 |
-
|
| 289 |
# Display new messages at the bottom
|
| 290 |
new_messages = st.session_state['chat_history_page1'][-2:]
|
| 291 |
for chat in new_messages:
|
| 292 |
background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
|
| 293 |
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)
|
| 294 |
-
|
| 295 |
# Clear the input field after the query is made
|
| 296 |
query = ""
|
| 297 |
-
|
| 298 |
# Mark all messages as old after displaying
|
| 299 |
st.session_state['chat_history_page1'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history_page1']]
|
|
|
|
| 300 |
|
| 301 |
except Exception as e:
|
| 302 |
st.error(f"Upsi, an unexpected error occurred: {e}")
|
|
|
|
| 261 |
if st.button("Was bedeutet die Vorhaltefinanzierung?"):
|
| 262 |
query = "Was bedeutet die Vorhaltefinanzierung?"
|
| 263 |
|
|
|
|
| 264 |
if query:
|
|
|
|
| 265 |
standard_prompt = ("Schreibe immer höflich und auf antworte immer in der Sprache, "
|
| 266 |
"in der der User auch schreibt. Formuliere immer ganze freundliche "
|
| 267 |
"ganze Sätze und biete, wenn möglich, auch mehr Informationen "
|
|
|
|
| 269 |
"frage nach - gerade wenn es um Jahre geht, frage nur nach Jahren, "
|
| 270 |
"wenn du zu dem Thema auch Daten zu bestimmten Jahren hast.")
|
| 271 |
full_query = standard_prompt + " " + query
|
| 272 |
+
|
|
|
|
| 273 |
combined_query = combine_history_with_query(full_query, st.session_state['chat_history_page1'])
|
| 274 |
+
|
| 275 |
with st.spinner('Bot is thinking...'):
|
| 276 |
chain = load_chatbot()
|
| 277 |
docs = VectorStore.similarity_search(query=combined_query, k=5)
|
| 278 |
with get_openai_callback() as cb:
|
| 279 |
response = chain.run(input_documents=docs, question=combined_query)
|
| 280 |
response = handle_no_answer(response)
|
| 281 |
+
|
| 282 |
+
# Update chat history after the bot's response
|
| 283 |
st.session_state['chat_history_page1'].append(("User", query))
|
| 284 |
st.session_state['chat_history_page1'].append(("Bot", response))
|
| 285 |
+
|
| 286 |
# Display new messages at the bottom
|
| 287 |
new_messages = st.session_state['chat_history_page1'][-2:]
|
| 288 |
for chat in new_messages:
|
| 289 |
background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
|
| 290 |
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)
|
| 291 |
+
|
| 292 |
# Clear the input field after the query is made
|
| 293 |
query = ""
|
| 294 |
+
|
| 295 |
# Mark all messages as old after displaying
|
| 296 |
st.session_state['chat_history_page1'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history_page1']]
|
| 297 |
+
|
| 298 |
|
| 299 |
except Exception as e:
|
| 300 |
st.error(f"Upsi, an unexpected error occurred: {e}")
|