zarashahid commited on
Commit
8019603
·
verified ·
1 Parent(s): f270530

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -0
app.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import fitz # PyMuPDF for PDF reading
3
+ from sentence_transformers import SentenceTransformer, util
4
+
5
+ # Load sentence transformer model
6
+ model = SentenceTransformer("all-MiniLM-L6-v2")
7
+
8
+ # Sample top skills to match in resume
9
+ top_skills = [
10
+ "Python", "Java", "C++", "SQL", "JavaScript", "React", "Node.js",
11
+ "Machine Learning", "Data Analysis", "Excel", "Communication",
12
+ "Project Management", "AWS", "Docker", "Leadership", "Time Management",
13
+ "Problem Solving", "Teamwork", "Critical Thinking"
14
+ ]
15
+
16
+ def extract_text_from_pdf(pdf_file):
17
+ doc = fitz.open(pdf_file)
18
+ text = ""
19
+ for page in doc:
20
+ text += page.get_text()
21
+ return text
22
+
23
+ def analyze_resume(text):
24
+ # Split into sentences
25
+ sentences = [s.strip() for s in text.split(".") if len(s.strip()) > 5]
26
+ if not sentences:
27
+ return "Could not extract sentences.", "", "", ""
28
+
29
+ # Encode sentences and skills
30
+ sentence_embeddings = model.encode(sentences, convert_to_tensor=True)
31
+ skill_embeddings = model.encode(top_skills, convert_to_tensor=True)
32
+
33
+ # Compare each skill to each sentence
34
+ cosine_scores = util.cos_sim(skill_embeddings, sentence_embeddings)
35
+
36
+ found_skills = []
37
+ for idx, skill in enumerate(top_skills):
38
+ score = max(cosine_scores[idx]) # Best score across all sentences
39
+ if score > 0.4:
40
+ found_skills.append(skill)
41
+
42
+ # Match to job titles (basic logic)
43
+ job_titles = []
44
+ if "Python" in found_skills and "Data Analysis" in found_skills:
45
+ job_titles.append("Data Analyst")
46
+ if "JavaScript" in found_skills and "React" in found_skills:
47
+ job_titles.append("Frontend Developer")
48
+ if "Project Management" in found_skills:
49
+ job_titles.append("Project Manager")
50
+ if "Machine Learning" in found_skills:
51
+ job_titles.append("ML Engineer")
52
+ if not job_titles:
53
+ job_titles.append("General Tech Roles")
54
+
55
+ missing_skills = [s for s in top_skills if s not in found_skills]
56
+
57
+ return ", ".join(found_skills), ", ".join(job_titles), ", ".join(missing_skills[:5])
58
+
59
+ def process_resume(file_obj):
60
+ filename = file_obj.name
61
+ ext = filename.split(".")[-1].lower()
62
+
63
+ if ext == "pdf":
64
+ resume_text = extract_text_from_pdf(filename)
65
+ elif ext == "txt":
66
+ resume_text = file_obj.read().decode("utf-8")
67
+ else:
68
+ return "Unsupported file format", "", "", ""
69
+
70
+ extracted, jobs, suggestions = analyze_resume(resume_text)
71
+ return resume_text, extracted, jobs, suggestions
72
+
73
+ # Gradio UI
74
+ demo = gr.Interface(
75
+ fn=process_resume,
76
+ inputs=gr.File(label="Upload your resume (.pdf or .txt)"),
77
+ outputs=[
78
+ gr.Textbox(label="Resume Text", lines=10),
79
+ gr.Textbox(label="Detected Skills"),
80
+ gr.Textbox(label="Suggested Job Titles"),
81
+ gr.Textbox(label="Recommended Skills to Learn")
82
+ ],
83
+ title="Resume Analyzer & Job Matcher",
84
+ description="Upload a PDF or text resume to get job suggestions and skill feedback using AI."
85
+ )
86
+
87
+ if __name__ == "__main__":
88
+ demo.launch()