Spaces:
Build error
Build error
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,277 +0,0 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import pdfplumber
|
| 3 |
-
import re
|
| 4 |
-
import spacy
|
| 5 |
-
from keybert import KeyBERT
|
| 6 |
-
from sentence_transformers import SentenceTransformer, util
|
| 7 |
-
import io
|
| 8 |
-
import pandas as pd
|
| 9 |
-
|
| 10 |
-
# -----------------------------------------------------------------------------
|
| 11 |
-
# App Configuration
|
| 12 |
-
# -----------------------------------------------------------------------------
|
| 13 |
-
st.set_page_config(
|
| 14 |
-
page_title="AI Resume Matcher",
|
| 15 |
-
page_icon="📄",
|
| 16 |
-
layout="wide",
|
| 17 |
-
initial_sidebar_state="expanded",
|
| 18 |
-
)
|
| 19 |
-
|
| 20 |
-
# -----------------------------------------------------------------------------
|
| 21 |
-
# Model Loading (with caching)
|
| 22 |
-
# -----------------------------------------------------------------------------
|
| 23 |
-
# Using st.cache_resource to load models only once
|
| 24 |
-
@st.cache_resource
|
| 25 |
-
def load_models():
|
| 26 |
-
"""Loads the SentenceTransformer, spaCy, and KeyBERT models."""
|
| 27 |
-
model = SentenceTransformer("all-MiniLM-L6-v2")
|
| 28 |
-
nlp = spacy.load("en_core_web_sm")
|
| 29 |
-
kw_model = KeyBERT(model=model)
|
| 30 |
-
return model, nlp, kw_model
|
| 31 |
-
|
| 32 |
-
model, nlp, kw_model = load_models()
|
| 33 |
-
|
| 34 |
-
# -----------------------------------------------------------------------------
|
| 35 |
-
# Core Python Functions (from your script)
|
| 36 |
-
# -----------------------------------------------------------------------------
|
| 37 |
-
def extract_text_from_pdf(pdf_file):
|
| 38 |
-
"""Extracts text from an uploaded PDF file."""
|
| 39 |
-
text = ''
|
| 40 |
-
with pdfplumber.open(pdf_file) as pdf:
|
| 41 |
-
for page in pdf.pages:
|
| 42 |
-
page_text = page.extract_text()
|
| 43 |
-
if page_text:
|
| 44 |
-
text += page_text + '\n'
|
| 45 |
-
return text.strip()
|
| 46 |
-
|
| 47 |
-
def clean_text(text):
|
| 48 |
-
"""Cleans the extracted text by removing extra whitespace."""
|
| 49 |
-
return re.sub(r'\s+', ' ', text).strip()
|
| 50 |
-
|
| 51 |
-
def extract_section(text, section_name):
|
| 52 |
-
"""Extracts a specific section from the text."""
|
| 53 |
-
pattern = re.compile(rf'{section_name}(.+?)(?=(Education|Work Experience|Technical Skills|Projects|Certifications|$))',
|
| 54 |
-
re.IGNORECASE | re.DOTALL)
|
| 55 |
-
match = pattern.search(text)
|
| 56 |
-
return match.group(1).strip() if match else ""
|
| 57 |
-
|
| 58 |
-
def extract_skills_auto(text, top_n=20):
|
| 59 |
-
"""Extracts keywords and keyphrases as skills."""
|
| 60 |
-
keywords = kw_model.extract_keywords(text, keyphrase_ngram_range=(1, 3), stop_words='english', top_n=top_n)
|
| 61 |
-
return sorted([kw[0] for kw in keywords])
|
| 62 |
-
|
| 63 |
-
def calculate_similarity(text1, text2):
|
| 64 |
-
"""Calculates the cosine similarity between two texts."""
|
| 65 |
-
emb1 = model.encode(text1, convert_to_tensor=True)
|
| 66 |
-
emb2 = model.encode(text2, convert_to_tensor=True)
|
| 67 |
-
score = util.pytorch_cos_sim(emb1, emb2).item()
|
| 68 |
-
return round(score * 100, 2)
|
| 69 |
-
|
| 70 |
-
def enhanced_info_extraction(resume_text):
|
| 71 |
-
"""Extracts degrees and organizations from the resume text."""
|
| 72 |
-
DEGREE_KEYWORDS = [
|
| 73 |
-
"Bachelor", "Bachelors", "B.Tech", "B.E", "BE", "BS", "BSc",
|
| 74 |
-
"Master", "M.Tech", "M.E", "MS", "MSc", "PhD", "Diploma"
|
| 75 |
-
]
|
| 76 |
-
doc = nlp(resume_text)
|
| 77 |
-
|
| 78 |
-
# Extract Degrees using keywords
|
| 79 |
-
degrees = list(set([deg for deg in DEGREE_KEYWORDS if re.search(rf"\b{deg}\b", resume_text, re.IGNORECASE)]))
|
| 80 |
-
|
| 81 |
-
# Extract Organizations using spaCy's NER
|
| 82 |
-
organizations = list(set([ent.text.strip() for ent in doc.ents if ent.label_ == "ORG"]))
|
| 83 |
-
|
| 84 |
-
return degrees, organizations
|
| 85 |
-
|
| 86 |
-
# -----------------------------------------------------------------------------
|
| 87 |
-
# UI Styling
|
| 88 |
-
# -----------------------------------------------------------------------------
|
| 89 |
-
def apply_custom_css():
|
| 90 |
-
"""Applies custom CSS for a professional look and feel."""
|
| 91 |
-
st.markdown("""
|
| 92 |
-
<style>
|
| 93 |
-
/* Main container and sidebar */
|
| 94 |
-
.stApp {
|
| 95 |
-
background-color: #0e1117;
|
| 96 |
-
color: #ffffff;
|
| 97 |
-
}
|
| 98 |
-
.st-emotion-cache-16txtl3 {
|
| 99 |
-
padding-top: 2rem;
|
| 100 |
-
}
|
| 101 |
-
/* Buttons */
|
| 102 |
-
.stButton>button {
|
| 103 |
-
width: 100%;
|
| 104 |
-
border-radius: 10px;
|
| 105 |
-
background-color: #4B8BBE;
|
| 106 |
-
color: white;
|
| 107 |
-
border: 2px solid #4B8BBE;
|
| 108 |
-
transition: all 0.2s ease-in-out;
|
| 109 |
-
}
|
| 110 |
-
.stButton>button:hover {
|
| 111 |
-
background-color: white;
|
| 112 |
-
color: #4B8BBE;
|
| 113 |
-
border: 2px solid #4B8BBE;
|
| 114 |
-
}
|
| 115 |
-
/* Expander styling */
|
| 116 |
-
.st-emotion-cache-p5msec {
|
| 117 |
-
border-radius: 10px;
|
| 118 |
-
border: 1px solid #2d3748;
|
| 119 |
-
background-color: #1a202c;
|
| 120 |
-
}
|
| 121 |
-
/* Metric styling */
|
| 122 |
-
.st-emotion-cache-1g8i8r4 {
|
| 123 |
-
background-color: #1a202c;
|
| 124 |
-
border-radius: 10px;
|
| 125 |
-
padding: 1rem;
|
| 126 |
-
box-shadow: 0 4px 6px rgba(0,0,0,0.3);
|
| 127 |
-
border: 1px solid #2d3748;
|
| 128 |
-
}
|
| 129 |
-
/* Text area */
|
| 130 |
-
.stTextArea textarea {
|
| 131 |
-
border-radius: 10px;
|
| 132 |
-
background-color: #1a202c;
|
| 133 |
-
border: 1px solid #2d3748;
|
| 134 |
-
color: #ffffff;
|
| 135 |
-
}
|
| 136 |
-
/* File uploader */
|
| 137 |
-
.st-emotion-cache-1gulkj5 {
|
| 138 |
-
border-radius: 10px;
|
| 139 |
-
background-color: #1a202c;
|
| 140 |
-
border: 1px solid #2d3748;
|
| 141 |
-
}
|
| 142 |
-
/* Sidebar styling */
|
| 143 |
-
.css-1d391kg {
|
| 144 |
-
background-color: #1a202c;
|
| 145 |
-
}
|
| 146 |
-
/* Text color for better visibility */
|
| 147 |
-
.stMarkdown, .stText {
|
| 148 |
-
color: #ffffff;
|
| 149 |
-
}
|
| 150 |
-
/* Success and warning messages */
|
| 151 |
-
.stSuccess {
|
| 152 |
-
background-color: #1a202c;
|
| 153 |
-
border: 1px solid #38a169;
|
| 154 |
-
}
|
| 155 |
-
.stWarning {
|
| 156 |
-
background-color: #1a202c;
|
| 157 |
-
border: 1px solid #d69e2e;
|
| 158 |
-
}
|
| 159 |
-
.stInfo {
|
| 160 |
-
background-color: #1a202c;
|
| 161 |
-
border: 1px solid #3182ce;
|
| 162 |
-
}
|
| 163 |
-
.stError {
|
| 164 |
-
background-color: #1a202c;
|
| 165 |
-
border: 1px solid #e53e3e;
|
| 166 |
-
}
|
| 167 |
-
</style>
|
| 168 |
-
""", unsafe_allow_html=True)
|
| 169 |
-
|
| 170 |
-
# -----------------------------------------------------------------------------
|
| 171 |
-
# Main Application UI
|
| 172 |
-
# -----------------------------------------------------------------------------
|
| 173 |
-
apply_custom_css()
|
| 174 |
-
|
| 175 |
-
# --- Sidebar for Inputs ---
|
| 176 |
-
with st.sidebar:
|
| 177 |
-
# st.image("https://i.imgur.com/g0h29tF.png", width=150) # A generic logo
|
| 178 |
-
st.title("📝 Input Panel")
|
| 179 |
-
st.markdown("Provide your resume and the job description to get a detailed match analysis.")
|
| 180 |
-
|
| 181 |
-
uploaded_resume = st.file_uploader(
|
| 182 |
-
"Upload Your Resume (PDF)",
|
| 183 |
-
type=["pdf"],
|
| 184 |
-
help="Please upload your resume in PDF format."
|
| 185 |
-
)
|
| 186 |
-
|
| 187 |
-
job_description = st.text_area(
|
| 188 |
-
"Paste Job Description",
|
| 189 |
-
height=300,
|
| 190 |
-
placeholder="Paste the full job description here..."
|
| 191 |
-
)
|
| 192 |
-
|
| 193 |
-
analyze_button = st.button("Analyze Match ✨")
|
| 194 |
-
|
| 195 |
-
# --- Main Panel for Results ---
|
| 196 |
-
st.title("AI-Powered Resume Matcher")
|
| 197 |
-
st.markdown("Welcome! This tool analyzes your resume against a job description to provide a similarity score and a detailed breakdown of matching skills.")
|
| 198 |
-
st.markdown("---")
|
| 199 |
-
|
| 200 |
-
if analyze_button:
|
| 201 |
-
if uploaded_resume is not None and job_description:
|
| 202 |
-
with st.spinner("Analyzing your documents... This may take a moment. ⏳"):
|
| 203 |
-
try:
|
| 204 |
-
# --- Processing ---
|
| 205 |
-
resume_file = io.BytesIO(uploaded_resume.getvalue())
|
| 206 |
-
resume_text = clean_text(extract_text_from_pdf(resume_file))
|
| 207 |
-
|
| 208 |
-
# Skill Extraction
|
| 209 |
-
resume_skills = extract_skills_auto(resume_text)
|
| 210 |
-
jd_skills = extract_skills_auto(job_description)
|
| 211 |
-
|
| 212 |
-
# Information Extraction
|
| 213 |
-
degrees, organizations = enhanced_info_extraction(resume_text)
|
| 214 |
-
|
| 215 |
-
# Similarity Score
|
| 216 |
-
match_score = calculate_similarity(" ".join(resume_skills), " ".join(jd_skills))
|
| 217 |
-
|
| 218 |
-
# Match Level Logic
|
| 219 |
-
if match_score > 85:
|
| 220 |
-
level = "Excellent Match"
|
| 221 |
-
level_icon = "🟢"
|
| 222 |
-
elif match_score > 70:
|
| 223 |
-
level = "Good Match"
|
| 224 |
-
level_icon = "🟡"
|
| 225 |
-
elif match_score > 50:
|
| 226 |
-
level = "Partial Match"
|
| 227 |
-
level_icon = "🟠"
|
| 228 |
-
else:
|
| 229 |
-
level = "Poor Match"
|
| 230 |
-
level_icon = "🔴"
|
| 231 |
-
|
| 232 |
-
# --- Displaying Results ---
|
| 233 |
-
st.header("Analysis Report")
|
| 234 |
-
col1, col2 = st.columns(2)
|
| 235 |
-
with col1:
|
| 236 |
-
st.metric(label="**Match Score**", value=f"{match_score}%")
|
| 237 |
-
with col2:
|
| 238 |
-
st.metric(label="**Match Level**", value=f"{level_icon} {level}")
|
| 239 |
-
|
| 240 |
-
st.markdown("---")
|
| 241 |
-
|
| 242 |
-
# Skills Comparison Expander
|
| 243 |
-
with st.expander("✅ **Skills Match Breakdown**", expanded=True):
|
| 244 |
-
# Find matching and missing skills
|
| 245 |
-
matching_skills = sorted(list(set(resume_skills) & set(jd_skills)))
|
| 246 |
-
missing_skills = sorted(list(set(jd_skills) - set(resume_skills)))
|
| 247 |
-
|
| 248 |
-
col1, col2 = st.columns(2)
|
| 249 |
-
|
| 250 |
-
with col1:
|
| 251 |
-
st.subheader("Your Top Skills")
|
| 252 |
-
st.markdown(f"<div style='background-color:#000000; padding:10px; border-radius:10px; border: 1px solid #2d3748;'>"
|
| 253 |
-
f"{', '.join(f'<span>`{s}`</span>' for s in resume_skills)}"
|
| 254 |
-
f"</div>", unsafe_allow_html=True)
|
| 255 |
-
|
| 256 |
-
with col2:
|
| 257 |
-
st.subheader("Required Skills in JD")
|
| 258 |
-
st.markdown(f"<div style='background-color:#000000; padding:10px; border-radius:10px; border: 1px solid #2d3748;'>"
|
| 259 |
-
f"{', '.join(f'<span>`{s}`</span>' for s in jd_skills)}"
|
| 260 |
-
f"</div>", unsafe_allow_html=True)
|
| 261 |
-
|
| 262 |
-
st.subheader("Comparison")
|
| 263 |
-
st.success(f"**Matching Skills ({len(matching_skills)}):** {', '.join(matching_skills) if matching_skills else 'None'}")
|
| 264 |
-
st.warning(f"**Missing Skills ({len(missing_skills)}):** {', '.join(missing_skills) if missing_skills else 'None'}")
|
| 265 |
-
|
| 266 |
-
# Extracted Information Expander
|
| 267 |
-
with st.expander("🎓 **Extracted Information from Resume**"):
|
| 268 |
-
st.info(f"**Degrees Found:** {', '.join(degrees) if degrees else 'None detected'}")
|
| 269 |
-
st.info(f"**Organizations Found:** {', '.join(organizations) if organizations else 'None detected'}")
|
| 270 |
-
|
| 271 |
-
except Exception as e:
|
| 272 |
-
st.error(f"An error occurred during analysis: {e}")
|
| 273 |
-
else:
|
| 274 |
-
st.warning("Please upload a resume and paste a job description before analyzing.")
|
| 275 |
-
else:
|
| 276 |
-
st.info("Your analysis report will appear here once you click the 'Analyze Match' button.")
|
| 277 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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