resume_scorer / app.py
catastropiyush's picture
Update app.py
7a4623b verified
import os
import fitz # PyMuPDF
import re
import pandas as pd
import streamlit as st
from smolagents import CodeAgent, HfApiModel, DuckDuckGoSearchTool
from io import BytesIO
# Disable SSL verification warning
import urllib3
urllib3.disable_warnings()
# Configure page
st.set_page_config(
page_title="Resume Scorer",
page_icon="πŸ“„",
layout="wide"
)
# Initialize the model and agent - moved outside of cache
try:
model = HfApiModel()
agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)
except Exception as e:
st.error(f"Error initializing agent: {e}")
agent = None
def extract_text_from_uploaded_pdf(pdf_file):
"""Extracts text from an uploaded PDF file."""
try:
pdf_bytes = pdf_file.read()
doc = fitz.open(stream=pdf_bytes, filetype="pdf")
text = ""
for page in doc:
text += page.get_text()
return text
except Exception as e:
st.error(f"Error extracting text from PDF: {e}")
return None
def score_resume_against_job_description(resume_text, job_description):
"""Scores a resume against a job description using smolagents."""
if agent is None:
st.error("Agent not initialized properly")
return None
prompt = f"""
You are a professional recruiter that is highly skilled in scoring resumes.
You will receive a resume and a job description.
You will score the resume based on how well it matches the job description.
Job Description:
{job_description}
Resume:
{resume_text}
Provide a score out of 100. Only provide the numerical score.
"""
try:
response = agent.run(prompt)
# Ensure we get a numeric response
score = int(''.join(filter(str.isdigit, str(response))))
return min(max(score, 0), 100) # Ensure score is between 0 and 100
except Exception as e:
st.error(f"An error has occurred: {e}")
return None
def extract_links_from_text(text):
"""Extracts links from text using regular expressions."""
links = re.findall(r'(https?://\S+)', text)
return links
def main():
st.title("πŸ“„ Resume Scorer")
st.write("Upload a resume and enter a job description to get a matching score!")
if agent is None:
st.error("Failed to initialize the scoring system. Please try again later.")
return
# Create two columns
col1, col2 = st.columns(2)
with col1:
st.subheader("Upload Resume")
uploaded_file = st.file_uploader("Upload Resume (PDF)", type="pdf")
with col2:
st.subheader("Job Description")
job_description = st.text_area(
"Enter Job Description",
height=200,
placeholder="Paste the job description here..."
)
if uploaded_file and job_description:
if st.button("Score Resume"):
with st.spinner("Analyzing resume..."):
resume_text = extract_text_from_uploaded_pdf(uploaded_file)
if resume_text:
links = extract_links_from_text(resume_text)
score = score_resume_against_job_description(resume_text, job_description)
st.divider()
st.subheader("Results")
if score is not None:
score_col, links_col = st.columns(2)
with score_col:
st.metric("Resume Match Score", f"{score}/100")
if score >= 80:
st.success("Strong match! 🌟")
elif score >= 60:
st.info("Good match! πŸ‘")
else:
st.warning("Consider revising the resume")
with links_col:
if links:
st.subheader("Links found in Resume:")
for link in links:
st.write(f"- {link}")
else:
st.info("No links found in the resume")
else:
st.error("Error calculating score")
else:
st.error("Could not extract text from the PDF")
with st.sidebar:
st.header("How to Use")
st.write("""
1. Upload a PDF resume
2. Paste the job description
3. Click 'Score Resume'
""")
st.divider()
st.markdown("""
### About
This tool uses AI to analyze resumes and provide
matching scores against job descriptions.
""")
if __name__ == "__main__":
main()