Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,74 +1,72 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from main import *
|
| 3 |
|
| 4 |
|
| 5 |
if __name__ == "__main__":
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
st.markdown("<h3 style='text-align: center;'>π€ JOB Website AI Assistance</h3>", unsafe_allow_html=True)
|
| 11 |
-
|
| 12 |
-
# Creating Session State Variable
|
| 13 |
-
if 'HuggingFace_API_Key' not in st.session_state:
|
| 14 |
-
st.session_state['HuggingFace_API_Key'] =''
|
| 15 |
-
|
| 16 |
-
#********SIDE BAR*******
|
| 17 |
-
with st.sidebar:
|
| 18 |
-
st.sidebar.title("ποΈ")
|
| 19 |
-
st.session_state['HuggingFace_API_Key']= st.text_input("What's your HuggingFace API key?",type="password")
|
| 20 |
-
load_button = st.button("Load", key="load_button")
|
| 21 |
|
| 22 |
-
|
| 23 |
-
#Proceed only if API keys are provided
|
| 24 |
-
if st.session_state['HuggingFace_API_Key'] !="":
|
| 25 |
-
if os.path.exists('./chroma_db'):
|
| 26 |
-
st.sidebar.success("Data pushed to Chromadb successfully!")
|
| 27 |
-
else:
|
| 28 |
-
#Fetch data from site
|
| 29 |
-
site_data= get_website_data("https://jobs.apple.com/sitemap/sitemap-jobs-en-gb.xml")
|
| 30 |
-
st.toast("Data pull done...", icon='π')
|
| 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 |
-
# Pull index data from Chroma
|
| 56 |
-
relavant_docs = pull_from_chroma(prompt)
|
| 57 |
-
st.toast("Chroma index retrieval done...")
|
| 58 |
-
# st.write(relavant_docs)
|
| 59 |
-
if prompt and relavant_docs:
|
| 60 |
-
if not load_button:
|
| 61 |
-
if st.session_state['HuggingFace_API_Key'] != "":
|
| 62 |
-
# Displaying search results
|
| 63 |
-
st.success("Please find the search results :")
|
| 64 |
-
for index in range(min(document_count, len(relavant_docs))):
|
| 65 |
-
document = relavant_docs[index]
|
| 66 |
-
st.write("π**Result : " + str(index + 1) + "**")
|
| 67 |
-
st.write("**Info**: " + get_summary(relavant_docs[index]))
|
| 68 |
-
# st.write("**Info**: " + document.page_content)
|
| 69 |
-
st.write("**Link**: " + document.metadata['source'])
|
| 70 |
-
st.markdown("-----------------------------------------------------------------------")
|
| 71 |
|
| 72 |
-
|
| 73 |
-
st.sidebar.error("Ooopssss!!! Please provide API key.....")
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
import streamlit as st
|
| 3 |
from main import *
|
| 4 |
|
| 5 |
|
| 6 |
if __name__ == "__main__":
|
| 7 |
+
st.set_page_config(page_title="AI Assistant",
|
| 8 |
+
page_icon='π€',
|
| 9 |
+
layout='centered')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
st.markdown("<h3 style='text-align: center;'>π€ JOB Website AI Assistance</h3>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
# Creating Session State Variable
|
| 14 |
+
if 'HuggingFace_API_Key' not in st.session_state:
|
| 15 |
+
st.session_state['HuggingFace_API_Key'] = ''
|
| 16 |
|
| 17 |
+
# ********SIDE BAR*******
|
| 18 |
+
with st.sidebar:
|
| 19 |
+
st.sidebar.title("ποΈ")
|
| 20 |
+
st.session_state['HuggingFace_API_Key'] = st.text_input("What's your HuggingFace API key?", type="password")
|
| 21 |
+
load_button = st.button("Load", key="load_button")
|
| 22 |
|
| 23 |
+
if load_button:
|
| 24 |
+
# Proceed only if API keys are provided
|
| 25 |
+
if st.session_state['HuggingFace_API_Key'] != "":
|
| 26 |
+
if os.path.exists('./chroma_db'):
|
| 27 |
+
st.sidebar.success("Data pushed to Chromadb successfully!")
|
| 28 |
+
else:
|
| 29 |
+
# Fetch data from site
|
| 30 |
+
site_data = get_website_data("https://jobs.apple.com/sitemap/sitemap-jobs-en-gb.xml")
|
| 31 |
+
st.toast("Data pull done...", icon='π')
|
| 32 |
|
| 33 |
+
# Split data into chunks
|
| 34 |
+
chunks_data = split_data(site_data)
|
| 35 |
+
st.toast("Splitting data done...", icon='π₯')
|
| 36 |
|
| 37 |
+
# Creating embeddings instance
|
| 38 |
+
embeddings = create_embeddings()
|
| 39 |
+
st.toast("Embeddings instance creation done...", icon='π€')
|
| 40 |
|
| 41 |
+
# Push data to Chroma
|
| 42 |
+
db = push_to_chroma(embeddings, chunks_data)
|
| 43 |
+
st.toast("Pushing data to Chromadb done...")
|
| 44 |
+
st.sidebar.success("Data pushed to Chromadb successfully!")
|
| 45 |
+
else:
|
| 46 |
+
st.sidebar.error("Ooopssss!!! Please provide API key.....")
|
| 47 |
|
| 48 |
+
prompt = st.text_input('Enter keyword - e.g Job title', key="prompt") # The box for the text prompt
|
| 49 |
+
document_count = st.slider('No.Of links to return π - (0 LOW || 5 HIGH)', 0, 5, 2, step=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
# submit = st.button("Search")
|
|
|
|
| 52 |
|
| 53 |
+
with st.spinner("Searching..."):
|
| 54 |
+
if st.button("Search"):
|
| 55 |
+
# Pull index data from Chroma
|
| 56 |
+
relavant_docs = pull_from_chroma(prompt)
|
| 57 |
+
st.toast("Chroma index retrieval done...")
|
| 58 |
+
# st.write(relavant_docs)
|
| 59 |
+
if prompt and relavant_docs:
|
| 60 |
+
if not load_button:
|
| 61 |
+
if st.session_state['HuggingFace_API_Key'] != "":
|
| 62 |
+
# Displaying search results
|
| 63 |
+
st.success("Please find the search results :")
|
| 64 |
+
for index in range(min(document_count, len(relavant_docs))):
|
| 65 |
+
document = relavant_docs[index]
|
| 66 |
+
st.write("π**Result : " + str(index + 1) + "**")
|
| 67 |
+
st.write("**Info**: " + get_summary(relavant_docs[index]))
|
| 68 |
+
# st.write("**Info**: " + document.page_content)
|
| 69 |
+
st.write("**Link**: " + document.metadata['source'])
|
| 70 |
+
st.markdown("-----------------------------------------------------------------------")
|
| 71 |
+
else:
|
| 72 |
+
st.sidebar.error("Ooopssss!!! Please provide API key.....")
|