ZarinT commited on
Commit
ba70895
Β·
verified Β·
1 Parent(s): b361b34

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -21
app.py CHANGED
@@ -335,6 +335,11 @@ def clear_user_input():
335
 
336
  from datetime import datetime
337
 
 
 
 
 
 
338
  def clear_user_input():
339
  st.session_state.user_input = ""
340
 
@@ -357,39 +362,47 @@ def main():
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()
@@ -397,16 +410,19 @@ def main():
397
  st.session_state.chat_ready = True
398
  st.success("MODTRAN User Manual loaded successfully!")
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,10 +450,12 @@ def main():
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:
@@ -448,7 +466,6 @@ def main():
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
@@ -457,8 +474,6 @@ def main():
457
  st.session_state.last_answered_question = user_question
458
  st.rerun()
459
 
460
-
461
-
462
  if __name__ == "__main__":
463
  load_environment()
464
  main()
 
335
 
336
  from datetime import datetime
337
 
338
+ def clear_user_input():
339
+ st.session_state.user_input = ""
340
+
341
+ from datetime import datetime
342
+
343
  def clear_user_input():
344
  st.session_state.user_input = ""
345
 
 
362
 
363
  st.header("Chat with MODTRAN Documents πŸ“„")
364
 
365
+ # Inject CSS for chat-style alignment
366
  st.markdown("""
367
  <style>
368
+ .chat-container {
369
+ display: flex;
370
+ flex-direction: column;
371
+ gap: 0.5rem;
372
+ }
373
  .user-bubble {
374
+ align-self: flex-end;
375
+ background-color: rgba(30, 30, 30, 0.85);
376
+ color: white;
377
  padding: 1rem;
378
+ border-radius: 1rem 0.5rem 1rem 1rem;
379
+ max-width: 80%;
 
380
  }
381
  .bot-bubble {
382
+ align-self: flex-start;
383
  background-color: #e8f4fd;
 
 
 
384
  color: #111;
385
+ padding: 1rem;
386
+ border-radius: 0.5rem 1rem 1rem 1rem;
387
+ max-width: 80%;
388
  }
389
  .rating-line {
 
390
  font-weight: bold;
391
+ color: #ffaa00;
392
  margin-top: -0.5rem;
393
  margin-bottom: 1rem;
394
+ font-size: 0.95rem;
395
  }
396
  .feedback-counter {
 
 
 
397
  font-style: italic;
398
+ color: #666;
399
+ font-size: 0.9rem;
400
+ margin: 1rem 0;
401
  }
402
  </style>
403
  """, unsafe_allow_html=True)
404
 
405
+ # Load chatbot agent and vectorstore if not ready
406
  if not st.session_state.chat_ready:
407
  with st.spinner("Loading MODTRAN document..."):
408
  preload_modtran_document()
 
410
  st.session_state.chat_ready = True
411
  st.success("MODTRAN User Manual loaded successfully!")
412
 
413
+ # 🟦 Chat History Output
414
+ st.markdown('<div class="chat-container">', unsafe_allow_html=True)
415
+
416
  for i, exchange in enumerate(st.session_state.chat_history):
417
  st.markdown(f'<div class="user-bubble"><strong>You:</strong> {exchange["user"]}</div>', unsafe_allow_html=True)
418
  st.markdown(f'<div class="bot-bubble"><strong>MODTRAN Bot:</strong> {exchange["bot"]}</div>', unsafe_allow_html=True)
419
 
420
+ # Show rating if available
421
  if "rating" in exchange:
422
  st.markdown(f'<div class="rating-line">⭐️ You rated this: {exchange["rating"]}/5</div>', unsafe_allow_html=True)
423
 
424
+ # Show form for last unanswered item
425
  elif i == len(st.session_state.chat_history) - 1:
 
426
  with st.form(key=f"feedback_form_{i}"):
427
  rating = st.radio(
428
  "Rate this response:",
 
450
  st.session_state.feedback_submitted = True
451
  st.rerun()
452
 
453
+ st.markdown('</div>', unsafe_allow_html=True)
454
+
455
+ # Feedback status
456
+ st.markdown(f'<div class="feedback-counter">πŸ“„ Feedbacks collected: <strong>{len(st.session_state.feedback_log)} / 5</strong></div>', unsafe_allow_html=True)
457
+
458
 
 
459
  user_question = st.text_input("Ask your next question:", key="user_input")
460
 
461
  if user_question and user_question != st.session_state.last_answered_question:
 
466
  except Exception as e:
467
  response = f"⚠️ Something went wrong: {e}"
468
 
 
469
  st.session_state.chat_history.append({
470
  "user": user_question,
471
  "bot": response
 
474
  st.session_state.last_answered_question = user_question
475
  st.rerun()
476
 
 
 
477
  if __name__ == "__main__":
478
  load_environment()
479
  main()