Update app.py
Browse files
app.py
CHANGED
@@ -2,89 +2,70 @@ import streamlit as st
|
|
2 |
from utils import *
|
3 |
import constants
|
4 |
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
if 'HuggingFace_API_Key' not in st.session_state:
|
7 |
st.session_state['HuggingFace_API_Key'] ='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'
|
8 |
if 'Pinecone_API_Key' not in st.session_state:
|
9 |
st.session_state['Pinecone_API_Key'] ='e230380c-daab-4529-8e5a-4fa84e6788d9'
|
10 |
|
|
|
11 |
|
12 |
-
|
13 |
-
st.title('π€ AI Assistance For Website')
|
14 |
-
|
15 |
-
#********SIDE BAR Funtionality started*******
|
16 |
-
|
17 |
-
# Sidebar to capture the API keys
|
18 |
-
st.sidebar.title("πποΈ")
|
19 |
-
#st.session_state['HuggingFace_API_Key']= st.sidebar.text_input("What's your HuggingFace API key?",type="password")
|
20 |
-
#st.session_state['Pinecone_API_Key']= st.sidebar.text_input("What's your Pinecone API key?",type="password")
|
21 |
|
22 |
load_button = st.sidebar.button("Load data to Pinecone", key="load_button")
|
23 |
|
24 |
-
#If the bove button is clicked, pushing the data to Pinecone...
|
25 |
if load_button:
|
26 |
-
#Proceed only if API keys are provided
|
27 |
if st.session_state['HuggingFace_API_Key'] !="" and st.session_state['Pinecone_API_Key']!="" :
|
28 |
|
29 |
-
#Fetch data from site
|
30 |
site_data=get_website_data(constants.WEBSITE_URL)
|
31 |
-
st.write("Data
|
32 |
|
33 |
-
#Split data into chunks
|
34 |
chunks_data=split_data(site_data)
|
35 |
-
st.write("
|
36 |
|
37 |
-
#Creating embeddings instance
|
38 |
embeddings=create_embeddings()
|
39 |
-
st.write("
|
40 |
|
41 |
-
#Push data to Pinecone
|
42 |
push_to_pinecone(st.session_state['Pinecone_API_Key'],constants.PINECONE_ENVIRONMENT,constants.PINECONE_INDEX,embeddings,chunks_data)
|
43 |
-
st.write("
|
44 |
|
45 |
-
st.sidebar.success("Data
|
46 |
else:
|
47 |
-
st.sidebar.error("
|
48 |
-
|
49 |
-
#********SIDE BAR Funtionality ended*******
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
document_count = st.slider('No.Of links to return π - (0 LOW || 5 HIGH)', 0, 5, 2,step=1)
|
54 |
|
55 |
-
submit = st.button("
|
56 |
|
57 |
|
58 |
if submit:
|
59 |
-
#Proceed only if API keys are provided
|
60 |
if st.session_state['HuggingFace_API_Key'] !="" and st.session_state['Pinecone_API_Key']!="" :
|
61 |
|
62 |
-
#Creating embeddings instance
|
63 |
embeddings=create_embeddings()
|
64 |
-
st.write("
|
65 |
|
66 |
-
#Pull index data from Pinecone
|
67 |
index=pull_from_pinecone(st.session_state['Pinecone_API_Key'],constants.PINECONE_ENVIRONMENT,constants.PINECONE_INDEX,embeddings)
|
68 |
-
st.write("
|
69 |
|
70 |
-
#Fetch relavant documents from Pinecone index
|
71 |
relavant_docs=get_similar_docs(index,prompt,document_count)
|
72 |
#st.write(relavant_docs)
|
73 |
|
74 |
-
|
75 |
-
st.
|
76 |
-
#Displaying search results
|
77 |
-
st.write("search results list....")
|
78 |
for document in relavant_docs:
|
|
|
|
|
|
|
79 |
|
80 |
-
st.write("π**Result : "+ str(relavant_docs.index(document)+1)+"**")
|
81 |
-
st.write("**Info**: "+document.page_content)
|
82 |
-
st.write("**Link**: "+ document.metadata['source'])
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
else:
|
87 |
-
st.sidebar.error("
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
2 |
from utils import *
|
3 |
import constants
|
4 |
|
5 |
+
st.set_page_config(initial_sidebar_state="collapsed")
|
6 |
+
hide_streamlit_style = """
|
7 |
+
<style>
|
8 |
+
#MainMenu {visibility: hidden;}
|
9 |
+
.stDeployButton {display:none;}
|
10 |
+
footer {visibility: hidden;}
|
11 |
+
</style>
|
12 |
+
"""
|
13 |
+
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
14 |
+
|
15 |
if 'HuggingFace_API_Key' not in st.session_state:
|
16 |
st.session_state['HuggingFace_API_Key'] ='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'
|
17 |
if 'Pinecone_API_Key' not in st.session_state:
|
18 |
st.session_state['Pinecone_API_Key'] ='e230380c-daab-4529-8e5a-4fa84e6788d9'
|
19 |
|
20 |
+
st.title("π TCE.edu Chat Assistant: Your Friendly Guide to Everything TCE! π")
|
21 |
|
22 |
+
st.sidebar.title("ποΈ")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
load_button = st.sidebar.button("Load data to Pinecone", key="load_button")
|
25 |
|
|
|
26 |
if load_button:
|
|
|
27 |
if st.session_state['HuggingFace_API_Key'] !="" and st.session_state['Pinecone_API_Key']!="" :
|
28 |
|
|
|
29 |
site_data=get_website_data(constants.WEBSITE_URL)
|
30 |
+
st.write("β
Data fetched successfully!")
|
31 |
|
|
|
32 |
chunks_data=split_data(site_data)
|
33 |
+
st.write("βοΈ Data split into manageable parts!")
|
34 |
|
|
|
35 |
embeddings=create_embeddings()
|
36 |
+
st.write("π§ Model ready to understand your queries!")
|
37 |
|
|
|
38 |
push_to_pinecone(st.session_state['Pinecone_API_Key'],constants.PINECONE_ENVIRONMENT,constants.PINECONE_INDEX,embeddings,chunks_data)
|
39 |
+
st.write("π Data loaded into Pinecone for quick searching!")
|
40 |
|
41 |
+
st.sidebar.success("π Data successfully loaded into Pinecone!")
|
42 |
else:
|
43 |
+
st.sidebar.error("β Oops! Please provide your API keys.")
|
|
|
|
|
44 |
|
45 |
+
prompt = st.text_input('How can I help you today β',key="prompt")
|
46 |
+
document_count = st.slider('Number of results to show π - (0 LOW || 5 HIGH)', 0, 5, 2,step=1)
|
|
|
47 |
|
48 |
+
submit = st.button("Ask! π")
|
49 |
|
50 |
|
51 |
if submit:
|
|
|
52 |
if st.session_state['HuggingFace_API_Key'] !="" and st.session_state['Pinecone_API_Key']!="" :
|
53 |
|
|
|
54 |
embeddings=create_embeddings()
|
55 |
+
st.write("π§ Model ready to understand your queries!")
|
56 |
|
|
|
57 |
index=pull_from_pinecone(st.session_state['Pinecone_API_Key'],constants.PINECONE_ENVIRONMENT,constants.PINECONE_INDEX,embeddings)
|
58 |
+
st.write("π Database retrieval is done!")
|
59 |
|
|
|
60 |
relavant_docs=get_similar_docs(index,prompt,document_count)
|
61 |
#st.write(relavant_docs)
|
62 |
|
63 |
+
st.success("π Here are the search results:")
|
64 |
+
st.write("π List of search results:")
|
|
|
|
|
65 |
for document in relavant_docs:
|
66 |
+
st.write("π**Result : "+ str(relavant_docs.index(document)+1) + "**")
|
67 |
+
st.write("**Info:**: "+document.page_content)
|
68 |
+
st.write("π **Link**: "+ document.metadata['source'])
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
else:
|
71 |
+
st.sidebar.error("β Oops! Please provide your API keys.")
|
|
|
|
|
|