Spaces:
Sleeping
Sleeping
File size: 21,484 Bytes
c62d40f 50c5705 c62d40f | 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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | {
"cells": [
{
"cell_type": "code",
"execution_count": 13,
"id": "2a42ee92-b6a0-4a96-af66-3ac795fe6b6b",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"[nltk_data] Downloading package stopwords to\n",
"[nltk_data] C:\\Users\\valan\\AppData\\Roaming\\nltk_data...\n",
"[nltk_data] Package stopwords is already up-to-date!\n"
]
}
],
"source": [
"# For Hugging Face Spaces with Streamlit\n",
"import os\n",
"os.system(\"python -m spacy download en_core_web_sm\")\n"
"import streamlit as st\n",
"import pdfplumber\n",
"import docx2txt\n",
"import spacy\n",
"import re\n",
"from sklearn.feature_extraction.text import TfidfVectorizer\n",
"from sklearn.metrics.pairwise import cosine_similarity\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import nltk\n",
"from nltk.corpus import stopwords\n",
"from collections import Counter\n",
"import base64\n",
"\n",
"# Download NLTK data\n",
"@st.cache_resource\n",
"def download_nltk_data():\n",
" nltk.download('stopwords')\n",
" return True\n",
"\n",
"# Load spaCy model\n",
"@st.cache_resource\n",
"def load_spacy():\n",
" try:\n",
" return spacy.load(\"en_core_web_sm\")\n",
" except OSError:\n",
" import os\n",
" os.system(\"python -m spacy download en_core_web_sm\")\n",
" return spacy.load(\"en_core_web_sm\")\n",
"\n",
"# Initialize\n",
"download_nltk_data()\n",
"nlp = load_spacy()\n",
"\n",
"# Resume parsing functions\n",
"def extract_text_from_pdf(file):\n",
" with pdfplumber.open(file) as pdf:\n",
" text = \" \".join([page.extract_text() or \"\" for page in pdf.pages])\n",
" return text\n",
"\n",
"def extract_text_from_docx(file):\n",
" text = docx2txt.process(file)\n",
" return text\n",
"\n",
"def extract_text(file):\n",
" file_name = file.name.lower()\n",
" if file_name.endswith('.pdf'):\n",
" return extract_text_from_pdf(file)\n",
" elif file_name.endswith('.docx'):\n",
" return extract_text_from_docx(file)\n",
" else:\n",
" return \"Unsupported file format. Please upload a PDF or DOCX file.\"\n",
"\n",
"# ATS Scoring functions\n",
"def preprocess_text(text):\n",
" text = text.lower()\n",
" text = re.sub(r'[^\\w\\s]', ' ', text)\n",
" text = re.sub(r'\\d+', ' ', text)\n",
" text = re.sub(r'\\s+', ' ', text).strip()\n",
" return text\n",
"\n",
"def calculate_similarity_score(resume_text, job_desc_text):\n",
" resume_processed = preprocess_text(resume_text)\n",
" job_processed = preprocess_text(job_desc_text)\n",
" \n",
" vectorizer = TfidfVectorizer(stop_words='english')\n",
" try:\n",
" tfidf_matrix = vectorizer.fit_transform([resume_processed, job_processed])\n",
" similarity = cosine_similarity(tfidf_matrix[0:1], tfidf_matrix[1:2])[0][0]\n",
" return similarity * 100\n",
" except:\n",
" return 0\n",
"\n",
"def extract_skills_from_text(text):\n",
" doc = nlp(text.lower())\n",
" potential_skills = [token.text for token in doc if token.pos_ in [\"NOUN\", \"PROPN\"]]\n",
" \n",
" stop_words = set(stopwords.words('english'))\n",
" skills = [skill for skill in potential_skills \n",
" if skill not in stop_words and len(skill) > 2]\n",
" \n",
" skill_freq = Counter(skills)\n",
" return skill_freq\n",
"\n",
"def get_missing_keywords(resume_text, job_desc_text, threshold=2):\n",
" job_skills = extract_skills_from_text(job_desc_text)\n",
" resume_skills = extract_skills_from_text(resume_text)\n",
" \n",
" missing_skills = {skill: count for skill, count in job_skills.items() \n",
" if count >= threshold and skill not in resume_skills}\n",
" \n",
" sorted_missing = sorted(missing_skills.items(), key=lambda x: x[1], reverse=True)\n",
" return sorted_missing\n",
"\n",
"def check_ats_formatting(resume_text):\n",
" formatting_issues = []\n",
" \n",
" important_sections = ['experience', 'education', 'skills', 'projects']\n",
" found_sections = []\n",
" \n",
" for section in important_sections:\n",
" pattern = re.compile(r'\\b' + section + r'\\b', re.IGNORECASE)\n",
" if pattern.search(resume_text):\n",
" found_sections.append(section)\n",
" \n",
" missing_sections = set(important_sections) - set(found_sections)\n",
" if missing_sections:\n",
" formatting_issues.append(f\"Missing key sections: {', '.join(missing_sections)}\")\n",
" \n",
" if 'โข' not in resume_text and '*' not in resume_text and '-' not in resume_text:\n",
" formatting_issues.append(\"No bullet points detected - consider using them for listing skills and responsibilities\")\n",
" \n",
" if '|' in resume_text or '\\t' in resume_text:\n",
" formatting_issues.append(\"Possible tables detected - avoid tables as they may not parse correctly\")\n",
" \n",
" contact_patterns = [\n",
" r'\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Z|a-z]{2,}\\b', # Email\n",
" r'\\b\\d{3}[-.]?\\d{3}[-.]?\\d{4}\\b', # Phone number\n",
" r'linkedin\\.com' # LinkedIn\n",
" ]\n",
" \n",
" missing_contact = []\n",
" for i, pattern in enumerate(['email', 'phone', 'linkedin']):\n",
" if not re.search(contact_patterns[i], resume_text, re.IGNORECASE):\n",
" missing_contact.append(pattern)\n",
" \n",
" if missing_contact:\n",
" formatting_issues.append(f\"Missing contact information: {', '.join(missing_contact)}\")\n",
" \n",
" paragraphs = resume_text.split('\\n\\n')\n",
" long_paragraphs = [p for p in paragraphs if len(p.split()) > 40]\n",
" if long_paragraphs:\n",
" formatting_issues.append(f\"Found {len(long_paragraphs)} long paragraphs - consider breaking them into bullet points\")\n",
" \n",
" return formatting_issues if formatting_issues else [\"No major formatting issues detected!\"]\n",
"\n",
"# Resume advice function\n",
"def get_resume_advice(query, resume_score=None, missing_keywords=None, formatting_issues=None):\n",
" query_lower = query.lower()\n",
" \n",
" context = \"\"\n",
" if resume_score is not None:\n",
" context += f\"Based on your ATS score of {resume_score:.1f}%: \"\n",
" \n",
" if any(word in query_lower for word in ['ats', 'score', 'improve score']):\n",
" return context + \"To improve your ATS score, tailor your resume to match the job description by incorporating relevant keywords naturally. Use a clean, simple format and standard section headings like 'Experience', 'Education', and 'Skills'.\"\n",
" \n",
" elif any(word in query_lower for word in ['keyword', 'keywords', 'missing']):\n",
" keyword_info = \"\"\n",
" if missing_keywords and len(missing_keywords) > 0:\n",
" top_keywords = [k for k, _ in missing_keywords[:5]]\n",
" keyword_info = f\"Consider adding these missing keywords: {', '.join(top_keywords)}. \"\n",
" \n",
" return context + keyword_info + \"Add missing keywords from the job description to your resume, but do it naturally. Include them in your skills section and work experience bullets. Don't just list them - show how you've used these skills in previous roles.\"\n",
" \n",
" elif any(word in query_lower for word in ['format', 'formatting', 'layout']):\n",
" format_info = \"\"\n",
" if formatting_issues and len(formatting_issues) > 0:\n",
" format_info = f\"Your specific formatting issues: {formatting_issues[0] if len(formatting_issues) == 1 else ', '.join(formatting_issues[:2]) + '...'}. \"\n",
" \n",
" return context + format_info + \"For ATS-friendly formatting: 1) Use standard section headings, 2) Avoid tables, images, and complex layouts, 3) Use bullet points for work experience, 4) Include your contact information at the top, 5) Save as a .docx or simple PDF file.\"\n",
" \n",
" elif any(word in query_lower for word in ['bullet', 'bullets', 'point']):\n",
" return context + \"Effective bullet points follow the STAR method: Situation, Task, Action, Result. Start with strong action verbs, include specific metrics where possible, and keep each bullet to 1-2 lines. Make sure they highlight achievements, not just responsibilities.\"\n",
" \n",
" elif any(word in query_lower for word in ['experience', 'work history', 'job']):\n",
" return context + \"When describing work experience, focus on achievements rather than duties. Use metrics and numbers to quantify your impact. Tailor each bullet to highlight skills relevant to the job you're applying for. Use past tense for previous jobs and present tense for current roles.\"\n",
" \n",
" elif any(word in query_lower for word in ['education', 'degree']):\n",
" return context + \"In your education section, list your most recent degree first. Include your degree, major, university name, location, and graduation year. If you're a recent graduate, you can also include relevant coursework, GPA (if above 3.5), and academic achievements.\"\n",
" \n",
" elif any(word in query_lower for word in ['skill', 'skills']):\n",
" return context + \"For your skills section, categorize them (Technical, Software, Soft Skills, etc.) and prioritize those mentioned in the job description. Be specific with technical skills - instead of 'Programming', list specific languages like 'Python' or 'Java'.\"\n",
" \n",
" elif any(word in query_lower for word in ['interview', 'prepare']):\n",
" return context + \"To prepare for interviews: 1) Research the company thoroughly, 2) Practice answering common questions using the STAR method, 3) Prepare examples that showcase the skills in the job description, 4) Have questions ready to ask the interviewer, 5) Review your resume and be ready to elaborate on any point.\"\n",
" \n",
" else:\n",
" return context + \"I'm here to help with your resume and job application questions. For best results, ask specific questions about improving your ATS score, formatting, keywords, or different resume sections. I can also help with interview preparation and career advice.\"\n",
"\n",
"# Create a download link for the results\n",
"def get_table_download_link(df):\n",
" csv = df.to_csv(index=False)\n",
" b64 = base64.b64encode(csv.encode()).decode()\n",
" href = f'<a href=\"data:file/csv;base64,{b64}\" download=\"resume_analysis.csv\">Download results as CSV</a>'\n",
" return href\n",
"\n",
"# Streamlit UI\n",
"st.set_page_config(page_title=\"AI Resume Checker\", page_icon=\"๐\", layout=\"wide\")\n",
"\n",
"st.title(\"๐ AI Resume Checker\")\n",
"st.markdown(\"### Optimize your resume for Applicant Tracking Systems (ATS)\")\n",
"\n",
"# Sidebar with instructions\n",
"with st.sidebar:\n",
" st.header(\"How it works\")\n",
" st.write(\"1. Upload your resume (PDF or DOCX)\")\n",
" st.write(\"2. Enter the job description\")\n",
" st.write(\"3. Get instant ATS compatibility analysis\")\n",
" st.write(\"4. Ask questions to improve your resume\")\n",
" \n",
" st.markdown(\"---\")\n",
" st.markdown(\"### About\")\n",
" st.write(\"This tool helps you optimize your resume for ATS systems by analyzing keyword matching, formatting, and providing personalized advice.\")\n",
" st.write(\"Your data is processed locally and not stored.\")\n",
"\n",
"# Create tabs\n",
"tab1, tab2, tab3 = st.tabs([\"Upload & Analyze\", \"Results\", \"Resume Assistant\"])\n",
"\n",
"# Global variables to store state\n",
"if 'resume_text' not in st.session_state:\n",
" st.session_state.resume_text = None\n",
"if 'job_desc' not in st.session_state:\n",
" st.session_state.job_desc = None\n",
"if 'ats_score' not in st.session_state:\n",
" st.session_state.ats_score = None\n",
"if 'missing_keywords' not in st.session_state:\n",
" st.session_state.missing_keywords = None\n",
"if 'formatting_issues' not in st.session_state:\n",
" st.session_state.formatting_issues = None\n",
"if 'analysis_complete' not in st.session_state:\n",
" st.session_state.analysis_complete = False\n",
"\n",
"# Tab 1: Upload & Analyze\n",
"with tab1:\n",
" col1, col2 = st.columns(2)\n",
" \n",
" with col1:\n",
" st.subheader(\"Upload Resume\")\n",
" uploaded_resume = st.file_uploader(\"Choose a resume file\", type=[\"pdf\", \"docx\"])\n",
" \n",
" if uploaded_resume is not None:\n",
" st.session_state.resume_text = extract_text(uploaded_resume)\n",
" if st.session_state.resume_text == \"Unsupported file format. Please upload a PDF or DOCX file.\":\n",
" st.error(st.session_state.resume_text)\n",
" else:\n",
" st.success(f\"Resume loaded successfully! ({len(st.session_state.resume_text)} characters)\")\n",
" \n",
" with col2:\n",
" st.subheader(\"Job Description\")\n",
" st.session_state.job_desc = st.text_area(\"Paste the job description here\", height=300)\n",
" \n",
" if st.button(\"Analyze Resume\") and st.session_state.resume_text and st.session_state.job_desc:\n",
" with st.spinner(\"Analyzing your resume...\"):\n",
" # Calculate ATS score\n",
" st.session_state.ats_score = calculate_similarity_score(st.session_state.resume_text, st.session_state.job_desc)\n",
" \n",
" # Get missing keywords\n",
" st.session_state.missing_keywords = get_missing_keywords(st.session_state.resume_text, st.session_state.job_desc)\n",
" \n",
" # Check formatting\n",
" st.session_state.formatting_issues = check_ats_formatting(st.session_state.resume_text)\n",
" \n",
" st.session_state.analysis_complete = True\n",
" st.success(\"Analysis complete! Check the Results tab.\")\n",
" st.balloons()\n",
"\n",
"# Tab 2: Results\n",
"with tab2:\n",
" if st.session_state.analysis_complete:\n",
" st.subheader(\"ATS Compatibility Analysis\")\n",
" \n",
" # ATS Score\n",
" col1, col2 = st.columns([1, 2])\n",
" with col1:\n",
" st.metric(\"ATS Score\", f\"{st.session_state.ats_score:.1f}%\")\n",
" if st.session_state.ats_score >= 70:\n",
" st.success(\"Great match! Your resume is well-aligned with this job.\")\n",
" elif st.session_state.ats_score >= 50:\n",
" st.warning(\"Moderate match. Some improvements could help.\")\n",
" else:\n",
" st.error(\"Low match. Significant tailoring recommended.\")\n",
" \n",
" with col2:\n",
" # Create a gauge chart\n",
" fig, ax = plt.subplots(figsize=(4, 0.8))\n",
" ax.barh(0, 100, color='#e0e0e0', height=0.5)\n",
" ax.barh(0, st.session_state.ats_score, color='#2e6ca4' if st.session_state.ats_score >= 70 else '#f9a825' if st.session_state.ats_score >= 50 else '#d32f2f', height=0.5)\n",
" ax.set_xlim(0, 100)\n",
" ax.set_yticks([])\n",
" ax.set_xticks([0, 25, 50, 75, 100])\n",
" ax.spines['top'].set_visible(False)\n",
" ax.spines['right'].set_visible(False)\n",
" ax.spines['left'].set_visible(False)\n",
" plt.tight_layout()\n",
" st.pyplot(fig)\n",
" \n",
" # Formatting Check\n",
" st.subheader(\"Formatting Check\")\n",
" for issue in st.session_state.formatting_issues:\n",
" if \"No major\" in issue:\n",
" st.success(issue)\n",
" else:\n",
" st.warning(issue)\n",
" \n",
" # Missing Keywords\n",
" st.subheader(\"Missing Keywords\")\n",
" if st.session_state.missing_keywords:\n",
" # Create dataframe for keywords\n",
" keywords_df = pd.DataFrame(st.session_state.missing_keywords[:15], columns=[\"Keyword\", \"Frequency\"])\n",
" \n",
" col1, col2 = st.columns([3, 2])\n",
" with col1:\n",
" # Plot missing keywords\n",
" fig, ax = plt.subplots(figsize=(10, min(8, 0.5*min(15, len(st.session_state.missing_keywords)))))\n",
" keywords = keywords_df[\"Keyword\"].tolist()\n",
" counts = keywords_df[\"Frequency\"].tolist()\n",
" ax.barh(keywords, counts, color='#2e6ca4')\n",
" ax.set_xlabel('Frequency in Job Description')\n",
" ax.set_title('Top Missing Keywords')\n",
" plt.tight_layout()\n",
" st.pyplot(fig)\n",
" \n",
" with col2:\n",
" st.dataframe(keywords_df)\n",
" st.markdown(get_table_download_link(keywords_df), unsafe_allow_html=True)\n",
" else:\n",
" st.success(\"Great job! Your resume already contains key terms from the job description.\")\n",
" \n",
" # Improvement suggestions\n",
" st.subheader(\"Improvement Suggestions\")\n",
" if st.session_state.ats_score < 50:\n",
" st.error(\"Your resume needs significant improvements to pass ATS systems. Focus on adding more relevant keywords and improving formatting.\")\n",
" elif st.session_state.ats_score < 70:\n",
" st.warning(\"Your resume may pass some ATS systems but could be improved. Try to incorporate more of the missing keywords.\")\n",
" else:\n",
" st.success(\"Your resume is well-optimized for ATS systems! Make minor adjustments to incorporate any missing keywords.\")\n",
" else:\n",
" st.info(\"Please upload your resume and job description, then click 'Analyze Resume' to see results here.\")\n",
"\n",
"# Tab 3: Resume Assistant\n",
"with tab3:\n",
" st.subheader(\"Ask the Resume AI Assistant\")\n",
" st.write(\"Ask questions about improving your resume, job applications, or interview preparation.\")\n",
" \n",
" user_question = st.text_input(\"Your question:\", placeholder=\"How can I improve my ATS score?\")\n",
" \n",
" if user_question:\n",
" response = get_resume_advice(\n",
" user_question, \n",
" st.session_state.ats_score, \n",
" st.session_state.missing_keywords, \n",
" st.session_state.formatting_issues\n",
" )\n",
" \n",
" st.markdown(f\"### Answer\")\n",
" st.markdown(response)\n",
" \n",
" # Sample questions\n",
" st.markdown(\"### Sample questions\")\n",
" questions = [\n",
" \"How can I improve my ATS score?\",\n",
" \"What keywords am I missing?\",\n",
" \"How should I format my resume?\",\n",
" \"How do I write good bullet points?\",\n",
" \"How should I describe my work experience?\"\n",
" ]\n",
" \n",
" cols = st.columns(3)\n",
" for i, question in enumerate(questions):\n",
" if cols[i % 3].button(question):\n",
" response = get_resume_advice(\n",
" question, \n",
" st.session_state.ats_score, \n",
" st.session_state.missing_keywords, \n",
" st.session_state.formatting_issues\n",
" )\n",
" st.markdown(f\"### Answer\")\n",
" st.markdown(response)"
]
},
{
"cell_type": "code",
"id": "05412911-2886-46ac-bea6-675c43ac5ca5",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|