Spaces:
Build error
Build error
File size: 4,927 Bytes
2cba6eb 7a4623b 2cba6eb f408ab0 7a4623b 2cba6eb 7a4623b 2cba6eb 7a4623b 2cba6eb 7a4623b 2cba6eb 7a4623b 2cba6eb 7a4623b 2cba6eb 7a4623b 2cba6eb 7a4623b 2cba6eb 7a4623b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
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() |