krishbakshi commited on
Commit
a645179
·
verified ·
1 Parent(s): 5c65e46

Create utils.py

Browse files
Files changed (1) hide show
  1. utils.py +137 -0
utils.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ import fitz # PyMuPDF for PDF parsing
4
+ import docx
5
+
6
+ from google import genai
7
+ from google.genai import types
8
+
9
+ # API key as envirnomental varibale
10
+ api_key = os.environ.get("GOOGLE_API_KEY")
11
+
12
+
13
+ # Function to extract text from PDFs
14
+ def extract_text_from_pdf(file_path):
15
+ text = ""
16
+ with fitz.open(file_path) as doc:
17
+ for page in doc:
18
+ text += page.get_text()
19
+ return text
20
+
21
+
22
+ # Function to extract text from DOCX files
23
+ def extract_text_from_docx(file_path):
24
+ doc = docx.Document(file_path)
25
+ return "\n".join([para.text for para in doc.paragraphs])
26
+
27
+
28
+ def process_resume(file_path):
29
+ if file_path.endswith(".pdf"):
30
+ resume_text = extract_text_from_pdf(file_path)
31
+ elif file_path.endswith(".docx"):
32
+ resume_text = extract_text_from_docx(file_path)
33
+ else:
34
+ print(f"Skipping unsupported file: {file_path}")
35
+ return None
36
+
37
+ # Extract structured resume data
38
+ structured_data = extract_resume_data(resume_text)
39
+ return structured_data
40
+
41
+
42
+ # Function to parse resume and extract structured data using Gemini
43
+ def extract_resume_data(resume_text):
44
+ prompt = f"""
45
+ Extract the following details from the resume:
46
+ - Full Name(first word capital, eg: "Krish Bakshi", "Uzumaki Naruto")
47
+ - Email
48
+ - Phone Number
49
+ - Work Experience (Company, Role, Contribution and work)
50
+ - Projects(Project, Tech Stack/Tehnology)
51
+ - Education (Degree, University, Year) /(Only first word capital)/
52
+ - Skills
53
+ Provide the data in a structured JSON format.
54
+
55
+ Resume:
56
+ {resume_text}
57
+ """
58
+
59
+ client = genai.Client(api_key=api_key)
60
+ response = client.models.generate_content(
61
+ model="gemini-2.0-flash",
62
+ contents=prompt,
63
+ )
64
+ return response.text # Gemini will return structured JSON
65
+
66
+
67
+ # Define the system instruction
68
+ sys_instruct_gen = """
69
+ You are an AI assistant tasked with drafting a professional and personalized email to a hiring manager
70
+ expressing interest in a job opportunity at their company.
71
+ You need to adjust accordingly with grammar and spot possible areas where the info in the resume and that of the hiring manager/recruiter are relavent.
72
+ Make the email such that it piques the interest of the hiring manger, such as a certain skill set they need or can be of great value to them.
73
+ The email should adhere to the following template and should generate in 260 - 280 words consistently, with placeholders to be filled accordingly:
74
+
75
+ Subject: Seeking Opportunities to Contribute at {Company Name}
76
+
77
+ Dear {Hiring Manager's Name},
78
+
79
+ I hope this email finds you well. My name is [Extract Full Name from Resume], and I am writing to express my keen interest in exploring career opportunities at {Company Name}. Your organization's work in {Industry/Field} has greatly impressed me, particularly your contributions to {Specific Projects, Innovations, or Company Achievements}.
80
+
81
+ With a background in [Extract Academic Background: degree, university, and GPA], I have developed strong skills in [Extract Relevant Technical Skills] and gained hands-on experience through projects such as [Extract Relevant Projects from Resume]. My expertise in {Specific Skills or Tools Relevant to the Job} aligns well with the work being done at your company, and I am eager to bring my knowledge and passion to your team.
82
+
83
+ Additionally, my certification in Practical AI with Python showcases my commitment to continuous learning in AI and data-driven solutions. Furthermore, my proficiency in Japanese, certified by the JLPT N3, allows me to collaborate effectively in diverse and international work environments.
84
+
85
+ I am particularly interested in {Specific Roles, Teams, or Projects at the Company} and believe that my skills in {Extract Skills from Resume} would allow me to contribute meaningfully to your organization's goals. I have attached my resume for your review and would welcome the opportunity to discuss how my experience and expertise align with your company’s needs.
86
+
87
+ Thank you for your time and consideration. I look forward to the possibility of joining {Company Name} and contributing to its continued success.
88
+
89
+ Best regards,
90
+ [Extract Full Name from Resume]
91
+
92
+ Resume:
93
+ {}
94
+
95
+ """
96
+
97
+ sys_instruct_jap = """
98
+ You are an AI assistant tasked with drafting a professional and personalized email to a hiring manager
99
+ expressing interest in a job opportunity at their company.
100
+ You need to adjust accordingly with grammar and spot possible areas where the info in the resume and that of the hiring manager/recruiter are relavent.
101
+ Make the email such that it piques the interest of the hiring manger, such as a certain skill set they need or can be of great value to them.
102
+ Always include japanese language point present in the template.
103
+ The email should adhere to the following template and should generate in 240 - 260 words consistently, with placeholders to be filled accordingly:
104
+
105
+ Subject: Seeking Opportunities to Contribute at {Company Name}
106
+
107
+ Dear {Hiring Manager's Name},
108
+
109
+ I hope this email finds you well. My name is [Extract Full Name from Resume], and I am writing to express my keen interest in exploring career opportunities at {Company Name}. Your organization's work in {Industry/Field} has greatly impressed me, particularly your contributions to {Specific Projects, Innovations, or Company Achievements}.
110
+
111
+ With a background in [Extract Academic Background: degree, university, and GPA], I have developed strong skills in [Extract Relevant Technical Skills] and gained hands-on experience through projects such as [Extract Relevant Projects from Resume].
112
+
113
+ My expertise in {Specific Skills or Tools Relevant to the Job} aligns well with the work being done at your company, and I am eager to bring my knowledge and passion to your team.
114
+
115
+ Furthermore, my proficiency in Japanese, certified by the JLPT N3, allows me to collaborate effectively in diverse and international work environments.
116
+
117
+ I am particularly interested in {Specific Roles, Teams, or Projects at the Company} and believe that my skills in {Extract Skills from Resume} would allow me to contribute meaningfully to your organization's goals. I have attached my resume for your review and would welcome the opportunity to discuss how my experience and expertise align with your company’s needs.
118
+
119
+ Thank you for your time and consideration. I look forward to the possibility of joining {Company Name} and contributing to its continued success.
120
+
121
+ Best regards,
122
+ [Extract Full Name from Resume]
123
+
124
+ Resume:
125
+ {}
126
+
127
+ """
128
+
129
+ # Response Pipeline
130
+ def generate_email(prompt):
131
+ client = genai.Client(api_key=api_key)
132
+ response = client.models.generate_content(
133
+ model="gemini-2.0-flash",
134
+ config=types.GenerateContentConfig(system_instruction=sys_instruct_jap),
135
+ contents=[prompt],
136
+ )
137
+ return response.text