Spaces:
Sleeping
Sleeping
File size: 3,425 Bytes
91249b5 | 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 | import streamlit as st
import zipfile
import os
import tempfile
import pandas as pd
from PyPDF2 import PdfReader
from sentence_transformers import SentenceTransformer, util
from fpdf import FPDF
from io import BytesIO
# Load the embedding model once
@st.cache_resource
def load_model():
return SentenceTransformer('all-MiniLM-L6-v2')
model = load_model()
st.title("π€ AI Resume Checker & Assistant")
# Input: Job Description
job_description = st.text_area("π Paste Job Description here", height=250)
# Input: ZIP file upload
uploaded_zip = st.file_uploader("π Upload ZIP of Resumes (PDF format only)", type="zip")
if uploaded_zip and job_description:
with tempfile.TemporaryDirectory() as tmpdir:
# Extract zip contents
with zipfile.ZipFile(uploaded_zip, 'r') as zip_ref:
zip_ref.extractall(tmpdir)
results = []
# Embed job description
job_embedding = model.encode(job_description, convert_to_tensor=True)
for file_name in os.listdir(tmpdir):
if file_name.lower().endswith(".pdf"):
pdf_path = os.path.join(tmpdir, file_name)
try:
# Extract text from PDF
reader = PdfReader(pdf_path)
text = " ".join(page.extract_text() or "" for page in reader.pages)
# Embed resume text
resume_embedding = model.encode(text, convert_to_tensor=True)
# Compute cosine similarity score (0-100)
score = util.cos_sim(resume_embedding, job_embedding).item() * 100
results.append({
"Resume": file_name,
"Match Score (%)": round(score, 2),
"Extracted Text": text
})
except Exception as e:
results.append({
"Resume": file_name,
"Match Score (%)": 0,
"Extracted Text": f"Error reading file: {e}"
})
# Create DataFrame and sort by score descending
df = pd.DataFrame(results).sort_values(by="Match Score (%)", ascending=False)
st.subheader("π Resume Match Results")
st.dataframe(df[["Resume", "Match Score (%)"]])
# CSV download button
csv = df.to_csv(index=False).encode('utf-8')
st.download_button(
label="π₯ Download CSV Report",
data=csv,
file_name="resume_match_report.csv",
mime="text/csv"
)
# Generate PDF report
pdf = FPDF()
pdf.set_auto_page_break(auto=True, margin=15)
pdf.add_page()
pdf.set_font("Arial", 'B', 16)
pdf.cell(0, 10, "Resume Match Report", ln=True, align='C')
pdf.ln(10)
pdf.set_font("Arial", size=12)
for idx, row in df.iterrows():
pdf.cell(0, 10, f"{row['Resume']} - Score: {row['Match Score (%)']}%", ln=True)
pdf_bytes = BytesIO()
pdf.output(pdf_bytes)
pdf_bytes.seek(0)
st.download_button(
label="π₯ Download PDF Summary",
data=pdf_bytes,
file_name="resume_match_summary.pdf",
mime="application/pdf"
)
else:
st.info("Please provide a job description and upload a ZIP file of PDF resumes.")
|