Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -262,77 +262,29 @@ def page1():
|
|
| 262 |
query = "Was bedeutet die Vorhaltefinanzierung?"
|
| 263 |
|
| 264 |
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
# Aktualisiere die Chat-Historie nach der Antwort des Bots
|
| 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}")
|
| 303 |
-
# [Rest des Codes bleibt unverändert]
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
#if query:
|
| 309 |
-
#full_query = ask_bot(query)
|
| 310 |
-
#st.session_state['chat_history_page1'].append(("User", query, "new"))
|
| 311 |
-
|
| 312 |
-
# Start timing
|
| 313 |
-
#start_time = time.time()
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
#with st.spinner('Bot is thinking...'):
|
| 317 |
-
#chain = load_chatbot()
|
| 318 |
-
#docs = VectorStore.similarity_search(query=query, k=5)
|
| 319 |
-
#with get_openai_callback() as cb:
|
| 320 |
-
#response = chain.run(input_documents=docs, question=full_query)
|
| 321 |
-
#response = handle_no_answer(response) # Process the response through the new function
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
# Stop timing
|
| 326 |
-
#end_time = time.time()
|
| 327 |
-
|
| 328 |
-
# Calculate duration
|
| 329 |
-
#duration = end_time - start_time
|
| 330 |
-
|
| 331 |
-
# You can use Streamlit's text function to display the timing
|
| 332 |
-
#st.text(f"Response time: {duration:.2f} seconds")
|
| 333 |
-
|
| 334 |
-
#st.session_state['chat_history_page1'].append(("Bot", response, "new"))
|
| 335 |
|
|
|
|
|
|
|
|
|
|
| 336 |
|
| 337 |
# Display new messages at the bottom
|
| 338 |
new_messages = st.session_state['chat_history_page1'][-2:]
|
|
@@ -340,16 +292,17 @@ def page1():
|
|
| 340 |
background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
|
| 341 |
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)
|
| 342 |
|
| 343 |
-
|
| 344 |
# Clear the input field after the query is made
|
| 345 |
query = ""
|
| 346 |
-
|
| 347 |
# Mark all messages as old after displaying
|
| 348 |
st.session_state['chat_history_page1'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history_page1']]
|
| 349 |
|
| 350 |
except Exception as e:
|
| 351 |
st.error(f"Upsi, an unexpected error occurred: {e}")
|
| 352 |
-
#
|
|
|
|
|
|
|
| 353 |
|
| 354 |
|
| 355 |
|
|
|
|
| 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 "
|
| 270 |
+
"(aber nicht mehr als 1 Satz mehr). Wenn der User sehr vage schreibt, "
|
| 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 |
+
# Aktualisiere die Chat-Historie nach der Antwort des Bots
|
| 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:]
|
|
|
|
| 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}")
|
| 303 |
+
# [Rest des Codes bleibt unverändert]
|
| 304 |
+
|
| 305 |
+
|
| 306 |
|
| 307 |
|
| 308 |
|