Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -335,10 +335,11 @@ def main():
|
|
335 |
st.session_state.chat_history = []
|
336 |
if "vectorstore" not in st.session_state:
|
337 |
st.session_state.vectorstore = None
|
|
|
|
|
338 |
|
339 |
st.header("Chat with MODTRAN Documents 📄")
|
340 |
|
341 |
-
# Preload the document once when app starts
|
342 |
if not st.session_state.chat_ready:
|
343 |
with st.spinner("Loading MODTRAN document..."):
|
344 |
preload_modtran_document()
|
@@ -348,7 +349,7 @@ def main():
|
|
348 |
|
349 |
user_question = st.text_input("Ask your question:", key="user_input")
|
350 |
|
351 |
-
if st.session_state.chat_ready and user_question:
|
352 |
with st.spinner("Generating answer..."):
|
353 |
try:
|
354 |
set_global_vectorstore(st.session_state.vectorstore)
|
@@ -356,14 +357,11 @@ def main():
|
|
356 |
except Exception as e:
|
357 |
response = f"⚠️ Something went wrong: {e}"
|
358 |
|
359 |
-
# ✅ Show the response
|
360 |
st.markdown("### Answer:")
|
361 |
st.write(response)
|
362 |
|
363 |
-
# Update chat history
|
364 |
st.session_state.chat_history.append({"user": user_question, "bot": response})
|
365 |
|
366 |
-
# After bot responds, ask for feedback
|
367 |
with st.form(key=f"feedback_form_{len(st.session_state.chat_history)}"):
|
368 |
rating = st.radio(
|
369 |
"Rate this response:",
|
@@ -381,12 +379,17 @@ def main():
|
|
381 |
}
|
382 |
st.session_state.feedback_log.append(feedback)
|
383 |
|
384 |
-
# If 5 feedbacks collected, auto upload to Hugging Face
|
385 |
if len(st.session_state.feedback_log) >= 5:
|
386 |
save_feedback_to_huggingface()
|
387 |
|
388 |
-
|
389 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
390 |
|
391 |
|
392 |
if __name__ == "__main__":
|
|
|
335 |
st.session_state.chat_history = []
|
336 |
if "vectorstore" not in st.session_state:
|
337 |
st.session_state.vectorstore = None
|
338 |
+
if "feedback_submitted" not in st.session_state:
|
339 |
+
st.session_state.feedback_submitted = False
|
340 |
|
341 |
st.header("Chat with MODTRAN Documents 📄")
|
342 |
|
|
|
343 |
if not st.session_state.chat_ready:
|
344 |
with st.spinner("Loading MODTRAN document..."):
|
345 |
preload_modtran_document()
|
|
|
349 |
|
350 |
user_question = st.text_input("Ask your question:", key="user_input")
|
351 |
|
352 |
+
if st.session_state.chat_ready and user_question and not st.session_state.feedback_submitted:
|
353 |
with st.spinner("Generating answer..."):
|
354 |
try:
|
355 |
set_global_vectorstore(st.session_state.vectorstore)
|
|
|
357 |
except Exception as e:
|
358 |
response = f"⚠️ Something went wrong: {e}"
|
359 |
|
|
|
360 |
st.markdown("### Answer:")
|
361 |
st.write(response)
|
362 |
|
|
|
363 |
st.session_state.chat_history.append({"user": user_question, "bot": response})
|
364 |
|
|
|
365 |
with st.form(key=f"feedback_form_{len(st.session_state.chat_history)}"):
|
366 |
rating = st.radio(
|
367 |
"Rate this response:",
|
|
|
379 |
}
|
380 |
st.session_state.feedback_log.append(feedback)
|
381 |
|
|
|
382 |
if len(st.session_state.feedback_log) >= 5:
|
383 |
save_feedback_to_huggingface()
|
384 |
|
385 |
+
# Mark feedback as submitted to prevent rerun loop
|
386 |
+
st.session_state.feedback_submitted = True
|
387 |
+
st.rerun()
|
388 |
+
|
389 |
+
# Reset feedback flag if no question is asked (new session)
|
390 |
+
if not user_question:
|
391 |
+
st.session_state.feedback_submitted = False
|
392 |
+
|
393 |
|
394 |
|
395 |
if __name__ == "__main__":
|