gkippili commited on
Commit
414621d
·
verified ·
1 Parent(s): 0c4eee1

Create Resume_analyser_agent_tools.py

Browse files
Files changed (1) hide show
  1. Resume_analyser_agent_tools.py +218 -218
Resume_analyser_agent_tools.py CHANGED
@@ -1,219 +1,219 @@
1
- # Warning control
2
- import warnings
3
- warnings.filterwarnings('ignore')
4
-
5
- #!pip install PyMuPDF
6
- #!pip install python-docx
7
- #!pip install crewai crewai-tools
8
-
9
- import fitz # PyMuPDF for PDF processing
10
- import docx # python-docx for DOCX processing
11
- from crewai_tools import SerperDevTool
12
- import os
13
- from crewai import Agent, Task, Crew
14
- from dotenv import load_dotenv
15
- import tempfile
16
-
17
- # Load environment variables
18
- load_dotenv()
19
-
20
- # Streamlit must be imported after setting page config
21
- import streamlit as st
22
-
23
- # Set page configuration FIRST
24
- st.set_page_config(page_title="Smart Resume Analyzer", layout="wide")
25
-
26
- # Custom CSS for background color
27
- st.markdown(
28
- f"""
29
- <style>
30
- .stApp {{
31
- background-color: #50a7c7;
32
- }}
33
- .title-text {{
34
- font-size: 1000px; /* Increased font size */
35
- font-weight: bold;
36
- color: white;
37
- text-align: center;
38
- margin-bottom: 20px;
39
- }}
40
- .subtitle-text {{
41
- font-style: italic;
42
- color: white;
43
- text-align: center;
44
- margin-bottom: 30px;
45
- }}
46
- .upload-box {{
47
- border: 2px dashed #ffffff;
48
- padding: 20px;
49
- text-align: center;
50
- background-color: rgba(255, 255, 255, 0.2);
51
- border-radius: 10px;
52
- margin: 0 auto;
53
- width: 50%; /* Reduced width of the upload box */
54
- }}
55
- .stTextInput input {{
56
- max-width: 300px; /* Reduced width of the text input */
57
- }}
58
- </style>
59
- """,
60
- unsafe_allow_html=True
61
- )
62
-
63
- # Title and description
64
- st.markdown('<p class="title-text">Smart Resume Analyzer & Job Matcher</p>', unsafe_allow_html=True)
65
- st.markdown('<p class="subtitle-text">Expected Runtime: 1 Min</p>', unsafe_allow_html=True)
66
-
67
- # Resume upload section
68
- st.markdown("### Upload Your Resume (PDF or DOCX)")
69
- uploaded_file = st.file_uploader("Drop File Here or Click to Upload", type=["pdf", "docx"], help="Upload your resume for analysis.",key="resume_upload")
70
-
71
- # Preferred location input
72
- preferred_location = st.text_input("Preferred Location", placeholder="e.g., San Francisco",max_chars=50, key="location_input")
73
-
74
-
75
-
76
-
77
- # Submit button
78
- submit_button = st.button("Submit",icon="😃")
79
-
80
- # Function to extract text from PDF
81
- def extract_text_from_pdf(file_path):
82
- """Extracts text from a PDF file using PyMuPDF."""
83
- doc = fitz.open(file_path)
84
- text = ""
85
- for page in doc:
86
- text += page.get_text()
87
- return text
88
-
89
- # Function to extract text from DOCX
90
- def extract_text_from_docx(file_path):
91
- """Extracts text from a DOCX file using python-docx."""
92
- doc = docx.Document(file_path)
93
- fullText = []
94
- for para in doc.paragraphs:
95
- fullText.append(para.text)
96
- return "\n".join(fullText)
97
-
98
- # Function to extract text from resume
99
- def extract_text_from_resume(file_path):
100
- """Determines file type and extracts text."""
101
- if file_path.endswith(".pdf"):
102
- return extract_text_from_pdf(file_path)
103
- elif file_path.endswith(".docx"):
104
- return extract_text_from_docx(file_path)
105
- else:
106
- return "Unsupported file format."
107
-
108
- # Initialize agents and tasks
109
- def initialize_crew():
110
- search_tool = SerperDevTool()
111
-
112
- # Agent 1: Resume Advisor
113
- resume_advisor = Agent(
114
- role="Professional Resume Advisor",
115
- goal="Give feedback on the resume to make it stand out in the job market.",
116
- verbose=True,
117
- backstory="With a strategic mind and an eye for detail, you excel at providing feedback on resumes to highlight the most relevant skills and experiences."
118
- )
119
-
120
- # Agent 2: Resume Writer
121
- resume_writer = Agent(
122
- role="Professional Resume Writer",
123
- goal="Based on the feedback received from Resume Advisor, make changes to the resume to make it stand out in the job market.",
124
- verbose=True,
125
- backstory="With a strategic mind and an eye for detail, you excel at refining resumes based on the feedback to highlight the most relevant skills and experiences."
126
- )
127
-
128
- # Agent 3: Job Researcher
129
- job_researcher = Agent(
130
- role="Senior Recruitment Consultant",
131
- goal="Find the 5 most relevant, recently posted jobs based on the improved resume received from resume advisor and the location preference.",
132
- tools=[search_tool],
133
- verbose=True,
134
- backstory="""As a senior recruitment consultant, your prowess in finding the most relevant jobs based on the resume and location preference is unmatched.
135
- You can scan the resume efficiently, identify the most suitable job roles, and search for the best-suited recently posted open job positions at the preferred location."""
136
- )
137
-
138
- # Task for Resume Advisor Agent: Give Feedback
139
- resume_advisor_task = Task(
140
- description=(
141
- """Give feedback on the resume to make it stand out for recruiters.
142
- Review every section, including the summary, work experience, skills, and education. Suggest to add relevant sections if they are missing.
143
- Also, give an overall score to the resume out of 10. This is the resume: {resume}"""
144
- ),
145
- expected_output="The overall score of the resume followed by the feedback in bullet points.",
146
- agent=resume_advisor
147
- )
148
-
149
- # Task for Resume Writer Agent: Improve Resume
150
- resume_writer_task = Task(
151
- description=(
152
- """Rewrite the resume based on the feedback to make it stand out for recruiters. You can adjust and enhance the resume but don't make up facts.
153
- Review and update every section, including the summary, work experience, skills, and education to better reflect the candidate's abilities. This is the resume: {resume}"""
154
- ),
155
- expected_output="Resume in markdown format that effectively highlights the candidate's qualifications and experiences.",
156
- context=[resume_advisor_task],
157
- agent=resume_writer
158
- )
159
-
160
- # Task for Job Researcher Agent: Find Jobs
161
- research_task = Task(
162
- description="""Find the 5 most relevant recent job postings based on the resume received from resume advisor and location preference. This is the preferred location: {location}.
163
- Use the tools to gather relevant content and shortlist the 5 most relevant, recent, job openings.""",
164
- expected_output="A bullet point list of the 5 job openings, with the appropriate links and detailed description about each job, in markdown format.",
165
- agent=job_researcher
166
- )
167
-
168
- # Create Crew
169
- crew = Crew(
170
- name="Resume Analysis Crew",
171
- tasks=[resume_advisor_task, resume_writer_task, research_task],
172
- agents=[resume_advisor, resume_writer, job_researcher]
173
- )
174
-
175
- return crew,resume_advisor_task, resume_writer_task, research_task
176
-
177
-
178
- # Function to run the crew and get results
179
- def resume_agent(file_path, location):
180
- resume_text = extract_text_from_resume(file_path)
181
-
182
- crew, resume_advisor_task, resume_writer_task, research_task = initialize_crew()
183
- result = crew.kickoff(inputs={"resume": resume_text, "location": location})
184
-
185
- # Extract outputs
186
- feedback = resume_advisor_task.output.raw.strip("```markdown").strip("```").strip()
187
- improved_resume = resume_writer_task.output.raw.strip("```markdown").strip("```").strip()
188
- job_roles = research_task.output.raw.strip("```markdown").strip("```").strip()
189
-
190
- return feedback, improved_resume, job_roles
191
-
192
- # Handle file upload and processing
193
- if submit_button:
194
- if uploaded_file is None:
195
- st.error("Please upload a resume before submitting.")
196
- else:
197
- with st.spinner("Analyzing your resume and finding job matches..."):
198
- # Save uploaded file to a temporary location
199
- with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(uploaded_file.name)[1]) as tmp_file:
200
- tmp_file.write(uploaded_file.getvalue())
201
- tmp_file_path = tmp_file.name
202
-
203
- try:
204
- feedback, improved_resume, job_roles = resume_agent(tmp_file_path, preferred_location)
205
-
206
- st.success("Analysis complete!")
207
- st.markdown("## Resume Feedback:")
208
- st.markdown(feedback)
209
-
210
- st.markdown("## Improved Resume Suggestions:")
211
- st.markdown(improved_resume)
212
-
213
- st.markdown("## Relevant Job Roles:")
214
- st.markdown(job_roles)
215
- except Exception as e:
216
- st.error(f"An error occurred: {e}")
217
- finally:
218
- # Clean up temporary file
219
  os.unlink(tmp_file_path)
 
1
+ # Warning control
2
+ import warnings
3
+ warnings.filterwarnings('ignore')
4
+
5
+ #!pip install PyMuPDF
6
+ #!pip install python-docx
7
+ #!pip install crewai crewai-tools
8
+
9
+ import fitz # PyMuPDF for PDF processing
10
+ import docx # python-docx for DOCX processing
11
+ from crewai_tools import SerperDevTool
12
+ import os
13
+ from crewai import Agent, Task, Crew
14
+ from dotenv import load_dotenv
15
+ import tempfile
16
+
17
+ # Load environment variables
18
+ load_dotenv()
19
+
20
+ # Streamlit must be imported after setting page config
21
+ import streamlit as st
22
+
23
+ # Set page configuration FIRST
24
+ st.set_page_config(page_title="Smart Resume Analyzer", layout="wide")
25
+
26
+ # Custom CSS for background color
27
+ st.markdown(
28
+ f"""
29
+ <style>
30
+ .stApp {{
31
+ background-color: #50a7c7;
32
+ }}
33
+ .title-text {{
34
+ font-size: 1000px; /* Increased font size */
35
+ font-weight: bold;
36
+ color: white;
37
+ text-align: center;
38
+ margin-bottom: 20px;
39
+ }}
40
+ .subtitle-text {{
41
+ font-style: italic;
42
+ color: white;
43
+ text-align: center;
44
+ margin-bottom: 30px;
45
+ }}
46
+ .upload-box {{
47
+ border: 2px dashed #ffffff;
48
+ padding: 20px;
49
+ text-align: center;
50
+ background-color: rgba(255, 255, 255, 0.2);
51
+ border-radius: 10px;
52
+ margin: 0 auto;
53
+ width: 50%; /* Reduced width of the upload box */
54
+ }}
55
+ .stTextInput input {{
56
+ max-width: 300px; /* Reduced width of the text input */
57
+ }}
58
+ </style>
59
+ """,
60
+ unsafe_allow_html=True
61
+ )
62
+
63
+ # Title and description
64
+ st.markdown('<p class="title-text">Smart Resume Analyzer & Job Matcher</p>', unsafe_allow_html=True)
65
+ st.markdown('<p class="subtitle-text">Expected Runtime: 1 Min</p>', unsafe_allow_html=True)
66
+
67
+ # Resume upload section
68
+ st.markdown("### Upload Your Resume (PDF or DOCX)")
69
+ uploaded_file = st.file_uploader("Drop File Here or Click to Upload", type=["pdf", "docx"], help="Upload your resume for analysis.",key="resume_upload")
70
+
71
+ # Preferred location input
72
+ preferred_location = st.text_input("Preferred Location", placeholder="e.g., San Francisco",max_chars=50, key="location_input")
73
+
74
+
75
+
76
+
77
+ # Submit button
78
+ submit_button = st.button("Submit",icon="😃")
79
+
80
+ # Function to extract text from PDF
81
+ def extract_text_from_pdf(file_path):
82
+ """Extracts text from a PDF file using PyMuPDF."""
83
+ doc = fitz.open(file_path)
84
+ text = ""
85
+ for page in doc:
86
+ text += page.get_text()
87
+ return text
88
+
89
+ # Function to extract text from DOCX
90
+ def extract_text_from_docx(file_path):
91
+ """Extracts text from a DOCX file using python-docx."""
92
+ doc = docx.Document(file_path)
93
+ fullText = []
94
+ for para in doc.paragraphs:
95
+ fullText.append(para.text)
96
+ return "\n".join(fullText)
97
+
98
+ # Function to extract text from resume
99
+ def extract_text_from_resume(file_path):
100
+ """Determines file type and extracts text."""
101
+ if file_path.endswith(".pdf"):
102
+ return extract_text_from_pdf(file_path)
103
+ elif file_path.endswith(".docx"):
104
+ return extract_text_from_docx(file_path)
105
+ else:
106
+ return "Unsupported file format."
107
+
108
+ # Initialize agents and tasks
109
+ def initialize_crew():
110
+ search_tool = SerperDevTool()
111
+
112
+ # Agent 1: Resume Advisor
113
+ resume_advisor = Agent(
114
+ role="Professional Resume Advisor",
115
+ goal="Give feedback on the resume to make it stand out in the job market.",
116
+ verbose=True,
117
+ backstory="With a strategic mind and an eye for detail, you excel at providing feedback on resumes to highlight the most relevant skills and experiences."
118
+ )
119
+
120
+ # Agent 2: Resume Writer
121
+ resume_writer = Agent(
122
+ role="Professional Resume Writer",
123
+ goal="Based on the feedback received from Resume Advisor, make changes to the resume to make it stand out in the job market.",
124
+ verbose=True,
125
+ backstory="With a strategic mind and an eye for detail, you excel at refining resumes based on the feedback to highlight the most relevant skills and experiences."
126
+ )
127
+
128
+ # Agent 3: Job Researcher
129
+ job_researcher = Agent(
130
+ role="Senior Recruitment Consultant",
131
+ goal="Find the 5 most relevant, recently posted jobs based on the improved resume received from resume advisor and the location preference.",
132
+ tools=[search_tool],
133
+ verbose=True,
134
+ backstory="""As a senior recruitment consultant, your prowess in finding the most relevant jobs based on the resume and location preference is unmatched.
135
+ You can scan the resume efficiently, identify the most suitable job roles, and search for the best-suited recently posted open job positions at the preferred location."""
136
+ )
137
+
138
+ # Task for Resume Advisor Agent: Give Feedback
139
+ resume_advisor_task = Task(
140
+ description=(
141
+ """Give feedback on the resume to make it stand out for recruiters.
142
+ Review every section, including the summary, work experience, skills, and education. Suggest to add relevant sections if they are missing.
143
+ Also, give an overall score to the resume out of 10. This is the resume: {resume}"""
144
+ ),
145
+ expected_output="The overall score of the resume followed by the feedback in bullet points.",
146
+ agent=resume_advisor
147
+ )
148
+
149
+ # Task for Resume Writer Agent: Improve Resume
150
+ resume_writer_task = Task(
151
+ description=(
152
+ """Rewrite the resume based on the feedback to make it stand out for recruiters. You can adjust and enhance the resume but don't make up facts.
153
+ Review and update every section, including the summary, work experience, skills, and education to better reflect the candidate's abilities. This is the resume: {resume}"""
154
+ ),
155
+ expected_output="Resume in markdown format that effectively highlights the candidate's qualifications and experiences.",
156
+ context=[resume_advisor_task],
157
+ agent=resume_writer
158
+ )
159
+
160
+ # Task for Job Researcher Agent: Find Jobs
161
+ research_task = Task(
162
+ description="""Find the 5 most relevant recent job postings based on the resume received from resume advisor and location preference. This is the preferred location: {location}.
163
+ Use the tools to gather relevant content and shortlist the 5 most relevant, recent, job openings.""",
164
+ expected_output="A bullet point list of the 5 job openings, with the appropriate links and detailed description about each job, in markdown format.",
165
+ agent=job_researcher
166
+ )
167
+
168
+ # Create Crew
169
+ crew = Crew(
170
+ name="Resume Analysis Crew",
171
+ tasks=[resume_advisor_task, resume_writer_task, research_task],
172
+ agents=[resume_advisor, resume_writer, job_researcher]
173
+ )
174
+
175
+ return crew,resume_advisor_task, resume_writer_task, research_task
176
+
177
+
178
+ # Function to run the crew and get results
179
+ def resume_agent(file_path, location):
180
+ resume_text = extract_text_from_resume(file_path)
181
+
182
+ crew, resume_advisor_task, resume_writer_task, research_task = initialize_crew()
183
+ result = crew.kickoff(inputs={"resume": resume_text, "location": location})
184
+
185
+ # Extract outputs
186
+ feedback = resume_advisor_task.output.raw.strip("```markdown").strip("```").strip()
187
+ improved_resume = resume_writer_task.output.raw.strip("```markdown").strip("```").strip()
188
+ job_roles = research_task.output.raw.strip("```markdown").strip("```").strip()
189
+
190
+ return feedback, improved_resume, job_roles
191
+
192
+ # Handle file upload and processing
193
+ if submit_button:
194
+ if uploaded_file is None:
195
+ st.error("Please upload a resume before submitting.")
196
+ else:
197
+ with st.spinner("Analyzing your resume and finding job matches..."):
198
+ # Save uploaded file to a temporary location
199
+ with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(uploaded_file.name)[1]) as tmp_file:
200
+ tmp_file.write(uploaded_file.getvalue())
201
+ tmp_file_path = tmp_file.name
202
+
203
+ try:
204
+ feedback, improved_resume, job_roles = resume_agent(tmp_file_path, preferred_location)
205
+
206
+ st.success("Analysis complete!")
207
+ st.markdown("## Resume Feedback:")
208
+ st.markdown(feedback)
209
+
210
+ st.markdown("## Improved Resume Suggestions:")
211
+ st.markdown(improved_resume)
212
+
213
+ st.markdown("## Relevant Job Roles:")
214
+ st.markdown(job_roles)
215
+ except Exception as e:
216
+ st.error(f"An error occurred: {e}")
217
+ finally:
218
+ # Clean up temporary file
219
  os.unlink(tmp_file_path)