devmalik-official commited on
Commit
af788b6
·
verified ·
1 Parent(s): ff116fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +135 -58
app.py CHANGED
@@ -1,100 +1,177 @@
1
  import gradio as gr
2
- import pdfplumber
 
 
3
  import docx
4
 
5
- # -------- Resume Text Extraction -------- #
 
 
 
6
 
7
  def extract_text(file):
 
8
  if file is None:
9
- return "Please upload a resume."
10
 
11
  file_name = file.name
12
 
13
- try:
14
- # PDF
15
- if file_name.endswith(".pdf"):
16
- text = ""
17
- with pdfplumber.open(file) as pdf:
18
- for page in pdf.pages:
19
- page_text = page.extract_text()
20
- if page_text:
21
- text += page_text
 
 
 
 
 
22
 
23
- # DOCX
24
- elif file_name.endswith(".docx"):
25
- doc = docx.Document(file)
26
- text = "\n".join([p.text for p in doc.paragraphs])
27
 
28
- else:
29
- return "Unsupported file format. Upload PDF or DOCX."
30
 
31
- return analyze_resume(text)
 
 
32
 
33
- except Exception as e:
34
- return f"Error reading file: {str(e)}"
35
 
 
 
 
 
 
36
 
37
- # -------- Resume Analyzer -------- #
38
 
39
- def analyze_resume(text):
 
 
 
 
40
 
41
- skills = [
42
- "python","machine learning","deep learning","data science",
43
- "sql","pandas","numpy","tensorflow","pytorch",
44
- "nlp","git","docker","flask","fastapi"
45
  ]
46
 
47
- found_skills = []
 
 
 
48
 
49
- for skill in skills:
50
- if skill.lower() in text.lower():
51
- found_skills.append(skill)
 
 
 
52
 
53
- score = min(len(found_skills) * 10, 100)
54
 
55
- result = f"""
56
- Resume Score: {score}/100
57
 
58
- Detected Skills:
59
- {', '.join(found_skills) if found_skills else 'No major skills detected'}
 
60
 
61
- Suggestions:
62
- • Add more technical skills
63
- • Include projects
64
- • Mention measurable achievements
65
- • Use clear headings
66
- """
67
 
68
- return result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
 
70
 
71
- # -------- Gradio UI -------- #
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
  with gr.Blocks(title="Resume Analyzer") as demo:
74
 
75
- gr.Markdown("# 📄 AI Resume Analyzer")
76
- gr.Markdown("Upload your resume and get instant feedback.")
 
 
77
 
78
- resume_input = gr.File(
79
- label="Upload Resume",
80
- file_types=[".pdf", ".docx"]
 
 
 
 
81
  )
82
 
83
- analyze_btn = gr.Button("Analyze Resume")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
- output_box = gr.Textbox(
86
- label="Analysis Result",
87
- lines=15
 
88
  )
89
 
90
- analyze_btn.click(
91
- fn=extract_text,
92
- inputs=resume_input,
93
- outputs=output_box
94
  )
95
 
96
 
97
- # -------- Launch App -------- #
 
 
98
 
99
  if __name__ == "__main__":
100
  demo.launch()
 
1
  import gradio as gr
2
+ import json
3
+ import os
4
+ import PyPDF2
5
  import docx
6
 
7
+
8
+ # -----------------------------
9
+ # Resume Parsing
10
+ # -----------------------------
11
 
12
  def extract_text(file):
13
+
14
  if file is None:
15
+ return ""
16
 
17
  file_name = file.name
18
 
19
+ if file_name.endswith(".pdf"):
20
+ reader = PyPDF2.PdfReader(file)
21
+ text = ""
22
+ for page in reader.pages:
23
+ text += page.extract_text() or ""
24
+ return text
25
+
26
+ elif file_name.endswith(".docx"):
27
+ doc = docx.Document(file)
28
+ text = "\n".join([p.text for p in doc.paragraphs])
29
+ return text
30
+
31
+ elif file_name.endswith(".txt"):
32
+ return file.read().decode("utf-8")
33
 
34
+ return ""
 
 
 
35
 
 
 
36
 
37
+ # -----------------------------
38
+ # Simple Resume Analyzer
39
+ # -----------------------------
40
 
41
+ def analyze_resume(resume_text):
 
42
 
43
+ if not resume_text or len(resume_text.strip()) == 0:
44
+ return {
45
+ "score": 0,
46
+ "message": "No resume text detected"
47
+ }
48
 
49
+ text = resume_text.lower()
50
 
51
+ technical_keywords = [
52
+ "python","java","c++","machine learning","ai",
53
+ "data","sql","tensorflow","pytorch","pandas",
54
+ "numpy","git","linux"
55
+ ]
56
 
57
+ soft_keywords = [
58
+ "teamwork","communication","leadership",
59
+ "problem solving","adaptability"
 
60
  ]
61
 
62
+ tech_found = [k for k in technical_keywords if k in text]
63
+ soft_found = [k for k in soft_keywords if k in text]
64
+
65
+ score = min(100, (len(tech_found)*8 + len(soft_found)*5))
66
 
67
+ result = {
68
+ "score": score,
69
+ "technical_skills": tech_found,
70
+ "soft_skills": soft_found,
71
+ "recommendation": "Add more quantified achievements and skills." if score < 50 else "Good resume. Minor improvements recommended."
72
+ }
73
 
74
+ return result
75
 
 
 
76
 
77
+ # -----------------------------
78
+ # Export Functions
79
+ # -----------------------------
80
 
81
+ def export_json(data):
 
 
 
 
 
82
 
83
+ if data is None:
84
+ return None
85
+
86
+ file_path = "analysis.json"
87
+
88
+ with open(file_path,"w") as f:
89
+ json.dump(data,f,indent=4)
90
+
91
+ return file_path
92
+
93
+
94
+ def export_text(data):
95
+
96
+ if data is None:
97
+ return None
98
+
99
+ file_path = "analysis.txt"
100
+
101
+ with open(file_path,"w") as f:
102
+ f.write(str(data))
103
 
104
+ return file_path
105
 
106
+
107
+ # -----------------------------
108
+ # Processing Pipeline
109
+ # -----------------------------
110
+
111
+ def process_resume(file):
112
+
113
+ text = extract_text(file)
114
+
115
+ analysis = analyze_resume(text)
116
+
117
+ return text, analysis
118
+
119
+
120
+ # -----------------------------
121
+ # UI
122
+ # -----------------------------
123
 
124
  with gr.Blocks(title="Resume Analyzer") as demo:
125
 
126
+ gr.Markdown("# AI Resume Analyzer")
127
+ gr.Markdown("Upload your resume and get an instant score.")
128
+
129
+ with gr.Row():
130
 
131
+ resume_file = gr.File(label="Upload Resume (PDF, DOCX, TXT)")
132
+
133
+ load_btn = gr.Button("Analyze Resume")
134
+
135
+ resume_text = gr.Textbox(
136
+ label="Extracted Resume Text",
137
+ lines=10
138
  )
139
 
140
+ analysis_output = gr.JSON(label="Analysis Result")
141
+
142
+ with gr.Row():
143
+
144
+ export_json_btn = gr.Button("Export JSON")
145
+ export_text_btn = gr.Button("Export Text")
146
+
147
+ download_file = gr.File(label="Download Analysis")
148
+
149
+ # -----------------------------
150
+ # Button Actions
151
+ # -----------------------------
152
+
153
+ load_btn.click(
154
+ process_resume,
155
+ inputs=resume_file,
156
+ outputs=[resume_text, analysis_output]
157
+ )
158
 
159
+ export_json_btn.click(
160
+ export_json,
161
+ inputs=analysis_output,
162
+ outputs=download_file
163
  )
164
 
165
+ export_text_btn.click(
166
+ export_text,
167
+ inputs=analysis_output,
168
+ outputs=download_file
169
  )
170
 
171
 
172
+ # -----------------------------
173
+ # Launch
174
+ # -----------------------------
175
 
176
  if __name__ == "__main__":
177
  demo.launch()