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
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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
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()