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
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from pypdf import PdfReader
3
+ from docx import Document
4
+ import re
5
+
6
+ # -----------------------------
7
+ # EXTRACT TEXT FROM RESUME
8
+ # -----------------------------
9
+ def extract_text(file):
10
+ if file is None:
11
+ return ""
12
+
13
+ path = file.name
14
+
15
+ if path.endswith(".pdf"):
16
+ reader = PdfReader(path)
17
+ text = ""
18
+ for page in reader.pages:
19
+ text += page.extract_text() or ""
20
+ return text
21
+
22
+ if path.endswith(".docx"):
23
+ doc = Document(path)
24
+ return "\n".join([p.text for p in doc.paragraphs])
25
+
26
+ if path.endswith(".txt"):
27
+ with open(path, "r", encoding="utf-8", errors="ignore") as f:
28
+ return f.read()
29
+
30
+ return ""
31
+
32
+
33
+ # -----------------------------
34
+ # RESUME ANALYSIS LOGIC
35
+ # -----------------------------
36
+ def score_resume(text):
37
+ score = 0
38
+ feedback = []
39
+
40
+ checks = {
41
+ "Contact Information": bool(re.search(r"[\w\.-]+@[\w\.-]+", text)),
42
+ "Education Section": "education" in text.lower(),
43
+ "Experience Section": any(word in text.lower() for word in ["experience", "internship", "work", "volunteer"]),
44
+ "Projects Section": any(word in text.lower() for word in ["project", "github", "portfolio"]),
45
+ "Skills Section": "skills" in text.lower(),
46
+ "Action Verbs": len(re.findall(r"\b(created|built|developed|led|managed|designed|improved|organized|analyzed)\b", text.lower())) >= 3,
47
+ "Quantifiable Impact": bool(re.search(r"\d+%|\d+\+|\$\d+|\d+ students|\d+ projects", text.lower())),
48
+ "Technical Keywords": any(word in text.lower() for word in ["python", "ai", "machine learning", "data", "automation", "chatbot"]),
49
+ }
50
+
51
+ for item, passed in checks.items():
52
+ if passed:
53
+ score += 12.5
54
+ else:
55
+ feedback.append(item)
56
+
57
+ return int(score), feedback, checks
58
+
59
+
60
+ # -----------------------------
61
+ # MAIN ANALYZER
62
+ # -----------------------------
63
+ def analyze_resume(file, target_role):
64
+
65
+ text = extract_text(file)
66
+
67
+ if not text.strip():
68
+ return """
69
+ <div class="result-card">
70
+ <div class="badge">Upload Required</div>
71
+ <h2>Please Upload a Resume</h2>
72
+ <p class="summary">
73
+ Upload a PDF, DOCX, or TXT resume to receive analysis.
74
+ </p>
75
+ </div>
76
+ """
77
+
78
+ score, missing, checks = score_resume(text)
79
+
80
+ if score >= 85:
81
+ level = "Strong Resume"
82
+ summary = "Your resume already has strong structure and application value."
83
+ elif score >= 65:
84
+ level = "Good Foundation"
85
+ summary = "Your resume has strong potential but needs more measurable outcomes and stronger positioning."
86
+ else:
87
+ level = "Needs Improvement"
88
+ summary = "Your resume needs stronger structure, technical depth, and clearer impact."
89
+
90
+ checklist_html = ""
91
+
92
+ for item, passed in checks.items():
93
+ icon = "✅" if passed else "⚠️"
94
+
95
+ checklist_html += f"""
96
+ <div class="check-row">
97
+ <span>{icon}</span>
98
+ <p>{item}</p>
99
+ </div>
100
+ """
101
+
102
+ missing_text = "None — strong coverage." if not missing else ", ".join(missing)
103
+
104
+ suggestions = [
105
+ "Add measurable outcomes using numbers, percentages, projects completed, or impact created.",
106
+ "Include a projects section if applying to competitive colleges, internships, STEM programs, or AI opportunities.",
107
+ "Use stronger action verbs such as built, developed, led, designed, analyzed, and improved.",
108
+ "Tailor the resume toward your target role instead of using one generic version.",
109
+ "Highlight technical tools, leadership experience, certifications, and portfolio work."
110
+ ]
111
+
112
+ suggestions_html = "".join([f"<li>{s}</li>" for s in suggestions])
113
+
114
+ return f"""
115
+ <div class="result-card">
116
+
117
+ <div class="badge">AI Resume Analysis</div>
118
+
119
+ <h2>{level}</h2>
120
+
121
+ <p class="summary">{summary}</p>
122
+
123
+ <div class="score-box">
124
+ <div>
125
+ <span class="score">{score}</span>
126
+ <span class="score-small">/100</span>
127
+ </div>
128
+
129
+ <p>Resume Strength Score</p>
130
+ </div>
131
+
132
+ <h3>Resume Checklist</h3>
133
+
134
+ {checklist_html}
135
+
136
+ <h3>Areas to Improve</h3>
137
+
138
+ <p>{missing_text}</p>
139
+
140
+ <h3>Smart Feedback</h3>
141
+
142
+ <ul>
143
+ {suggestions_html}
144
+ </ul>
145
+
146
+ <h3>Target Opportunity</h3>
147
+
148
+ <p><strong>{target_role if target_role else "General Applications"}</strong></p>
149
+
150
+ </div>
151
+ """
152
+
153
+
154
+ # -----------------------------
155
+ # PREMIUM CSS
156
+ # -----------------------------
157
+ css = """
158
+
159
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');
160
+
161
+ :root {
162
+ --navy: #071A33;
163
+ --navy2: #0E2A4F;
164
+ --gold: #C9A227;
165
+ --cream: #F7F3EA;
166
+ --white: #FFFFFF;
167
+ --text: #111827;
168
+ --muted: #64748B;
169
+ --border: #E5E7EB;
170
+ --soft: #F8FAFC;
171
+ }
172
+
173
+ body {
174
+ background:
175
+ radial-gradient(circle at top left, rgba(201,162,39,0.10), transparent 30%),
176
+ linear-gradient(135deg, #F7F3EA 0%, #F8FAFC 45%, #FFFFFF 100%) !important;
177
+
178
+ font-family: 'Inter', sans-serif !important;
179
+ }
180
+
181
+ .gradio-container {
182
+ max-width: 1180px !important;
183
+ margin: auto !important;
184
+ padding: 36px 20px !important;
185
+ }
186
+
187
+ /* HERO */
188
+ #hero {
189
+ background: linear-gradient(135deg, #071A33 0%, #0E2A4F 100%);
190
+ color: white;
191
+ padding: 52px 54px;
192
+ border-radius: 32px;
193
+ margin-bottom: 30px;
194
+ box-shadow: 0 28px 80px rgba(7, 26, 51, 0.28);
195
+ border: 1px solid rgba(255,255,255,0.08);
196
+ position: relative;
197
+ overflow: hidden;
198
+ }
199
+
200
+ #hero::after {
201
+ content: "";
202
+ position: absolute;
203
+ width: 340px;
204
+ height: 340px;
205
+ right: -120px;
206
+ top: -120px;
207
+ background: rgba(201,162,39,0.16);
208
+ border-radius: 50%;
209
+ }
210
+
211
+ #hero h1 {
212
+ font-size: 48px;
213
+ line-height: 1.05;
214
+ font-weight: 900;
215
+ margin: 0 0 16px 0;
216
+ color: #FFFFFF !important;
217
+ letter-spacing: -0.04em;
218
+ text-shadow: 0 4px 18px rgba(0,0,0,0.35);
219
+ max-width: 780px;
220
+ position: relative;
221
+ z-index: 2;
222
+ }
223
+
224
+ #hero p {
225
+ font-size: 18px;
226
+ line-height: 1.65;
227
+ color: #DDE7F6;
228
+ max-width: 760px;
229
+ margin: 0;
230
+ position: relative;
231
+ z-index: 2;
232
+ }
233
+
234
+ .gold {
235
+ color: #E7C766;
236
+ }
237
+
238
+ /* PANELS */
239
+ .panel {
240
+ background: rgba(255,255,255,0.92);
241
+ border-radius: 28px;
242
+ padding: 28px;
243
+ box-shadow: 0 18px 55px rgba(15,23,42,0.08);
244
+ border: 1px solid rgba(226,232,240,0.95);
245
+ }
246
+
247
+ /* LABELS */
248
+ label {
249
+ color: #071A33 !important;
250
+ font-weight: 700 !important;
251
+ font-size: 13px !important;
252
+ }
253
+
254
+ /* INPUTS */
255
+ input, textarea, select {
256
+ border-radius: 14px !important;
257
+ border: 1px solid #D7DEE8 !important;
258
+ background: #FFFFFF !important;
259
+ color: #111827 !important;
260
+ }
261
+
262
+ input:focus, textarea:focus {
263
+ border-color: #C9A227 !important;
264
+ box-shadow: 0 0 0 3px rgba(201,162,39,0.12) !important;
265
+ }
266
+
267
+ /* BUTTON */
268
+ button {
269
+ background: linear-gradient(135deg, #071A33 0%, #0E2A4F 100%) !important;
270
+ color: white !important;
271
+ border-radius: 16px !important;
272
+ font-weight: 800 !important;
273
+ border: 1px solid rgba(255,255,255,0.12) !important;
274
+ padding: 14px 20px !important;
275
+ box-shadow: 0 12px 28px rgba(7,26,51,0.20) !important;
276
+ }
277
+
278
+ button:hover {
279
+ transform: translateY(-1px);
280
+ box-shadow: 0 16px 36px rgba(7,26,51,0.26) !important;
281
+ }
282
+
283
+ /* RESULT CARD */
284
+ .result-card {
285
+ background: rgba(255,255,255,0.96);
286
+ border-radius: 28px;
287
+ padding: 30px;
288
+ border: 1px solid rgba(226,232,240,0.95);
289
+ box-shadow: 0 18px 55px rgba(15,23,42,0.08);
290
+ color: #111827;
291
+ }
292
+
293
+ .badge {
294
+ display: inline-block;
295
+ background: #F7F3EA;
296
+ color: #8A6A12;
297
+ padding: 8px 14px;
298
+ border-radius: 999px;
299
+ font-weight: 800;
300
+ font-size: 12px;
301
+ text-transform: uppercase;
302
+ letter-spacing: 0.06em;
303
+ margin-bottom: 12px;
304
+ border: 1px solid rgba(201,162,39,0.24);
305
+ }
306
+
307
+ .result-card h2 {
308
+ color: #071A33;
309
+ font-size: 34px;
310
+ font-weight: 900;
311
+ margin: 8px 0 12px 0;
312
+ letter-spacing: -0.03em;
313
+ }
314
+
315
+ .result-card h3 {
316
+ color: #071A33;
317
+ font-size: 18px;
318
+ font-weight: 850;
319
+ margin-top: 24px;
320
+ margin-bottom: 12px;
321
+ }
322
+
323
+ .summary {
324
+ color: #64748B;
325
+ font-size: 16px;
326
+ line-height: 1.65;
327
+ }
328
+
329
+ /* SCORE */
330
+ .score-box {
331
+ margin: 24px 0;
332
+ background: linear-gradient(135deg, #071A33 0%, #0E2A4F 100%);
333
+ color: white;
334
+ padding: 24px;
335
+ border-radius: 24px;
336
+ border: 1px solid rgba(255,255,255,0.10);
337
+ box-shadow: 0 16px 40px rgba(7,26,51,0.22);
338
+ }
339
+
340
+ .score {
341
+ font-size: 58px;
342
+ font-weight: 900;
343
+ color: #E7C766;
344
+ letter-spacing: -0.04em;
345
+ }
346
+
347
+ .score-small {
348
+ font-size: 24px;
349
+ color: #FFFFFF;
350
+ }
351
+
352
+ /* CHECKLIST */
353
+ .check-row {
354
+ display: flex;
355
+ gap: 12px;
356
+ align-items: center;
357
+ background: #F8FAFC;
358
+ border: 1px solid #E5E7EB;
359
+ border-radius: 16px;
360
+ padding: 12px 14px;
361
+ margin-bottom: 9px;
362
+ }
363
+
364
+ .check-row p {
365
+ margin: 0;
366
+ font-weight: 650;
367
+ color: #111827;
368
+ }
369
+
370
+ /* LISTS */
371
+ ul {
372
+ padding-left: 22px;
373
+ }
374
+
375
+ li {
376
+ margin-bottom: 9px;
377
+ line-height: 1.55;
378
+ color: #334155;
379
+ }
380
+
381
+ /* MOBILE */
382
+ @media (max-width: 800px) {
383
+
384
+ #hero {
385
+ padding: 36px 28px;
386
+ border-radius: 24px;
387
+ }
388
+
389
+ #hero h1 {
390
+ font-size: 34px;
391
+ }
392
+
393
+ #hero p {
394
+ font-size: 16px;
395
+ }
396
+ }
397
+ """
398
+
399
+
400
+ # -----------------------------
401
+ # FRONTEND
402
+ # -----------------------------
403
+ with gr.Blocks(
404
+ css=css,
405
+ title="AI Resume Analyzer | AI-Scholars Final Project"
406
+ ) as app:
407
+
408
+ gr.HTML("""
409
+ <div id="hero">
410
+
411
+ <h1>
412
+ AI Resume Analyzer
413
+ <span class="gold">for Students</span>
414
+ </h1>
415
+
416
+ <p>
417
+ Upload a resume and receive instant, structured feedback to strengthen applications,
418
+ improve clarity, and stand out for colleges, internships, and future opportunities.
419
+ </p>
420
+
421
+ </div>
422
+ """)
423
+
424
+ with gr.Row():
425
+
426
+ with gr.Column(scale=1, elem_classes="panel"):
427
+
428
+ gr.Markdown("## Upload Resume")
429
+
430
+ resume_file = gr.File(
431
+ label="Upload PDF, DOCX, or TXT Resume"
432
+ )
433
+
434
+ target_role = gr.Textbox(
435
+ label="Target Opportunity",
436
+ placeholder="Example: Internship, Research Program, College Application"
437
+ )
438
+
439
+ analyze_btn = gr.Button(
440
+ "Analyze Resume"
441
+ )
442
+
443
+ with gr.Column(scale=1):
444
+
445
+ output = gr.HTML("""
446
+ <div class="result-card">
447
+
448
+ <div class="badge">Ready</div>
449
+
450
+ <h2>Your Resume Feedback Will Appear Here</h2>
451
+
452
+ <p class="summary">
453
+ Upload a resume to receive a professional score,
454
+ checklist, and improvement suggestions.
455
+ </p>
456
+
457
+ </div>
458
+ """)
459
+
460
+ analyze_btn.click(
461
+ analyze_resume,
462
+ inputs=[resume_file, target_role],
463
+ outputs=output
464
+ )
465
+
466
+ app.launch()