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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Byte-compiled / optimized / DLL files
|
| 2 |
+
cacert.pem
|
| 3 |
+
__pycache__/
|
| 4 |
+
*.py[cod]
|
| 5 |
+
*$py.class
|
| 6 |
+
|
| 7 |
+
# C extensions
|
| 8 |
+
*.so
|
| 9 |
+
|
| 10 |
+
# Distribution / packaging
|
| 11 |
+
.Python
|
| 12 |
+
build/
|
| 13 |
+
develop-eggs/
|
| 14 |
+
dist/
|
| 15 |
+
downloads/
|
| 16 |
+
eggs/
|
| 17 |
+
.eggs/
|
| 18 |
+
lib/
|
| 19 |
+
lib64/
|
| 20 |
+
parts/
|
| 21 |
+
sdist/
|
| 22 |
+
var/
|
| 23 |
+
wheels/
|
| 24 |
+
share/python-wheels/
|
| 25 |
+
*.egg-info/
|
| 26 |
+
.installed.cfg
|
| 27 |
+
*.egg
|
| 28 |
+
MANIFEST
|
| 29 |
+
|
| 30 |
+
# PyInstaller
|
| 31 |
+
# Usually these files are written by a python script from a template
|
| 32 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
| 33 |
+
*.manifest
|
| 34 |
+
*.spec
|
| 35 |
+
|
| 36 |
+
# Installer logs
|
| 37 |
+
pip-log.txt
|
| 38 |
+
pip-delete-this-directory.txt
|
| 39 |
+
|
| 40 |
+
# Unit test / coverage reports
|
| 41 |
+
htmlcov/
|
| 42 |
+
.tox/
|
| 43 |
+
.nox/
|
| 44 |
+
.coverage
|
| 45 |
+
.coverage.*
|
| 46 |
+
.cache
|
| 47 |
+
nosetests.xml
|
| 48 |
+
coverage.xml
|
| 49 |
+
*.cover
|
| 50 |
+
*.py,cover
|
| 51 |
+
.hypothesis/
|
| 52 |
+
.pytest_cache/
|
| 53 |
+
cover/
|
| 54 |
+
|
| 55 |
+
# Translations
|
| 56 |
+
*.mo
|
| 57 |
+
*.pot
|
| 58 |
+
|
| 59 |
+
# Django stuff:
|
| 60 |
+
*.log
|
| 61 |
+
local_settings.py
|
| 62 |
+
db.sqlite3
|
| 63 |
+
db.sqlite3-journal
|
| 64 |
+
|
| 65 |
+
# Flask stuff:
|
| 66 |
+
instance/
|
| 67 |
+
.webassets-cache
|
| 68 |
+
|
| 69 |
+
# Scrapy stuff:
|
| 70 |
+
.scrapy
|
| 71 |
+
|
| 72 |
+
# Sphinx documentation
|
| 73 |
+
docs/_build/
|
| 74 |
+
|
| 75 |
+
# PyBuilder
|
| 76 |
+
.pybuilder/
|
| 77 |
+
target/
|
| 78 |
+
|
| 79 |
+
# Jupyter Notebook
|
| 80 |
+
.ipynb_checkpoints
|
| 81 |
+
|
| 82 |
+
# IPython
|
| 83 |
+
profile_default/
|
| 84 |
+
ipython_config.py
|
| 85 |
+
|
| 86 |
+
# pyenv
|
| 87 |
+
# For a library or package, you might want to ignore these files since the code is
|
| 88 |
+
# intended to run in multiple environments; otherwise, check them in:
|
| 89 |
+
# .python-version
|
| 90 |
+
|
| 91 |
+
# pipenv
|
| 92 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 93 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 94 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 95 |
+
# install all needed dependencies.
|
| 96 |
+
#Pipfile.lock
|
| 97 |
+
|
| 98 |
+
# poetry
|
| 99 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
| 100 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 101 |
+
# commonly ignored for libraries.
|
| 102 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
| 103 |
+
#poetry.lock
|
| 104 |
+
|
| 105 |
+
# pdm
|
| 106 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
| 107 |
+
#pdm.lock
|
| 108 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
| 109 |
+
# in version control.
|
| 110 |
+
# https://pdm.fming.dev/#use-with-ide
|
| 111 |
+
.pdm.toml
|
| 112 |
+
|
| 113 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
| 114 |
+
__pypackages__/
|
| 115 |
+
|
| 116 |
+
# Celery stuff
|
| 117 |
+
celerybeat-schedule
|
| 118 |
+
celerybeat.pid
|
| 119 |
+
|
| 120 |
+
# SageMath parsed files
|
| 121 |
+
*.sage.py
|
| 122 |
+
|
| 123 |
+
# Environments
|
| 124 |
+
.env
|
| 125 |
+
.venv
|
| 126 |
+
env/
|
| 127 |
+
venv/
|
| 128 |
+
ENV/
|
| 129 |
+
env.bak/
|
| 130 |
+
venv.bak/
|
| 131 |
+
|
| 132 |
+
# Spyder project settings
|
| 133 |
+
.spyderproject
|
| 134 |
+
.spyproject
|
| 135 |
+
|
| 136 |
+
# Rope project settings
|
| 137 |
+
.ropeproject
|
| 138 |
+
|
| 139 |
+
# mkdocs documentation
|
| 140 |
+
/site
|
| 141 |
+
|
| 142 |
+
# mypy
|
| 143 |
+
.mypy_cache/
|
| 144 |
+
.dmypy.json
|
| 145 |
+
dmypy.json
|
| 146 |
+
|
| 147 |
+
# Pyre type checker
|
| 148 |
+
.pyre/
|
| 149 |
+
|
| 150 |
+
# pytype static type analyzer
|
| 151 |
+
.pytype/
|
| 152 |
+
|
| 153 |
+
# Cython debug symbols
|
| 154 |
+
cython_debug/
|
| 155 |
+
|
| 156 |
+
# PyCharm
|
| 157 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
| 158 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
| 159 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 160 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 161 |
+
#.idea/
|
LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2024 Marsiya Issah
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
Pipfile
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[[source]]
|
| 2 |
+
url = "https://pypi.org/simple"
|
| 3 |
+
verify_ssl = true
|
| 4 |
+
name = "pypi"
|
| 5 |
+
|
| 6 |
+
[packages]
|
| 7 |
+
openai = "*"
|
| 8 |
+
langchain = "*"
|
| 9 |
+
streamlit = "*"
|
| 10 |
+
python-dotenv = "*"
|
| 11 |
+
langchain-community = "*"
|
| 12 |
+
langchain-openai = "*"
|
| 13 |
+
sentence-transformers = "*"
|
| 14 |
+
chromadb = "*"
|
| 15 |
+
nest-asyncio = "*"
|
| 16 |
+
|
| 17 |
+
[dev-packages]
|
| 18 |
+
|
| 19 |
+
[requires]
|
| 20 |
+
python_version = "3.10"
|
Pipfile.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
__init__.py
ADDED
|
File without changes
|
app.png
ADDED
|
main.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import asyncio
|
| 3 |
+
from langchain.document_loaders.sitemap import SitemapLoader
|
| 4 |
+
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 5 |
+
from langchain.embeddings.sentence_transformer import SentenceTransformerEmbeddings
|
| 6 |
+
from langchain_community.vectorstores import Chroma
|
| 7 |
+
import streamlit as st
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
os.environ.get("HUGGINGFACEHUB_API_TOKEN")
|
| 11 |
+
|
| 12 |
+
#Function to fetch data from website
|
| 13 |
+
#https://python.langchain.com/docs/modules/data_connection/document_loaders/integrations/sitemap
|
| 14 |
+
def get_website_data(sitemap_url):
|
| 15 |
+
loop = asyncio.new_event_loop()
|
| 16 |
+
asyncio.set_event_loop(loop)
|
| 17 |
+
loader = SitemapLoader(sitemap_url)
|
| 18 |
+
loader.requests_kwargs = {'verify': './cacert.pem'}
|
| 19 |
+
docs = loader.load()
|
| 20 |
+
# print(docs)
|
| 21 |
+
return docs
|
| 22 |
+
|
| 23 |
+
#Function to split data into smaller chunks
|
| 24 |
+
def split_data(docs):
|
| 25 |
+
text_splitter = RecursiveCharacterTextSplitter(
|
| 26 |
+
chunk_size = 1000,
|
| 27 |
+
chunk_overlap = 200,
|
| 28 |
+
length_function = len,
|
| 29 |
+
)
|
| 30 |
+
docs_chunks = text_splitter.split_documents(docs)
|
| 31 |
+
# print(docs_chunks)
|
| 32 |
+
return docs_chunks
|
| 33 |
+
|
| 34 |
+
#Function to create embeddings instance
|
| 35 |
+
def create_embeddings():
|
| 36 |
+
embeddings = SentenceTransformerEmbeddings(model_name="all-MiniLM-L6-v2")
|
| 37 |
+
return embeddings
|
| 38 |
+
|
| 39 |
+
# Function to push data to Chroma
|
| 40 |
+
def push_to_chroma(embeddings, chunk_data):
|
| 41 |
+
Chroma.from_documents(chunk_data, embeddings, persist_directory="./chroma_db")
|
| 42 |
+
|
| 43 |
+
# Function to pull data from chroma
|
| 44 |
+
def pull_from_chroma(query):
|
| 45 |
+
db = Chroma(persist_directory="./chroma_db", embedding_function= create_embeddings())
|
| 46 |
+
docs = db.similarity_search(query)
|
| 47 |
+
return docs
|
| 48 |
+
|
| 49 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
openai
|
| 2 |
+
langchain
|
| 3 |
+
streamlit
|
| 4 |
+
langchain-experimental
|
| 5 |
+
langchain-community
|
| 6 |
+
sentence-transformers
|
| 7 |
+
chromadb
|
streamlit.py
ADDED
|
@@ -0,0 +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:
|
| 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**: " + document.page_content)
|
| 68 |
+
st.write("**Link**: " + document.metadata['source'])
|
| 69 |
+
st.markdown("-----------------------------------------------------------------------")
|
| 70 |
+
else:
|
| 71 |
+
st.sidebar.error("Ooopssss!!! Please provide API key.....")
|
| 72 |
+
|