File size: 4,176 Bytes
1aea493
af788b6
 
d57e12f
1aea493
af788b6
e990ba3
 
 
1aea493
d57e12f
af788b6
d57e12f
af788b6
1aea493
e990ba3
 
1aea493
e990ba3
af788b6
 
 
 
e990ba3
 
 
 
af788b6
e990ba3
 
1aea493
e990ba3
1aea493
 
e990ba3
 
 
1aea493
af788b6
1aea493
e990ba3
af788b6
 
e990ba3
 
 
af788b6
1aea493
af788b6
1aea493
e990ba3
 
 
 
af788b6
1aea493
af788b6
e990ba3
af788b6
d57e12f
1aea493
e990ba3
af788b6
 
e990ba3
1aea493
e990ba3
 
 
 
 
 
 
af788b6
 
 
e990ba3
af788b6
1aea493
 
e990ba3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1aea493
e990ba3
 
af788b6
e990ba3
1aea493
af788b6
1aea493
af788b6
 
 
 
 
 
 
 
 
 
 
 
 
 
1aea493
af788b6
1aea493
af788b6
e990ba3
af788b6
e990ba3
af788b6
 
 
 
 
 
 
e990ba3
 
 
af788b6
 
e990ba3
af788b6
e990ba3
1aea493
d57e12f
1aea493
af788b6
e990ba3
af788b6
e990ba3
af788b6
e990ba3
af788b6
 
 
 
d57e12f
1aea493
e990ba3
 
 
af788b6
 
 
 
 
 
 
 
e990ba3
af788b6
e990ba3
af788b6
e990ba3
af788b6
 
e990ba3
af788b6
1aea493
af788b6
 
e990ba3
af788b6
d57e12f
1aea493
af788b6
 
e990ba3
af788b6
d57e12f
1aea493
 
e990ba3
af788b6
e990ba3
1aea493
 
d57e12f
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
import gradio as gr
import json
import PyPDF2
import docx


# ----------------------------
# Resume Text Extraction
# ----------------------------

def extract_text(file):

    if file is None:
        return ""

    filename = file.name
    text = ""

    if filename.endswith(".pdf"):
        reader = PyPDF2.PdfReader(file)
        for page in reader.pages:
            text += page.extract_text() or ""

    elif filename.endswith(".docx"):
        document = docx.Document(file)
        for para in document.paragraphs:
            text += para.text + "\n"

    elif filename.endswith(".txt"):
        text = file.read().decode("utf-8")

    return text


# ----------------------------
# Resume Analyzer
# ----------------------------

def analyze_resume(resume_text):

    if not resume_text.strip():
        return {
            "score": 0,
            "technical_skills": [],
            "soft_skills": [],
            "recommendation": "No text detected in resume"
        }

    text = resume_text.lower()

    tech_keywords = [
        "python","java","c++","sql","machine learning",
        "data analysis","tensorflow","pandas","numpy",
        "git","linux","ai"
    ]

    soft_keywords = [
        "communication","teamwork","leadership",
        "problem solving","adaptability"
    ]

    tech_found = [k for k in tech_keywords if k in text]
    soft_found = [k for k in soft_keywords if k in text]

    score = min(100, len(tech_found)*8 + len(soft_found)*5)

    recommendation = (
        "Add more technical skills and measurable achievements."
        if score < 50 else
        "Good resume. Minor improvements recommended."
    )

    return {
        "score": score,
        "technical_skills": tech_found,
        "soft_skills": soft_found,
        "recommendation": recommendation
    }


# ----------------------------
# Format analysis for UI
# ----------------------------

def format_analysis(result):

    return f"""
## Resume Score: {result['score']}/100

### Technical Skills Found
{', '.join(result['technical_skills']) if result['technical_skills'] else "None"}

### Soft Skills Found
{', '.join(result['soft_skills']) if result['soft_skills'] else "None"}

### Recommendation
{result['recommendation']}
"""


# ----------------------------
# Export Functions
# ----------------------------

def export_json(data):

    file_path = "analysis.json"

    with open(file_path,"w") as f:
        json.dump(data,f,indent=4)

    return file_path


def export_text(data):

    file_path = "analysis.txt"

    with open(file_path,"w") as f:
        f.write(str(data))

    return file_path


# ----------------------------
# Processing Pipeline
# ----------------------------

def process_resume(file):

    text = extract_text(file)

    analysis = analyze_resume(text)

    formatted = format_analysis(analysis)

    return text, formatted, analysis


# ----------------------------
# UI
# ----------------------------

with gr.Blocks(title="Resume Analyzer") as demo:

    gr.Markdown("# AI Resume Analyzer")
    gr.Markdown("Upload your resume and get instant feedback.")

    resume_file = gr.File(label="Upload Resume (PDF / DOCX / TXT)")

    analyze_btn = gr.Button("Analyze Resume")

    resume_text = gr.Textbox(
        label="Extracted Resume Text",
        lines=10
    )

    analysis_output = gr.Markdown(label="Analysis Result")

    analysis_state = gr.State()

    with gr.Row():

        export_json_btn = gr.Button("Export JSON")
        export_text_btn = gr.Button("Export Text")

    download_file = gr.File(label="Download Analysis")

    # ----------------------------
    # Button Actions
    # ----------------------------

    analyze_btn.click(
        process_resume,
        inputs=resume_file,
        outputs=[resume_text, analysis_output, analysis_state]
    )

    export_json_btn.click(
        export_json,
        inputs=analysis_state,
        outputs=download_file
    )

    export_text_btn.click(
        export_text,
        inputs=analysis_state,
        outputs=download_file
    )


# ----------------------------
# Launch
# ----------------------------

if __name__ == "__main__":
    demo.launch()