MarsiyaIssah commited on
Commit
c1f5fba
Β·
verified Β·
1 Parent(s): e6f6189

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -59
app.py CHANGED
@@ -1,74 +1,72 @@
 
1
  import streamlit as st
2
  from main import *
3
 
4
 
5
  if __name__ == "__main__":
6
- st.set_page_config(page_title="AI Assistant",
7
- page_icon='πŸ€–',
8
- layout='centered')
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
- if load_button:
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
- #Split data into chunks
33
- chunks_data=split_data(site_data)
34
- st.toast("Spliting data done...", icon='πŸ”₯')
35
 
36
- #Creating embeddings instance
37
- embeddings=create_embeddings()
38
- st.toast("Embeddings instance creation done...",icon='πŸ€–')
 
 
39
 
40
- #Push data to Chroma
41
- db = push_to_chroma(embeddings,chunks_data)
42
- st.toast("Pushing data to Chromadb done...")
43
- st.sidebar.success("Data pushed to Chromadb successfully!")
44
- else:
45
- st.sidebar.error("Ooopssss!!! Please provide API key.....")
 
 
 
46
 
 
 
 
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
 
72
- else:
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.....")