Spaces:
Sleeping
Sleeping
Download app.py from AI-Accelerator/krish-ResumeAnalyzer: direct link, hf CLI and curl.
- Browser
- Download file 11.4 kB
-
https://huggingface.co/spaces/AI-Accelerator/krish-ResumeAnalyzer/resolve/main/app.py
- Command line
-
hf download hf://spaces/AI-Accelerator/krish-ResumeAnalyzer/app.py
-
curl -L -o app.py https://huggingface.co/spaces/AI-Accelerator/krish-ResumeAnalyzer/resolve/main/app.py
11.4 kB
| import gradio as gr | |
| from pypdf import PdfReader | |
| from docx import Document | |
| import re | |
| # ----------------------------- | |
| # EXTRACT TEXT FROM RESUME | |
| # ----------------------------- | |
| def extract_text(file): | |
| if file is None: | |
| return "" | |
| path = file.name | |
| if path.endswith(".pdf"): | |
| reader = PdfReader(path) | |
| text = "" | |
| for page in reader.pages: | |
| text += page.extract_text() or "" | |
| return text | |
| if path.endswith(".docx"): | |
| doc = Document(path) | |
| return "\n".join([p.text for p in doc.paragraphs]) | |
| if path.endswith(".txt"): | |
| with open(path, "r", encoding="utf-8", errors="ignore") as f: | |
| return f.read() | |
| return "" | |
| # ----------------------------- | |
| # RESUME ANALYSIS LOGIC | |
| # ----------------------------- | |
| def score_resume(text): | |
| score = 0 | |
| feedback = [] | |
| checks = { | |
| "Contact Information": bool(re.search(r"[\w\.-]+@[\w\.-]+", text)), | |
| "Education Section": "education" in text.lower(), | |
| "Experience Section": any(word in text.lower() for word in ["experience", "internship", "work", "volunteer"]), | |
| "Projects Section": any(word in text.lower() for word in ["project", "github", "portfolio"]), | |
| "Skills Section": "skills" in text.lower(), | |
| "Action Verbs": len(re.findall(r"\b(created|built|developed|led|managed|designed|improved|organized|analyzed)\b", text.lower())) >= 3, | |
| "Quantifiable Impact": bool(re.search(r"\d+%|\d+\+|\$\d+|\d+ students|\d+ projects", text.lower())), | |
| "Technical Keywords": any(word in text.lower() for word in ["python", "ai", "machine learning", "data", "automation", "chatbot"]), | |
| } | |
| for item, passed in checks.items(): | |
| if passed: | |
| score += 12.5 | |
| else: | |
| feedback.append(item) | |
| return int(score), feedback, checks | |
| # ----------------------------- | |
| # MAIN ANALYZER | |
| # ----------------------------- | |
| def analyze_resume(file, target_role): | |
| text = extract_text(file) | |
| if not text.strip(): | |
| return """ | |
| <div class="result-card"> | |
| <div class="badge">Upload Required</div> | |
| <h2>Please Upload a Resume</h2> | |
| <p class="summary"> | |
| Upload a PDF, DOCX, or TXT resume to receive analysis. | |
| </p> | |
| </div> | |
| """ | |
| score, missing, checks = score_resume(text) | |
| if score >= 85: | |
| level = "Strong Resume" | |
| summary = "Your resume already has strong structure and application value." | |
| elif score >= 65: | |
| level = "Good Foundation" | |
| summary = "Your resume has strong potential but needs more measurable outcomes and stronger positioning." | |
| else: | |
| level = "Needs Improvement" | |
| summary = "Your resume needs stronger structure, technical depth, and clearer impact." | |
| checklist_html = "" | |
| for item, passed in checks.items(): | |
| icon = "✅" if passed else "⚠️" | |
| checklist_html += f""" | |
| <div class="check-row"> | |
| <span>{icon}</span> | |
| <p>{item}</p> | |
| </div> | |
| """ | |
| missing_text = "None — strong coverage." if not missing else ", ".join(missing) | |
| suggestions = [ | |
| "Add measurable outcomes using numbers, percentages, projects completed, or impact created.", | |
| "Include a projects section if applying to competitive colleges, internships, STEM programs, or AI opportunities.", | |
| "Use stronger action verbs such as built, developed, led, designed, analyzed, and improved.", | |
| "Tailor the resume toward your target role instead of using one generic version.", | |
| "Highlight technical tools, leadership experience, certifications, and portfolio work." | |
| ] | |
| suggestions_html = "".join([f"<li>{s}</li>" for s in suggestions]) | |
| return f""" | |
| <div class="result-card"> | |
| <div class="badge">AI Resume Analysis</div> | |
| <h2>{level}</h2> | |
| <p class="summary">{summary}</p> | |
| <div class="score-box"> | |
| <div> | |
| <span class="score">{score}</span> | |
| <span class="score-small">/100</span> | |
| </div> | |
| <p>Resume Strength Score</p> | |
| </div> | |
| <h3>Resume Checklist</h3> | |
| {checklist_html} | |
| <h3>Areas to Improve</h3> | |
| <p>{missing_text}</p> | |
| <h3>Smart Feedback</h3> | |
| <ul> | |
| {suggestions_html} | |
| </ul> | |
| <h3>Target Opportunity</h3> | |
| <p><strong>{target_role if target_role else "General Applications"}</strong></p> | |
| </div> | |
| """ | |
| # ----------------------------- | |
| # PREMIUM CSS | |
| # ----------------------------- | |
| css = """ | |
| @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap'); | |
| :root { | |
| --navy: #071A33; | |
| --navy2: #0E2A4F; | |
| --gold: #C9A227; | |
| --cream: #F7F3EA; | |
| --white: #FFFFFF; | |
| --text: #111827; | |
| --muted: #64748B; | |
| --border: #E5E7EB; | |
| --soft: #F8FAFC; | |
| } | |
| body { | |
| background: | |
| radial-gradient(circle at top left, rgba(201,162,39,0.10), transparent 30%), | |
| linear-gradient(135deg, #F7F3EA 0%, #F8FAFC 45%, #FFFFFF 100%) !important; | |
| font-family: 'Inter', sans-serif !important; | |
| } | |
| .gradio-container { | |
| max-width: 1180px !important; | |
| margin: auto !important; | |
| padding: 36px 20px !important; | |
| } | |
| /* HERO */ | |
| #hero { | |
| background: linear-gradient(135deg, #071A33 0%, #0E2A4F 100%); | |
| color: white; | |
| padding: 52px 54px; | |
| border-radius: 32px; | |
| margin-bottom: 30px; | |
| box-shadow: 0 28px 80px rgba(7, 26, 51, 0.28); | |
| border: 1px solid rgba(255,255,255,0.08); | |
| position: relative; | |
| overflow: hidden; | |
| } | |
| #hero::after { | |
| content: ""; | |
| position: absolute; | |
| width: 340px; | |
| height: 340px; | |
| right: -120px; | |
| top: -120px; | |
| background: rgba(201,162,39,0.16); | |
| border-radius: 50%; | |
| } | |
| #hero h1 { | |
| font-size: 48px; | |
| line-height: 1.05; | |
| font-weight: 900; | |
| margin: 0 0 16px 0; | |
| color: #FFFFFF !important; | |
| letter-spacing: -0.04em; | |
| text-shadow: 0 4px 18px rgba(0,0,0,0.35); | |
| max-width: 780px; | |
| position: relative; | |
| z-index: 2; | |
| } | |
| #hero p { | |
| font-size: 18px; | |
| line-height: 1.65; | |
| color: #DDE7F6; | |
| max-width: 760px; | |
| margin: 0; | |
| position: relative; | |
| z-index: 2; | |
| } | |
| .gold { | |
| color: #E7C766; | |
| } | |
| /* PANELS */ | |
| .panel { | |
| background: rgba(255,255,255,0.92); | |
| border-radius: 28px; | |
| padding: 28px; | |
| box-shadow: 0 18px 55px rgba(15,23,42,0.08); | |
| border: 1px solid rgba(226,232,240,0.95); | |
| } | |
| /* LABELS */ | |
| label { | |
| color: #071A33 !important; | |
| font-weight: 700 !important; | |
| font-size: 13px !important; | |
| } | |
| /* INPUTS */ | |
| input, textarea, select { | |
| border-radius: 14px !important; | |
| border: 1px solid #D7DEE8 !important; | |
| background: #FFFFFF !important; | |
| color: #111827 !important; | |
| } | |
| input:focus, textarea:focus { | |
| border-color: #C9A227 !important; | |
| box-shadow: 0 0 0 3px rgba(201,162,39,0.12) !important; | |
| } | |
| /* BUTTON */ | |
| button { | |
| background: linear-gradient(135deg, #071A33 0%, #0E2A4F 100%) !important; | |
| color: white !important; | |
| border-radius: 16px !important; | |
| font-weight: 800 !important; | |
| border: 1px solid rgba(255,255,255,0.12) !important; | |
| padding: 14px 20px !important; | |
| box-shadow: 0 12px 28px rgba(7,26,51,0.20) !important; | |
| } | |
| button:hover { | |
| transform: translateY(-1px); | |
| box-shadow: 0 16px 36px rgba(7,26,51,0.26) !important; | |
| } | |
| /* RESULT CARD */ | |
| .result-card { | |
| background: rgba(255,255,255,0.96); | |
| border-radius: 28px; | |
| padding: 30px; | |
| border: 1px solid rgba(226,232,240,0.95); | |
| box-shadow: 0 18px 55px rgba(15,23,42,0.08); | |
| color: #111827; | |
| } | |
| .badge { | |
| display: inline-block; | |
| background: #F7F3EA; | |
| color: #8A6A12; | |
| padding: 8px 14px; | |
| border-radius: 999px; | |
| font-weight: 800; | |
| font-size: 12px; | |
| text-transform: uppercase; | |
| letter-spacing: 0.06em; | |
| margin-bottom: 12px; | |
| border: 1px solid rgba(201,162,39,0.24); | |
| } | |
| .result-card h2 { | |
| color: #071A33; | |
| font-size: 34px; | |
| font-weight: 900; | |
| margin: 8px 0 12px 0; | |
| letter-spacing: -0.03em; | |
| } | |
| .result-card h3 { | |
| color: #071A33; | |
| font-size: 18px; | |
| font-weight: 850; | |
| margin-top: 24px; | |
| margin-bottom: 12px; | |
| } | |
| .summary { | |
| color: #64748B; | |
| font-size: 16px; | |
| line-height: 1.65; | |
| } | |
| /* SCORE */ | |
| .score-box { | |
| margin: 24px 0; | |
| background: linear-gradient(135deg, #071A33 0%, #0E2A4F 100%); | |
| color: white; | |
| padding: 24px; | |
| border-radius: 24px; | |
| border: 1px solid rgba(255,255,255,0.10); | |
| box-shadow: 0 16px 40px rgba(7,26,51,0.22); | |
| } | |
| .score { | |
| font-size: 58px; | |
| font-weight: 900; | |
| color: #E7C766; | |
| letter-spacing: -0.04em; | |
| } | |
| .score-small { | |
| font-size: 24px; | |
| color: #FFFFFF; | |
| } | |
| /* CHECKLIST */ | |
| .check-row { | |
| display: flex; | |
| gap: 12px; | |
| align-items: center; | |
| background: #F8FAFC; | |
| border: 1px solid #E5E7EB; | |
| border-radius: 16px; | |
| padding: 12px 14px; | |
| margin-bottom: 9px; | |
| } | |
| .check-row p { | |
| margin: 0; | |
| font-weight: 650; | |
| color: #111827; | |
| } | |
| /* LISTS */ | |
| ul { | |
| padding-left: 22px; | |
| } | |
| li { | |
| margin-bottom: 9px; | |
| line-height: 1.55; | |
| color: #334155; | |
| } | |
| /* MOBILE */ | |
| @media (max-width: 800px) { | |
| #hero { | |
| padding: 36px 28px; | |
| border-radius: 24px; | |
| } | |
| #hero h1 { | |
| font-size: 34px; | |
| } | |
| #hero p { | |
| font-size: 16px; | |
| } | |
| } | |
| """ | |
| # ----------------------------- | |
| # FRONTEND | |
| # ----------------------------- | |
| with gr.Blocks( | |
| css=css, | |
| title="AI Resume Analyzer | AI-Scholars Final Project" | |
| ) as app: | |
| gr.HTML(""" | |
| <div id="hero"> | |
| <h1> | |
| AI Resume Analyzer | |
| <span class="gold">for Students</span> | |
| </h1> | |
| <p> | |
| Upload a resume and receive instant, structured feedback to strengthen applications, | |
| improve clarity, and stand out for colleges, internships, and future opportunities. | |
| </p> | |
| </div> | |
| """) | |
| with gr.Row(): | |
| with gr.Column(scale=1, elem_classes="panel"): | |
| gr.Markdown("## Upload Resume") | |
| resume_file = gr.File( | |
| label="Upload PDF, DOCX, or TXT Resume" | |
| ) | |
| target_role = gr.Textbox( | |
| label="Target Opportunity", | |
| placeholder="Example: Internship, Research Program, College Application" | |
| ) | |
| analyze_btn = gr.Button( | |
| "Analyze Resume" | |
| ) | |
| with gr.Column(scale=1): | |
| output = gr.HTML(""" | |
| <div class="result-card"> | |
| <div class="badge">Ready</div> | |
| <h2>Your Resume Feedback Will Appear Here</h2> | |
| <p class="summary"> | |
| Upload a resume to receive a professional score, | |
| checklist, and improvement suggestions. | |
| </p> | |
| </div> | |
| """) | |
| analyze_btn.click( | |
| analyze_resume, | |
| inputs=[resume_file, target_role], | |
| outputs=output | |
| ) | |
| app.launch() |