CoolFace
Apppublic

agshiv92/TorontoCanadaChapter_CanPolicyInsight

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes
app.py54 linesDownload Raw Back to root
1import streamlit as st2import os3import sys4from dotenv import load_dotenv5 6from task6_model_deployment.scripts.query_engine import index_connection, initialize_retriever, index_retrieval, load_config7# Load environment variables8load_dotenv()9 10# Add the scripts directory to the system path11script_dir = os.path.dirname(os.path.abspath(__file__))12base_dir = os.path.dirname(script_dir)13print(base_dir)14scripts_dir = os.path.join(base_dir, 'scripts')15logo_path = os.path.join(base_dir,'app', 'task6_model_deployment', 'assets', 'logo.png')16sys.path.append(scripts_dir)17 18# Import functions from the query engine script19 20 21def main():22    # Create a side-by-side layout using columns23    col1, col2 = st.columns([1, 5])  # Adjust the width ratios of the columns as needed24 25    # Display the logo in the first column26    with col1:27        if os.path.exists(logo_path):28            st.image(logo_path, width=80)  # Adjust the width to resize the logo29        else:30            st.error(f"Logo not found at: {logo_path}")31 32    # Display the title in the second column33    with col2:34        st.title("Canada Policy Explorer")35 36    # Initialize Pinecone connection and retrieverC:\Users\agshi\Desktop\Omdena\Canada Policy\TorontoCanadaChapter_CanPolicyInsight\task6_model_deployment\configs37    config_path = os.path.join(base_dir,'app','task6_model_deployment','configs','config.yaml')38    config = load_config(config_path)39    pinecone_index,summary_index = index_connection(config_path)40    retriever,summary_retriever = initialize_retriever(pinecone_index,summary_index)41    st.write("Welcome to the Canada Policy Navigator. Explore policy insights and more.")42    # User input for query43    query_text = st.text_input("Enter your query:", "")44 45    if st.button("Submit"):46        if query_text:47            response = index_retrieval(retriever, summary_retriever, query_text)48            st.write(response.response) 49        else:50            st.warning("Please enter a query.")51 52if __name__ == "__main__":53    main()54