AlanOC commited on
Commit
7b41153
1 Parent(s): 545c7de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -35
app.py CHANGED
@@ -657,50 +657,50 @@ def main():
657
 
658
  ############# Container for chat messages ##############
659
  with st.container():
660
- # Display chat history
661
- for i, (question, answer) in enumerate(st.session_state.chat_history):
662
- answer_id = f"answer-{i}"
663
 
664
- # Custom HTML for the question with user avatar aligned to the right
665
- st.markdown(f"""
666
- <div style="display: flex; justify-content: flex-end; align-items: flex-start; margin-bottom: 20px;">
667
- <span style="margin-right: 10px;">{question}</span>
668
- <img src='data:image/png;base64,{st.session_state.user_selected_avatar}' style='width: 50px; height: 50px;'>
669
- </div>
670
- """, unsafe_allow_html=True)
671
-
672
- # Display the response (only if it's not empty)
673
- if response:
674
  st.markdown(f"""
675
- <div id="{answer_id}" style="display: flex; align-items: flex-start; margin-bottom: 20px;">
676
- <img src='data:image/png;base64,{ci_icon}' style='width: 50px; height: 50px; margin-right: 10px;'>
677
- <span>{response}</span>
678
  </div>
679
  """, unsafe_allow_html=True)
680
 
681
- # Display metadata for unique source documents
682
- if source_documents:
683
- unique_sources = []
684
- seen_urls = set()
685
-
686
- for doc in source_documents:
687
- url = doc.metadata.get('url', 'N/A')
688
- if url not in seen_urls:
689
- unique_sources.append(doc)
690
- seen_urls.add(url)
691
-
692
- if unique_sources:
693
  st.markdown(f"""
694
- <div style="display: flex; align-items: flex-start; margin-bottom: 20px;">
695
  <img src='data:image/png;base64,{ci_icon}' style='width: 50px; height: 50px; margin-right: 10px;'>
696
- <div>
697
- <b>Further Reading:</b><br>
698
  """, unsafe_allow_html=True)
699
 
700
- for doc in unique_sources:
701
- st.markdown(f"- [{doc.metadata.get('title', 'No title available')}]({doc.metadata.get('url', '#')})")
702
-
703
- st.markdown("</div></div>", unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
704
 
705
  # JavaScript to scroll to the latest answer
706
  if st.session_state.chat_history:
 
657
 
658
  ############# Container for chat messages ##############
659
  with st.container():
660
+ # Display chat history
661
+ for i, (question, answer) in enumerate(st.session_state.chat_history):
662
+ answer_id = f"answer-{i}"
663
 
664
+ # Custom HTML for the question with user avatar aligned to the right
 
 
 
 
 
 
 
 
 
665
  st.markdown(f"""
666
+ <div style="display: flex; justify-content: flex-end; align-items: flex-start; margin-bottom: 20px;">
667
+ <span style="margin-right: 10px;">{question}</span>
668
+ <img src='data:image/png;base64,{st.session_state.user_selected_avatar}' style='width: 50px; height: 50px;'>
669
  </div>
670
  """, unsafe_allow_html=True)
671
 
672
+ # Display the response (only if it's not empty)
673
+ if response:
 
 
 
 
 
 
 
 
 
 
674
  st.markdown(f"""
675
+ <div id="{answer_id}" style="display: flex; align-items: flex-start; margin-bottom: 20px;">
676
  <img src='data:image/png;base64,{ci_icon}' style='width: 50px; height: 50px; margin-right: 10px;'>
677
+ <span>{response}</span>
678
+ </div>
679
  """, unsafe_allow_html=True)
680
 
681
+ # Display metadata for unique source documents
682
+ if source_documents:
683
+ unique_sources = []
684
+ seen_urls = set()
685
+
686
+ for doc in source_documents:
687
+ url = doc.metadata.get('url', 'N/A')
688
+ if url not in seen_urls:
689
+ unique_sources.append(doc)
690
+ seen_urls.add(url)
691
+
692
+ if unique_sources:
693
+ st.markdown(f"""
694
+ <div style="display: flex; align-items: flex-start; margin-bottom: 20px;">
695
+ <img src='data:image/png;base64,{ci_icon}' style='width: 50px; height: 50px; margin-right: 10px;'>
696
+ <div>
697
+ <b>Further Reading:</b><br>
698
+ """, unsafe_allow_html=True)
699
+
700
+ for doc in unique_sources:
701
+ st.markdown(f"- [{doc.metadata.get('title', 'No title available')}]({doc.metadata.get('url', '#')})")
702
+
703
+ st.markdown("</div></div>", unsafe_allow_html=True)
704
 
705
  # JavaScript to scroll to the latest answer
706
  if st.session_state.chat_history: