Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -333,9 +333,15 @@ def save_feedback_to_huggingface():
|
|
333 |
def clear_user_input():
|
334 |
st.session_state["user_input"] = ""
|
335 |
|
|
|
|
|
|
|
|
|
|
|
336 |
def main():
|
337 |
load_environment()
|
338 |
|
|
|
339 |
if "chat_ready" not in st.session_state:
|
340 |
st.session_state.chat_ready = False
|
341 |
if "chat_history" not in st.session_state:
|
@@ -351,6 +357,39 @@ def main():
|
|
351 |
|
352 |
st.header("Chat with MODTRAN Documents π")
|
353 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
354 |
if not st.session_state.chat_ready:
|
355 |
with st.spinner("Loading MODTRAN document..."):
|
356 |
preload_modtran_document()
|
@@ -360,14 +399,14 @@ def main():
|
|
360 |
|
361 |
# Display entire chat history
|
362 |
for i, exchange in enumerate(st.session_state.chat_history):
|
363 |
-
st.markdown(f"
|
364 |
-
st.markdown(f"
|
365 |
|
366 |
if "rating" in exchange:
|
367 |
-
st.markdown(f"
|
368 |
|
369 |
elif i == len(st.session_state.chat_history) - 1:
|
370 |
-
# Show
|
371 |
with st.form(key=f"feedback_form_{i}"):
|
372 |
rating = st.radio(
|
373 |
"Rate this response:",
|
@@ -395,13 +434,12 @@ def main():
|
|
395 |
st.session_state.feedback_submitted = True
|
396 |
st.rerun()
|
397 |
|
398 |
-
#
|
399 |
-
st.markdown(f"
|
400 |
|
401 |
-
#
|
402 |
user_question = st.text_input("Ask your next question:", key="user_input")
|
403 |
|
404 |
-
# Only handle if user typed something new
|
405 |
if user_question and user_question != st.session_state.last_answered_question:
|
406 |
with st.spinner("Generating answer..."):
|
407 |
try:
|
@@ -410,18 +448,18 @@ def main():
|
|
410 |
except Exception as e:
|
411 |
response = f"β οΈ Something went wrong: {e}"
|
412 |
|
413 |
-
#
|
414 |
st.session_state.chat_history.append({
|
415 |
"user": user_question,
|
416 |
"bot": response
|
417 |
})
|
418 |
|
419 |
-
# Save the last answered question
|
420 |
st.session_state.last_answered_question = user_question
|
421 |
-
|
422 |
st.rerun()
|
423 |
|
424 |
|
|
|
425 |
if __name__ == "__main__":
|
426 |
load_environment()
|
427 |
main()
|
|
|
333 |
def clear_user_input():
|
334 |
st.session_state["user_input"] = ""
|
335 |
|
336 |
+
from datetime import datetime
|
337 |
+
|
338 |
+
def clear_user_input():
|
339 |
+
st.session_state.user_input = ""
|
340 |
+
|
341 |
def main():
|
342 |
load_environment()
|
343 |
|
344 |
+
# Initialize session state
|
345 |
if "chat_ready" not in st.session_state:
|
346 |
st.session_state.chat_ready = False
|
347 |
if "chat_history" not in st.session_state:
|
|
|
357 |
|
358 |
st.header("Chat with MODTRAN Documents π")
|
359 |
|
360 |
+
# Add custom CSS for chat bubbles
|
361 |
+
st.markdown("""
|
362 |
+
<style>
|
363 |
+
.user-bubble {
|
364 |
+
background-color: #f0f0f0;
|
365 |
+
padding: 1rem;
|
366 |
+
margin: 0.5rem 0;
|
367 |
+
border-radius: 1rem;
|
368 |
+
color: #333;
|
369 |
+
}
|
370 |
+
.bot-bubble {
|
371 |
+
background-color: #e8f4fd;
|
372 |
+
padding: 1rem;
|
373 |
+
margin: 0.5rem 0;
|
374 |
+
border-radius: 1rem;
|
375 |
+
color: #111;
|
376 |
+
}
|
377 |
+
.rating-line {
|
378 |
+
color: #ffaa00;
|
379 |
+
font-weight: bold;
|
380 |
+
margin-top: -0.5rem;
|
381 |
+
margin-bottom: 1rem;
|
382 |
+
}
|
383 |
+
.feedback-counter {
|
384 |
+
color: #444;
|
385 |
+
font-size: 0.9rem;
|
386 |
+
margin-top: 1rem;
|
387 |
+
font-style: italic;
|
388 |
+
}
|
389 |
+
</style>
|
390 |
+
""", unsafe_allow_html=True)
|
391 |
+
|
392 |
+
# Preload documents and agent
|
393 |
if not st.session_state.chat_ready:
|
394 |
with st.spinner("Loading MODTRAN document..."):
|
395 |
preload_modtran_document()
|
|
|
399 |
|
400 |
# Display entire chat history
|
401 |
for i, exchange in enumerate(st.session_state.chat_history):
|
402 |
+
st.markdown(f'<div class="user-bubble"><strong>You:</strong> {exchange["user"]}</div>', unsafe_allow_html=True)
|
403 |
+
st.markdown(f'<div class="bot-bubble"><strong>MODTRAN Bot:</strong> {exchange["bot"]}</div>', unsafe_allow_html=True)
|
404 |
|
405 |
if "rating" in exchange:
|
406 |
+
st.markdown(f'<div class="rating-line">βοΈ You rated this: {exchange["rating"]}/5</div>', unsafe_allow_html=True)
|
407 |
|
408 |
elif i == len(st.session_state.chat_history) - 1:
|
409 |
+
# Show feedback form for most recent response
|
410 |
with st.form(key=f"feedback_form_{i}"):
|
411 |
rating = st.radio(
|
412 |
"Rate this response:",
|
|
|
434 |
st.session_state.feedback_submitted = True
|
435 |
st.rerun()
|
436 |
|
437 |
+
# Show feedback counter
|
438 |
+
#st.markdown(f'<div class="feedback-counter">π Feedbacks collected: <strong>{len(st.session_state.feedback_log)} / 5</strong></div>', unsafe_allow_html=True)
|
439 |
|
440 |
+
# Ask next question
|
441 |
user_question = st.text_input("Ask your next question:", key="user_input")
|
442 |
|
|
|
443 |
if user_question and user_question != st.session_state.last_answered_question:
|
444 |
with st.spinner("Generating answer..."):
|
445 |
try:
|
|
|
448 |
except Exception as e:
|
449 |
response = f"β οΈ Something went wrong: {e}"
|
450 |
|
451 |
+
# Save chat
|
452 |
st.session_state.chat_history.append({
|
453 |
"user": user_question,
|
454 |
"bot": response
|
455 |
})
|
456 |
|
|
|
457 |
st.session_state.last_answered_question = user_question
|
458 |
+
st.session_state.user_input = ""
|
459 |
st.rerun()
|
460 |
|
461 |
|
462 |
+
|
463 |
if __name__ == "__main__":
|
464 |
load_environment()
|
465 |
main()
|