import streamlit as st from streamlit_option_menu import option_menu from markup import app_intro import langchain from query_data import chat_chain from memory import msgs def tab1(): st.header("CIMA Chatbot") col1, col2 = st.columns([1, 2]) with col1: st.image("image.jpg", use_column_width=True) with col2: st.markdown(app_intro(), unsafe_allow_html=True) metadata_list = [] unique_metadata_list = [] seen = set() def tab4(): st.header("🗣️ Chat with the AI about the ingested documents! 📚") for i, msg in enumerate(msgs.messages): name = "user" if i % 2 == 0 else "assistant" st.chat_message(name).markdown(msg.content) if user_input := st.chat_input("User Input"): with st.chat_message("user"): st.markdown(user_input) with st.spinner("Generating Response..."): with st.chat_message("assistant"): response = chat_chain({"question": user_input}) answer = response['answer'] source_documents = response['source_documents'] for doc in source_documents: if hasattr(doc, 'metadata'): metadata = doc.metadata metadata_list.append(metadata) for metadata in metadata_list: metadata_tuple = tuple(metadata.items()) if metadata_tuple not in seen: unique_metadata_list.append(metadata) seen.add(metadata_tuple) st.write(answer) st.write(unique_metadata_list) if st.sidebar.button("Clear Chat History"): msgs.clear() def main(): st.set_page_config(page_title="CIMA Chat", page_icon=":memo:", layout="wide") tabs = ["Intro", "Chat"] with st.sidebar: current_tab = option_menu("Select a Tab", tabs, menu_icon="cast") tab_functions = { "Intro": tab1, "Chat": tab4, } if current_tab in tab_functions: tab_functions[current_tab]() if __name__ == "__main__": main()