Spaces:
Sleeping
Sleeping
File size: 3,353 Bytes
fc655de c1f5fba fc655de c1f5fba fc655de c1f5fba fc655de c1f5fba fc655de c1f5fba fc655de c1f5fba fc655de c1f5fba fc655de c1f5fba fc655de 10fd244 c1f5fba e6f6189 c1f5fba fc655de c1f5fba f3eb21e c1f5fba | 1 2 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | import streamlit as st
from main import *
if __name__ == "__main__":
st.set_page_config(page_title="AI Assistant",
page_icon='π€',
layout='centered')
st.markdown("<h3 style='text-align: center;'>π€ JOB Website AI Assistance</h3>", unsafe_allow_html=True)
# Creating Session State Variable
if 'HuggingFace_API_Key' not in st.session_state:
st.session_state['HuggingFace_API_Key'] = ''
# ********SIDE BAR*******
with st.sidebar:
st.sidebar.title("ποΈ")
st.session_state['HuggingFace_API_Key'] = st.text_input("What's your HuggingFace API key?", type="password")
load_button = st.button("Load", key="load_button")
if load_button:
# Proceed only if API keys are provided
if st.session_state['HuggingFace_API_Key'] != "":
if os.path.exists('./chroma_db'):
st.sidebar.success("Data pushed to Chromadb successfully!")
else:
# Fetch data from site
site_data = get_website_data("https://jobs.apple.com/sitemap/sitemap-jobs-en-gb.xml")
st.toast("Data pull done...", icon='π')
# Split data into chunks
chunks_data = split_data(site_data)
st.toast("Splitting data done...", icon='π₯')
# Creating embeddings instance
embeddings = create_embeddings()
st.toast("Embeddings instance creation done...", icon='π€')
# Push data to Chroma
db = push_to_chroma(embeddings, chunks_data)
st.toast("Pushing data to Chromadb done...")
st.sidebar.success("Data pushed to Chromadb successfully!")
else:
st.sidebar.error("Ooopssss!!! Please provide API key.....")
prompt = st.text_input('Enter keyword - e.g Job title', key="prompt", placeholder='Senior Software Engineer') # 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")
with st.spinner("Searching..."):
if st.button("Search"):
# Pull index data from Chroma
relavant_docs = pull_from_chroma(prompt)
#st.toast("Chroma index retrieval done...")
# st.write(relavant_docs)
if prompt and relavant_docs:
if not load_button:
if st.session_state['HuggingFace_API_Key'] != "":
# Displaying search results
st.success("Please find the search results :")
for index in range(min(document_count, len(relavant_docs))):
document = relavant_docs[index]
st.write("π**Result : " + str(index + 1) + "**")
st.write("**Info**: " + get_summary(relavant_docs[index]))
# st.write("**Info**: " + document.page_content)
st.write("**Link**: " + document.metadata['source'])
st.markdown("-----------------------------------------------------------------------")
else:
st.sidebar.error("Ooopssss!!! Please provide API key.....")
|