Spaces:
Sleeping
Sleeping
Download src/streamlit_app.py from saikumar27/Resume: direct link, hf CLI and curl.
- Browser
- Download file 3.43 kB
-
https://huggingface.co/spaces/saikumar27/Resume/resolve/main/src/streamlit_app.py
- Command line
-
hf download hf://spaces/saikumar27/Resume/src/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/saikumar27/Resume/resolve/main/src/streamlit_app.py
3.43 kB
| 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 | |
| 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.") | |