Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(
|
20 |
+
"What's your HuggingFace API key?", type="password")
|
21 |
+
st.session_state['Pinecone_API_Key'] = st.sidebar.text_input(
|
22 |
+
"What's your Pinecone API key?", type="password")
|
23 |
+
|
24 |
+
load_button = st.sidebar.button("Load data to Pinecone", key="load_button")
|
25 |
+
|
26 |
+
# If the bove button is clicked, pushing the data to Pinecone...
|
27 |
+
if load_button:
|
28 |
+
# Proceed only if API keys are provided
|
29 |
+
if st.session_state['HuggingFace_API_Key'] != "" and st.session_state['Pinecone_API_Key'] != "":
|
30 |
+
|
31 |
+
# Fetch data from site
|
32 |
+
site_data = get_website_data(constants.WEBSITE_URL)
|
33 |
+
st.write("Data pull done...")
|
34 |
+
|
35 |
+
# Split data into chunks
|
36 |
+
chunks_data = split_data(site_data)
|
37 |
+
st.write("Spliting data done...")
|
38 |
+
|
39 |
+
# Creating embeddings instance
|
40 |
+
embeddings = create_embeddings()
|
41 |
+
st.write("Embeddings instance creation done...")
|
42 |
+
|
43 |
+
# Push data to Pinecone
|
44 |
+
push_to_pinecone(st.session_state['Pinecone_API_Key'], constants.PINECONE_ENVIRONMENT,
|
45 |
+
constants.PINECONE_INDEX, embeddings, chunks_data)
|
46 |
+
st.write("Pushing data to Pinecone done...")
|
47 |
+
|
48 |
+
st.sidebar.success("Data pushed to Pinecone successfully!")
|
49 |
+
else:
|
50 |
+
st.sidebar.error("Ooopssss!!! Please provide API keys.....")
|
51 |
+
|
52 |
+
# ********SIDE BAR Funtionality ended*******
|
53 |
+
|
54 |
+
# Captures User Inputs
|
55 |
+
prompt = st.text_input('How can I help you my friend β',
|
56 |
+
key="prompt") # The box for the text prompt
|
57 |
+
document_count = st.slider(
|
58 |
+
'No.Of links to return π - (0 LOW || 5 HIGH)', 0, 5, 2, step=1)
|
59 |
+
|
60 |
+
submit = st.button("Search")
|
61 |
+
|
62 |
+
|
63 |
+
if submit:
|
64 |
+
# Proceed only if API keys are provided
|
65 |
+
if st.session_state['HuggingFace_API_Key'] != "" and st.session_state['Pinecone_API_Key'] != "":
|
66 |
+
|
67 |
+
# Creating embeddings instance
|
68 |
+
embeddings = create_embeddings()
|
69 |
+
st.write("Embeddings instance creation done...")
|
70 |
+
|
71 |
+
# Pull index data from Pinecone
|
72 |
+
index = pull_from_pinecone(
|
73 |
+
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 |
+
else:
|
91 |
+
st.sidebar.error("Ooopssss!!! Please provide API keys.....")
|