moved app.py to the root folder
Browse files
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
import sys
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
|
6 |
+
from TorontoCanadaChapter_CanPolicyInsight.task6_model_deployment.scripts.query_engine import index_connection, initialize_retriever, index_retrieval, load_config
|
7 |
+
# Load environment variables
|
8 |
+
load_dotenv()
|
9 |
+
|
10 |
+
# Add the scripts directory to the system path
|
11 |
+
script_dir = os.path.dirname(os.path.abspath(__file__))
|
12 |
+
base_dir = os.path.dirname(script_dir)
|
13 |
+
scripts_dir = os.path.join(base_dir, 'scripts')
|
14 |
+
logo_path = os.path.join(base_dir, 'Canada Policy', 'TorontoCanadaChapter_CanPolicyInsight', 'task6_model_deployment', 'assets', 'logo.png')
|
15 |
+
sys.path.append(scripts_dir)
|
16 |
+
|
17 |
+
# Import functions from the query engine script
|
18 |
+
|
19 |
+
|
20 |
+
def main():
|
21 |
+
# Create a side-by-side layout using columns
|
22 |
+
col1, col2 = st.columns([1, 5]) # Adjust the width ratios of the columns as needed
|
23 |
+
|
24 |
+
# Display the logo in the first column
|
25 |
+
with col1:
|
26 |
+
if os.path.exists(logo_path):
|
27 |
+
st.image(logo_path, width=80) # Adjust the width to resize the logo
|
28 |
+
else:
|
29 |
+
st.error(f"Logo not found at: {logo_path}")
|
30 |
+
|
31 |
+
# Display the title in the second column
|
32 |
+
with col2:
|
33 |
+
st.title("Canada Policy Explorer")
|
34 |
+
|
35 |
+
# Initialize Pinecone connection and retrieverC:\Users\agshi\Desktop\Omdena\Canada Policy\TorontoCanadaChapter_CanPolicyInsight\task6_model_deployment\configs
|
36 |
+
config_path = os.path.join(base_dir, 'Canada Policy','TorontoCanadaChapter_CanPolicyInsight','task6_model_deployment','configs','config.yaml')
|
37 |
+
config = load_config(config_path)
|
38 |
+
pinecone_index = index_connection(config_path)
|
39 |
+
retriever = initialize_retriever(pinecone_index)
|
40 |
+
st.write("Welcome to the Canada Policy Navigator. Explore policy insights and more.")
|
41 |
+
# User input for query
|
42 |
+
query_text = st.text_input("Enter your query:", "")
|
43 |
+
|
44 |
+
if st.button("Submit"):
|
45 |
+
if query_text:
|
46 |
+
response = index_retrieval(retriever, query_text)
|
47 |
+
st.write(response.response)
|
48 |
+
else:
|
49 |
+
st.warning("Please enter a query.")
|
50 |
+
|
51 |
+
if __name__ == "__main__":
|
52 |
+
main()
|