MuhammadQASIM111 commited on
Commit
8e26cc1
·
verified ·
1 Parent(s): af8b072

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -85
app.py CHANGED
@@ -1,8 +1,6 @@
1
- # Warning control
2
  import warnings
3
  warnings.filterwarnings('ignore')
4
 
5
-
6
  import fitz # PyMuPDF for PDF processing
7
  import docx # python-docx for DOCX processing
8
  import gradio as gr
@@ -10,28 +8,29 @@ import os
10
  from crewai import Agent, Task, Crew
11
  from crewai_tools import SerperDevTool
12
 
 
 
 
13
 
14
- os.environ['OPENAI_API_KEY'] = os.getenv("openaikey")
15
- os.environ["OPENAI_MODEL_NAME"] = 'gpt-4o-mini'
16
- os.environ["SERPER_API_KEY"] = os.getenv("serper_key")
17
-
18
 
 
 
 
19
 
20
  def extract_text_from_pdf(file_path):
21
  """Extracts text from a PDF file using PyMuPDF."""
22
  doc = fitz.open(file_path)
23
- text = ""
24
- for page in doc:
25
- text += page.get_text()
26
  return text
27
 
28
  def extract_text_from_docx(file_path):
29
  """Extracts text from a DOCX file using python-docx."""
30
  doc = docx.Document(file_path)
31
- fullText = []
32
- for para in doc.paragraphs:
33
- fullText.append(para.text)
34
- return "\n".join(fullText)
35
 
36
  def extract_text_from_resume(file_path):
37
  """Determines file type and extracts text."""
@@ -42,101 +41,70 @@ def extract_text_from_resume(file_path):
42
  else:
43
  return "Unsupported file format."
44
 
45
-
46
-
47
- # Agent 1: Resume Strategist
48
  resume_feedback = Agent(
49
  role="Professional Resume Advisor",
50
- goal="Give feedback on the resume to make it stand out in the job market.",
51
  verbose=True,
52
- 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."
53
- )
54
-
55
 
56
- # Task for Resume Strategist Agent: Align Resume with Job Requirements
57
  resume_feedback_task = Task(
58
- description=(
59
- """Give feedback on the resume to make it stand out for recruiters.
60
- Review every section, inlcuding the summary, work experience, skills, and education. Suggest to add relevant sections if they are missing.
61
- Also give an overall score to the resume out of 10. This is the resume: {resume}"""
62
- ),
63
- expected_output="The overall score of the resume followed by the feedback in bullet points.",
64
  agent=resume_feedback
65
  )
66
 
67
- # Agent 2: Resume Strategist
68
  resume_advisor = Agent(
69
  role="Professional Resume Writer",
70
- goal="Based on the feedback recieved from Resume Advisor, make changes to the resume to make it stand out in the job market.",
71
- verbose=True,
72
- 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."
73
  )
74
 
75
- # Task for Resume Strategist Agent: Align Resume with Job Requirements
76
  resume_advisor_task = Task(
77
- description=(
78
- """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.
79
- Review and update every section, including the summary, work experience, skills, and education to better reflect the candidates abilities. This is the resume: {resume}"""
80
- ),
81
- expected_output= "Resume in markdown format that effectively highlights the candidate's qualifications and experiences",
82
- # output_file="improved_resume.md",
83
  context=[resume_feedback_task],
84
  agent=resume_advisor
85
  )
86
 
87
  search_tool = SerperDevTool()
88
 
89
-
90
- # Agent 3: Researcher
91
  job_researcher = Agent(
92
- role = "Senior Recruitment Consultant",
93
- goal = "Find the 5 most relevant, recently posted jobs based on the improved resume recieved from resume advisor and the location preference",
94
- tools = [search_tool],
95
- verbose = True,
96
- backstory = """As a senior recruitment consultant your prowess in finding the most relevant jobs based on the resume and location preference is unmatched.
97
- 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 preffered location."""
98
- )
99
 
100
  research_task = Task(
101
- description = """Find the 5 most relevant recent job postings based on the resume recieved from resume advisor and location preference. This is the preferred location: {location} .
102
- Use the tools to gather relevant content and shortlist the 5 most relevant, recent, job openings""",
103
- expected_output=(
104
- "A bullet point list of the 5 job openings, with the appropriate links and detailed description about each job, in markdown format"
105
- ),
106
- # output_file="relevant_jobs.md",
107
  agent=job_researcher
108
  )
109
 
110
-
111
  crew = Crew(
112
  agents=[resume_feedback, resume_advisor, job_researcher],
113
  tasks=[resume_feedback_task, resume_advisor_task, research_task],
114
  verbose=True
115
  )
116
 
117
-
118
-
119
  def resume_agent(file_path, location):
120
  resume_text = extract_text_from_resume(file_path)
121
-
122
  result = crew.kickoff(inputs={"resume": resume_text, "location": location})
123
-
124
- # Extract outputs
125
- feedback = resume_feedback_task.output.raw.strip("```markdown").strip("```").strip()
126
- improved_resume = resume_advisor_task.output.raw.strip("```markdown").strip("```").strip()
127
- job_roles = research_task.output.raw.strip("```markdown").strip("```").strip()
128
-
129
  return feedback, improved_resume, job_roles
130
-
131
 
132
- # Gradio Interface
133
  with gr.Blocks() as demo:
134
  gr.Markdown("# Resume Feedback and Job Matching Tool")
135
  gr.Markdown("*Expected Runtime: 1 Min*")
136
 
137
  with gr.Column():
138
  with gr.Row():
139
- resume_upload = gr.File(label="Upload Your Resume (PDF or DOCX)", height=120)
140
  location_input = gr.Textbox(label="Preferred Location", placeholder="e.g., San Francisco")
141
  submit_button = gr.Button("Submit")
142
 
@@ -144,17 +112,7 @@ with gr.Blocks() as demo:
144
  feedback_output = gr.Markdown(label="Resume Feedback")
145
  improved_resume_output = gr.Markdown(label="Improved Resume")
146
  job_roles_output = gr.Markdown(label="Relevant Job Roles")
147
-
148
- # Define the click event for the submit button
149
- def format_outputs(feedback, improved_resume, job_roles):
150
- # Add bold headings to each section
151
- feedback_with_heading = f"## Resume Feedback:**\n\n{feedback}"
152
- improved_resume_with_heading = f"## Improved Resume:\n\n{improved_resume}"
153
- job_roles_with_heading = f"## Relevant Job Roles:\n\n{job_roles}"
154
- return feedback_with_heading, improved_resume_with_heading, job_roles_with_heading
155
-
156
-
157
-
158
  submit_button.click(
159
  lambda: gr.update(value="Processing..."),
160
  inputs=[],
@@ -163,10 +121,6 @@ with gr.Blocks() as demo:
163
  resume_agent,
164
  inputs=[resume_upload, location_input],
165
  outputs=[feedback_output, improved_resume_output, job_roles_output]
166
- ).then(
167
- format_outputs,
168
- inputs=[feedback_output, improved_resume_output, job_roles_output],
169
- outputs=[feedback_output, improved_resume_output, job_roles_output]
170
  ).then(
171
  lambda: gr.update(value="Submit"),
172
  inputs=[],
@@ -174,7 +128,4 @@ with gr.Blocks() as demo:
174
  )
175
 
176
  demo.queue()
177
- demo.launch(share=True)
178
-
179
-
180
-
 
 
1
  import warnings
2
  warnings.filterwarnings('ignore')
3
 
 
4
  import fitz # PyMuPDF for PDF processing
5
  import docx # python-docx for DOCX processing
6
  import gradio as gr
 
8
  from crewai import Agent, Task, Crew
9
  from crewai_tools import SerperDevTool
10
 
11
+ # Ensure environment variables are set
12
+ openai_key = os.getenv("openaikey")
13
+ serper_key = os.getenv("serper_key")
14
 
15
+ if not openai_key:
16
+ raise ValueError("ERROR: OPENAI_API_KEY is missing. Set it in Hugging Face Spaces settings.")
17
+ if not serper_key:
18
+ raise ValueError("ERROR: SERPER_API_KEY is missing. Set it in Hugging Face Spaces settings.")
19
 
20
+ os.environ['OPENAI_API_KEY'] = openai_key
21
+ os.environ["OPENAI_MODEL_NAME"] = 'gpt-4o-mini'
22
+ os.environ["SERPER_API_KEY"] = serper_key
23
 
24
  def extract_text_from_pdf(file_path):
25
  """Extracts text from a PDF file using PyMuPDF."""
26
  doc = fitz.open(file_path)
27
+ text = "".join(page.get_text() for page in doc)
 
 
28
  return text
29
 
30
  def extract_text_from_docx(file_path):
31
  """Extracts text from a DOCX file using python-docx."""
32
  doc = docx.Document(file_path)
33
+ return "\n".join(para.text for para in doc.paragraphs)
 
 
 
34
 
35
  def extract_text_from_resume(file_path):
36
  """Determines file type and extracts text."""
 
41
  else:
42
  return "Unsupported file format."
43
 
 
 
 
44
  resume_feedback = Agent(
45
  role="Professional Resume Advisor",
46
+ goal="Give feedback on resumes.",
47
  verbose=True,
48
+ backstory="Experienced in making resumes stand out."
49
+ )
 
50
 
 
51
  resume_feedback_task = Task(
52
+ description="Provide detailed feedback on resumes.",
53
+ expected_output="Resume feedback with an overall score.",
 
 
 
 
54
  agent=resume_feedback
55
  )
56
 
 
57
  resume_advisor = Agent(
58
  role="Professional Resume Writer",
59
+ goal="Enhance resumes based on feedback.",
60
+ verbose=True
 
61
  )
62
 
 
63
  resume_advisor_task = Task(
64
+ description="Rewrite the resume based on feedback.",
65
+ expected_output="Enhanced resume in markdown format.",
 
 
 
 
66
  context=[resume_feedback_task],
67
  agent=resume_advisor
68
  )
69
 
70
  search_tool = SerperDevTool()
71
 
 
 
72
  job_researcher = Agent(
73
+ role="Senior Recruitment Consultant",
74
+ goal="Find relevant job postings.",
75
+ tools=[search_tool],
76
+ verbose=True
77
+ )
 
 
78
 
79
  research_task = Task(
80
+ description="Find 5 relevant jobs based on the resume.",
81
+ expected_output="List of 5 job openings with links.",
 
 
 
 
82
  agent=job_researcher
83
  )
84
 
 
85
  crew = Crew(
86
  agents=[resume_feedback, resume_advisor, job_researcher],
87
  tasks=[resume_feedback_task, resume_advisor_task, research_task],
88
  verbose=True
89
  )
90
 
 
 
91
  def resume_agent(file_path, location):
92
  resume_text = extract_text_from_resume(file_path)
 
93
  result = crew.kickoff(inputs={"resume": resume_text, "location": location})
94
+
95
+ feedback = resume_feedback_task.output.raw.strip("```markdown").strip()
96
+ improved_resume = resume_advisor_task.output.raw.strip("```markdown").strip()
97
+ job_roles = research_task.output.raw.strip("```markdown").strip()
98
+
 
99
  return feedback, improved_resume, job_roles
 
100
 
 
101
  with gr.Blocks() as demo:
102
  gr.Markdown("# Resume Feedback and Job Matching Tool")
103
  gr.Markdown("*Expected Runtime: 1 Min*")
104
 
105
  with gr.Column():
106
  with gr.Row():
107
+ resume_upload = gr.File(label="Upload Resume (PDF or DOCX)", height=120)
108
  location_input = gr.Textbox(label="Preferred Location", placeholder="e.g., San Francisco")
109
  submit_button = gr.Button("Submit")
110
 
 
112
  feedback_output = gr.Markdown(label="Resume Feedback")
113
  improved_resume_output = gr.Markdown(label="Improved Resume")
114
  job_roles_output = gr.Markdown(label="Relevant Job Roles")
115
+
 
 
 
 
 
 
 
 
 
 
116
  submit_button.click(
117
  lambda: gr.update(value="Processing..."),
118
  inputs=[],
 
121
  resume_agent,
122
  inputs=[resume_upload, location_input],
123
  outputs=[feedback_output, improved_resume_output, job_roles_output]
 
 
 
 
124
  ).then(
125
  lambda: gr.update(value="Submit"),
126
  inputs=[],
 
128
  )
129
 
130
  demo.queue()
131
+ demo.launch(share=True)