Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,24 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import gradio as gr
|
|
|
|
| 5 |
from crewai import Agent, Task, Crew
|
| 6 |
from crewai_tools import SerperDevTool
|
| 7 |
|
| 8 |
-
# Initialize tools
|
| 9 |
-
search_tool = SerperDevTool()
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def extract_text_from_pdf(file_path):
|
|
|
|
| 13 |
doc = fitz.open(file_path)
|
| 14 |
text = ""
|
| 15 |
for page in doc:
|
|
@@ -17,6 +26,7 @@ def extract_text_from_pdf(file_path):
|
|
| 17 |
return text
|
| 18 |
|
| 19 |
def extract_text_from_docx(file_path):
|
|
|
|
| 20 |
doc = docx.Document(file_path)
|
| 21 |
fullText = []
|
| 22 |
for para in doc.paragraphs:
|
|
@@ -24,110 +34,121 @@ def extract_text_from_docx(file_path):
|
|
| 24 |
return "\n".join(fullText)
|
| 25 |
|
| 26 |
def extract_text_from_resume(file_path):
|
|
|
|
| 27 |
if file_path.endswith(".pdf"):
|
| 28 |
return extract_text_from_pdf(file_path)
|
| 29 |
elif file_path.endswith(".docx"):
|
| 30 |
return extract_text_from_docx(file_path)
|
| 31 |
else:
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
# CrewAI Setup
|
| 35 |
-
def setup_crewai(resume_text, location):
|
| 36 |
-
# Set up agents
|
| 37 |
-
resume_feedback = Agent(
|
| 38 |
-
role="Professional Resume Advisor",
|
| 39 |
-
goal="Give feedback on the resume to make it stand out in the job market.",
|
| 40 |
-
verbose=True,
|
| 41 |
-
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."
|
| 42 |
-
)
|
| 43 |
|
| 44 |
-
resume_advisor = Agent(
|
| 45 |
-
role="Professional Resume Writer",
|
| 46 |
-
goal="Based on the feedback recieved from Resume Advisor, make changes to the resume to make it stand out in the job market.",
|
| 47 |
-
verbose=True,
|
| 48 |
-
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."
|
| 49 |
-
)
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
)
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
| 63 |
Review every section, inlcuding the summary, work experience, skills, and education. Suggest to add relevant sections if they are missing.
|
| 64 |
-
Also give an overall score to the resume out of 10. This is the resume: {
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
| 75 |
)
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
Use the tools to gather relevant content and shortlist the 5 most relevant, recent, job openings""",
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
-
# Create and run crew
|
| 85 |
-
crew = Crew(
|
| 86 |
-
agents=[resume_feedback, resume_advisor, job_researcher],
|
| 87 |
-
tasks=[feedback_task, rewrite_task, research_task],
|
| 88 |
-
verbose=True
|
| 89 |
-
)
|
| 90 |
-
|
| 91 |
-
return crew.kickoff()
|
| 92 |
-
|
| 93 |
-
# Gradio Interface
|
| 94 |
-
def process_resume(file, location):
|
| 95 |
-
try:
|
| 96 |
-
# Extract text
|
| 97 |
-
resume_text = extract_text_from_resume(file.name)
|
| 98 |
-
|
| 99 |
-
# Process with CrewAI
|
| 100 |
-
result = setup_crewai(resume_text, location)
|
| 101 |
-
|
| 102 |
-
# Parse results
|
| 103 |
-
feedback = feedback_task.output.raw.strip("```markdown").strip("```").strip()
|
| 104 |
-
improved_resume = rewrite_task.output.raw.strip("```markdown").strip("```").strip()
|
| 105 |
-
jobs = research_task.output.raw.strip("```markdown").strip("```").strip()
|
| 106 |
-
|
| 107 |
-
return feedback, improved_resume, jobs
|
| 108 |
-
|
| 109 |
-
except Exception as e:
|
| 110 |
-
return str(e), "", ""
|
| 111 |
|
| 112 |
with gr.Blocks() as demo:
|
| 113 |
-
gr.Markdown("#
|
| 114 |
-
|
| 115 |
with gr.Row():
|
| 116 |
with gr.Column():
|
| 117 |
-
|
| 118 |
-
location_input = gr.Textbox(label="Preferred
|
| 119 |
-
|
| 120 |
-
|
| 121 |
with gr.Column():
|
| 122 |
-
feedback_output = gr.
|
| 123 |
improved_resume_output = gr.Markdown(label="Improved Resume")
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
inputs=[
|
| 129 |
-
outputs=[feedback_output, improved_resume_output,
|
| 130 |
)
|
| 131 |
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
| 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
|
| 9 |
+
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:
|
|
|
|
| 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:
|
|
|
|
| 34 |
return "\n".join(fullText)
|
| 35 |
|
| 36 |
def extract_text_from_resume(file_path):
|
| 37 |
+
"""Determines file type and extracts text."""
|
| 38 |
if file_path.endswith(".pdf"):
|
| 39 |
return extract_text_from_pdf(file_path)
|
| 40 |
elif file_path.endswith(".docx"):
|
| 41 |
return extract_text_from_docx(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 |
|
| 133 |
with gr.Blocks() as demo:
|
| 134 |
+
gr.Markdown("# Resume Feedback and Job Matching Tool")
|
|
|
|
| 135 |
with gr.Row():
|
| 136 |
with gr.Column():
|
| 137 |
+
resume_upload = gr.File(label="Upload Your Resume (PDF or DOCX)")
|
| 138 |
+
location_input = gr.Textbox(label="Preferred Location", placeholder="e.g., San Francisco")
|
| 139 |
+
submit_button = gr.Button("Submit")
|
|
|
|
| 140 |
with gr.Column():
|
| 141 |
+
feedback_output = gr.Markdown(label="Resume Feedback")
|
| 142 |
improved_resume_output = gr.Markdown(label="Improved Resume")
|
| 143 |
+
job_roles_output = gr.Markdown(label="Relevant Job Roles")
|
| 144 |
+
|
| 145 |
+
submit_button.click(
|
| 146 |
+
resume_agent,
|
| 147 |
+
inputs=[resume_upload, location_input],
|
| 148 |
+
outputs=[feedback_output, improved_resume_output, job_roles_output]
|
| 149 |
)
|
| 150 |
|
| 151 |
+
demo.launch()
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
|