Update app.py
Browse files
app.py
CHANGED
|
@@ -1,51 +1,49 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import easyocr
|
| 3 |
-
from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
| 4 |
-
import os
|
| 5 |
-
from dotenv import load_dotenv
|
| 6 |
-
from sklearn.metrics.pairwise import cosine_similarity
|
| 7 |
-
import numpy as np
|
| 8 |
-
import cv2
|
| 9 |
-
import PyPDF2
|
| 10 |
-
|
| 11 |
-
load_dotenv()
|
| 12 |
-
|
| 13 |
-
st.title('Resume Shortlist Applications')
|
| 14 |
-
|
| 15 |
-
file_input_resume = st.file_uploader('Enter your resume file', type=['png', 'jpg', 'jpeg', 'pdf'])
|
| 16 |
-
text_file_input_resume = st.file_uploader('Enter your job descriptions', type=['txt'])
|
| 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 |
-
similarity = calculate_similarity(vector_resume_text, vector_job_description)
|
| 51 |
-
st.write(f'The similarity between your resume and job descriptions is {similarity:.2f}%')
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import easyocr
|
| 3 |
+
from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
| 4 |
+
import os
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
| 7 |
+
import numpy as np
|
| 8 |
+
import cv2
|
| 9 |
+
import PyPDF2
|
| 10 |
+
|
| 11 |
+
load_dotenv()
|
| 12 |
+
|
| 13 |
+
st.title('Resume Shortlist Applications')
|
| 14 |
+
|
| 15 |
+
file_input_resume = st.file_uploader('Enter your resume file', type=['png', 'jpg', 'jpeg', 'pdf'])
|
| 16 |
+
text_file_input_resume = st.file_uploader('Enter your job descriptions', type=['txt'])
|
| 17 |
+
def extract_text_easyocr(image_bytes):
|
| 18 |
+
nparr = np.frombuffer(image_bytes, np.uint8)
|
| 19 |
+
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
|
| 20 |
+
reader = easyocr.Reader(['en'])
|
| 21 |
+
result = reader.readtext(img, detail=0)
|
| 22 |
+
return "\n".join(result)
|
| 23 |
+
|
| 24 |
+
def text_loader(file):
|
| 25 |
+
return file.read().decode('utf-8')
|
| 26 |
+
|
| 27 |
+
GOOGLE_API_KEY = os.environ.get('GOOGLE_API_KEY')
|
| 28 |
+
os.environ['GOOGLE_API_KEY'] = GOOGLE_API_KEY
|
| 29 |
+
embeddings = GoogleGenerativeAIEmbeddings(model='models/embedding-001')
|
| 30 |
+
|
| 31 |
+
def calculate_similarity(vector1, vector2):
|
| 32 |
+
return (cosine_similarity([vector1], [vector2])[0][0] * 100)
|
| 33 |
+
|
| 34 |
+
if st.button('Check your Score'):
|
| 35 |
+
text_job_descriptions = text_loader(text_file_input_resume)
|
| 36 |
+
if file_input_resume and text_file_input_resume:
|
| 37 |
+
if file_input_resume.type in ['image/png', 'image/jpeg', 'image/jpg']:
|
| 38 |
+
image_bytes = file_input_resume.read()
|
| 39 |
+
text = extract_text_easyocr(image_bytes)
|
| 40 |
+
elif file_input_resume.type == 'application/pdf':
|
| 41 |
+
pdf_reader = PyPDF2.PdfReader(file_input_resume)
|
| 42 |
+
text = "\n".join([page.extract_text() for page in pdf_reader.pages if page.extract_text()])
|
| 43 |
+
else:
|
| 44 |
+
st.error("Unsupported file format for resume.")
|
| 45 |
+
st.stop()
|
| 46 |
+
vector_resume_text = embeddings.embed_query(text)
|
| 47 |
+
vector_job_description = embeddings.embed_query(text_job_descriptions)
|
| 48 |
+
similarity = calculate_similarity(vector_resume_text, vector_job_description)
|
| 49 |
+
st.write(f'The similarity between your resume and job descriptions is {similarity:.2f}%')
|
|
|
|
|
|