Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -336,6 +336,9 @@ def clear_user_input():
|
|
336 |
def main():
|
337 |
load_environment()
|
338 |
|
|
|
|
|
|
|
339 |
# Initialize session state safely
|
340 |
if "chat_ready" not in st.session_state:
|
341 |
st.session_state.chat_ready = False
|
@@ -403,7 +406,7 @@ def main():
|
|
403 |
# Show input box for next question
|
404 |
user_question = st.text_input("Ask your next question:", key="user_input", on_change=clear_user_input)
|
405 |
|
406 |
-
if user_question:
|
407 |
with st.spinner("Generating answer..."):
|
408 |
try:
|
409 |
set_global_vectorstore(st.session_state.vectorstore)
|
@@ -411,12 +414,15 @@ def main():
|
|
411 |
except Exception as e:
|
412 |
response = f"⚠️ Something went wrong: {e}"
|
413 |
|
414 |
-
#
|
415 |
st.session_state.chat_history.append({
|
416 |
"user": user_question,
|
417 |
"bot": response
|
418 |
})
|
419 |
|
|
|
|
|
|
|
420 |
st.rerun()
|
421 |
|
422 |
if __name__ == "__main__":
|
|
|
336 |
def main():
|
337 |
load_environment()
|
338 |
|
339 |
+
if "last_answered_question" not in st.session_state:
|
340 |
+
st.session_state.last_answered_question = ""
|
341 |
+
|
342 |
# Initialize session state safely
|
343 |
if "chat_ready" not in st.session_state:
|
344 |
st.session_state.chat_ready = False
|
|
|
406 |
# Show input box for next question
|
407 |
user_question = st.text_input("Ask your next question:", key="user_input", on_change=clear_user_input)
|
408 |
|
409 |
+
if user_question and user_question != st.session_state.last_answered_question:
|
410 |
with st.spinner("Generating answer..."):
|
411 |
try:
|
412 |
set_global_vectorstore(st.session_state.vectorstore)
|
|
|
414 |
except Exception as e:
|
415 |
response = f"⚠️ Something went wrong: {e}"
|
416 |
|
417 |
+
# Store answer
|
418 |
st.session_state.chat_history.append({
|
419 |
"user": user_question,
|
420 |
"bot": response
|
421 |
})
|
422 |
|
423 |
+
# ✅ Mark this question as answered
|
424 |
+
st.session_state.last_answered_question = user_question
|
425 |
+
|
426 |
st.rerun()
|
427 |
|
428 |
if __name__ == "__main__":
|