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 """
Upload Required
Please Upload a Resume
Upload a PDF, DOCX, or TXT resume to receive analysis.
"""
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"""
"""
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"{s}" for s in suggestions])
return f"""
AI Resume Analysis
{level}
{summary}
{score}
/100
Resume Strength Score
Resume Checklist
{checklist_html}
Areas to Improve
{missing_text}
Smart Feedback
Target Opportunity
{target_role if target_role else "General Applications"}
"""
# -----------------------------
# 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("""
AI Resume Analyzer
for Students
Upload a resume and receive instant, structured feedback to strengthen applications,
improve clarity, and stand out for colleges, internships, and future opportunities.
""")
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("""
Ready
Your Resume Feedback Will Appear Here
Upload a resume to receive a professional score,
checklist, and improvement suggestions.
""")
analyze_btn.click(
analyze_resume,
inputs=[resume_file, target_role],
outputs=output
)
app.launch()