| import streamlit as st
|
| from database import main as populate_db
|
| from query import query_rag
|
| from langchain.schema.document import Document
|
|
|
|
|
|
|
| st.set_page_config(page_title='Content Engine')
|
|
|
|
|
| def load_and_populate_database():
|
| st.header("Database Population")
|
| st.write("Use this section to populate the database.")
|
| if st.button("Populate Database"):
|
| populate_db()
|
|
|
| st.markdown("<hr style='border: 1px dashed #e0e0e0;'>", unsafe_allow_html=True)
|
|
|
|
|
|
|
| def display_chat_box():
|
| st.header("Chat Box")
|
| st.write("Enter your questions below and get responses generated from the context.")
|
|
|
|
|
| if 'messages' not in st.session_state:
|
| st.session_state.messages = []
|
|
|
|
|
| with st.container():
|
| for message in st.session_state.messages:
|
| st.chat_message(message['role']).markdown(message['content'])
|
|
|
|
|
| user_query = st.chat_input("Your Query:", key="query_input")
|
|
|
| if user_query:
|
|
|
| st.chat_message('user').markdown(user_query)
|
|
|
|
|
| st.session_state.messages.append({'role': 'user', 'content': user_query})
|
|
|
|
|
| with st.spinner('Waiting for response...'):
|
|
|
| response_text = query_rag(user_query)
|
|
|
|
|
| st.chat_message('assistant').markdown(response_text)
|
|
|
|
|
| st.session_state.messages.append({'role': 'assistant', 'content': response_text})
|
|
|
|
|
| def main():
|
|
|
| st.markdown("<h1 style='font-size: 60px; text-align: center;'>🧠Content Engine🤖</h1>", unsafe_allow_html=True)
|
|
|
|
|
| st.markdown("<hr style='border: 1px dashed #e0e0e0;'>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
| display_chat_box()
|
|
|
|
|
|
|
| if __name__ == "__main__":
|
| main()
|
|
|