Update app.py
Browse files
app.py
CHANGED
@@ -1,47 +1,93 @@
|
|
1 |
import streamlit as st
|
2 |
-
from
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
else:
|
47 |
-
st.error("Please
|
|
|
1 |
import streamlit as st
|
2 |
+
from utils import *
|
3 |
+
import constants
|
4 |
+
|
5 |
+
# Creating Session State Variable
|
6 |
+
if 'HuggingFace_API_Key' not in st.session_state:
|
7 |
+
st.session_state['HuggingFace_API_Key'] =''
|
8 |
+
if 'Pinecone_API_Key' not in st.session_state:
|
9 |
+
st.session_state['Pinecone_API_Key'] =''
|
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 |
+
#Recent changes by langchain team, expects ""PINECONE_API_KEY" environment variable for Pinecone usage! So we are creating it here
|
23 |
+
import os
|
24 |
+
os.environ["PINECONE_API_KEY"] = st.session_state['Pinecone_API_Key']
|
25 |
+
|
26 |
+
|
27 |
+
load_button = st.sidebar.button("Load data to Pinecone", key="load_button")
|
28 |
+
|
29 |
+
#If the bove button is clicked, pushing the data to Pinecone...
|
30 |
+
if load_button:
|
31 |
+
#Proceed only if API keys are provided
|
32 |
+
if st.session_state['HuggingFace_API_Key'] !="" and st.session_state['Pinecone_API_Key']!="" :
|
33 |
+
|
34 |
+
#Fetch data from site
|
35 |
+
site_data=get_website_data(constants.WEBSITE_URL)
|
36 |
+
st.write("Data pull done...")
|
37 |
+
|
38 |
+
#Split data into chunks
|
39 |
+
chunks_data=split_data(site_data)
|
40 |
+
st.write("Spliting data done...")
|
41 |
+
|
42 |
+
#Creating embeddings instance
|
43 |
+
embeddings=create_embeddings()
|
44 |
+
st.write("Embeddings instance creation done...")
|
45 |
+
|
46 |
+
#Push data to Pinecone
|
47 |
+
|
48 |
+
push_to_pinecone(st.session_state['Pinecone_API_Key'],constants.PINECONE_ENVIRONMENT,constants.PINECONE_INDEX,embeddings,chunks_data)
|
49 |
+
st.write("Pushing data to Pinecone done...")
|
50 |
+
|
51 |
+
st.sidebar.success("Data pushed to Pinecone successfully!")
|
52 |
+
else:
|
53 |
+
st.sidebar.error("Ooopssss!!! Please provide API keys.....")
|
54 |
+
|
55 |
+
#********SIDE BAR Funtionality ended*******
|
56 |
+
|
57 |
+
#Captures User Inputs
|
58 |
+
prompt = st.text_input('How can I help you my friend β',key="prompt") # The box for the text prompt
|
59 |
+
document_count = st.slider('No.Of links to return π - (0 LOW || 5 HIGH)', 0, 5, 2,step=1)
|
60 |
+
|
61 |
+
submit = st.button("Search")
|
62 |
+
|
63 |
+
|
64 |
+
if submit:
|
65 |
+
#Proceed only if API keys are provided
|
66 |
+
if st.session_state['HuggingFace_API_Key'] !="" and st.session_state['Pinecone_API_Key']!="" :
|
67 |
+
|
68 |
+
#Creating embeddings instance
|
69 |
+
embeddings=create_embeddings()
|
70 |
+
st.write("Embeddings instance creation done...")
|
71 |
+
|
72 |
+
#Pull index data from Pinecone
|
73 |
+
index=pull_from_pinecone(st.session_state['Pinecone_API_Key'],constants.PINECONE_ENVIRONMENT,constants.PINECONE_INDEX,embeddings)
|
74 |
+
st.write("Pinecone index retrieval done...")
|
75 |
+
|
76 |
+
#Fetch relavant documents from Pinecone index
|
77 |
+
relavant_docs=get_similar_docs(index,prompt,document_count)
|
78 |
+
st.write(relavant_docs)
|
79 |
+
|
80 |
+
#Displaying search results
|
81 |
+
st.success("Please find the search results :")
|
82 |
+
#Displaying search results
|
83 |
+
st.write("search results list....")
|
84 |
+
for document in relavant_docs:
|
85 |
+
|
86 |
+
st.write("π**Result : "+ str(relavant_docs.index(document)+1)+"**")
|
87 |
+
st.write("**Info**: "+document.page_content)
|
88 |
+
st.write("**Link**: "+ document.metadata['source'])
|
89 |
+
|
90 |
+
|
91 |
+
|
92 |
else:
|
93 |
+
st.sidebar.error("Ooopssss!!! Please provide API keys.....")
|