Spaces:
Sleeping
Sleeping
import streamlit as st | |
import utils.utils as ut | |
import utils.constants as constants | |
if 'huggingface_api_key' not in st.session_state: | |
st.session_state['huggingface_api_key'] = '' | |
if 'PINECONE_API_KEY' not in st.session_state: | |
st.session_state['PINECONE_API_KEY'] = '' | |
st.title('π€ AI Assistance For Website') | |
st.sidebar.title("πποΈ") | |
st.session_state['huggingface_api_key']= st.sidebar.text_input("What's your HuggingFace API key?",type="password") | |
st.session_state['PINECONE_API_KEY']= st.sidebar.text_input("What's your Pinecone API key?",type="password") | |
load_button = st.sidebar.button("Load data to Pinecone", key="load_button") | |
if load_button: | |
if st.session_state['huggingface_api_key'] and st.session_state['PINECONE_API_KEY']: | |
site_data=ut.get_website_data(constants.URL) | |
st.sidebar.write("Data pull done...") | |
#Split data into chunks | |
chunks_data=ut.split_data(site_data) | |
st.sidebar.write("Spliting data done...") | |
#Creating embeddings instance | |
embeddings=ut.create_embeddings() | |
st.sidebar.write("Embeddings instance creation done...") | |
#Push data to Pinecone | |
ut.push_to_pinecone(st.session_state['PINECONE_API_KEY'],constants.PINECONE_INDEX,embeddings,chunks_data) | |
st.sidebar.write("Pushing data to Pinecone done...") | |
st.success("Successfully pushed embeddings to Pinecone!") | |
else: | |
st.sidebar.error("Please provide API keys...") | |
prompt = st.text_input('How can I help you my friend β',key="prompt") # The box for the text prompt | |
document_count = st.slider('No.Of links to return π - (0 LOW || 5 HIGH)', 0, 5, 2,step=1) | |
submit = st.button("Search") | |
if submit: | |
#Proceed only if API keys are provided | |
if st.session_state['huggingface_api_key'] !="" and st.session_state['PINECONE_API_KEY']!="" : | |
#Creating embeddings instance | |
embeddings=ut.create_embeddings() | |
st.write("Embeddings instance creation done...") | |
#Pull index data from Pinecone | |
index= ut.pull_from_pinecone(st.session_state['PINECONE_API_KEY'],constants.PINECONE_INDEX,embeddings) | |
st.write("Pinecone index retrieval done...") | |
#Fetch relavant documents from Pinecone index | |
relavant_docs=ut.get_similar_docs(index,prompt,document_count) | |
#Displaying search results | |
st.success("Please find the search results :") | |
#Displaying search results | |
st.write("search results list....") | |
for document in relavant_docs: | |
st.write("π**Result : "+ str(relavant_docs.index(document)+1)+"**") | |
st.write("**Info**: "+document.page_content) | |
st.write("**Link**: "+ document.metadata['source']) |