Spaces:
Runtime error
Runtime error
| # crewai_resume_optimization.py | |
| import os | |
| from crewai import Agent, Task, Crew | |
| from crewai_tools import PDFSearchTool, ScrapeWebsiteTool | |
| import openai | |
| # Set the model; adjust as needed. | |
| os.environ["OPENAI_MODEL_NAME"] = 'gpt-4o-mini' | |
| openai.api_key = os.getenv("OPENAI_API_KEY") | |
| # Initialize tools. | |
| pdf_tool = PDFSearchTool() | |
| scrape_tool = ScrapeWebsiteTool() | |
| # For this module, we do not need external scraping tools since job input is text. | |
| # Define the Resume Strategist Agent. | |
| # resume_strategist = Agent( | |
| # role="Resume Strategist for Engineers", | |
| # goal="Optimize the candidate's resume by integrating job keywords while preserving its original content.", | |
| # backstory="You are an expert resume strategist. You enhance resumes by incorporating provided keywords exactly where necessary, preserving the original content.", | |
| # verbose=True | |
| # ) | |
| # Resume Strategist Agent: Optimize resume based on provided job description. | |
| resume_strategist = Agent( | |
| role="Resume Strategist for ATS Optimization", | |
| goal="Optimize the candidate's resume to better match the job description for ATS screening. Do not create new roles or responsibilities; instead, tailor the existing content to highlight alignment with the job requirements.", | |
| backstory="You are an expert resume strategist who refines resumes by selectively integrating provided job keywords while preserving the candidate's original experience.", | |
| verbose=True | |
| ) | |
| # # Define the Interview Preparer Agent. | |
| # interview_preparer = Agent( | |
| # role="Interview Preparer", | |
| # goal="Generate interview questions and talking points based on the optimized resume and job keywords.", | |
| # backstory="You create insightful interview questions that help a candidate prepare for an interview, based on the resume content and job requirements.", | |
| # verbose=True | |
| # ) | |
| # Interview Preparer Agent: Generate interview questions based on optimized resume. | |
| interview_preparer = Agent( | |
| role="Interview Preparer", | |
| goal="Generate interview questions and talking points based on the optimized resume and job description.", | |
| backstory="You create insightful interview questions to help candidates prepare, using the optimized resume and job description as context.", | |
| verbose=True | |
| ) | |
| # Job Description Extractor Agent: Used when the user provides a job URL. | |
| job_desc_extractor = Agent( | |
| role="Job Description Extractor", | |
| goal="Extract the job description content from the provided job posting URL using scraping.", | |
| backstory="You specialize in scraping and extracting relevant job information from websites.", | |
| verbose=True, | |
| tools=[scrape_tool] | |
| ) | |
| # # Task 1: Resume Optimization Task. | |
| # resume_optimization_task = Task( | |
| # description=( | |
| # "Given the original resume text: {resume_text}\n\n" | |
| # "and the following job keywords: {job_keywords}, " | |
| # "optimize the resume to highlight the candidate's strengths by incorporating these keywords where appropriate. " | |
| # "Preserve the original content; do not invent new details. " | |
| # "Return the updated resume in markdown format." | |
| # ), | |
| # expected_output="A markdown formatted optimized resume.", | |
| # output_file="tailored_resume.md", | |
| # agent=resume_strategist | |
| # ) | |
| # Task for Resume Optimization: Use the original resume text and job description. | |
| resume_optimization_task = Task( | |
| description=( | |
| "Given the original resume text:\n\n{resume_text}\n\n" | |
| "and the job description:\n\n{job_description}\n\n" | |
| "Optimize the resume to better match the job requirements for ATS screening." | |
| "Make sure to identify keywords form the job description and inlcude all necessary keywords to make the resume standout" | |
| "Preserve the original roles and responsibilities, but tailor the content to emphasize alignment with the job requirements. " | |
| "Return the optimized resume in markdown format." | |
| ), | |
| expected_output="A markdown formatted optimized resume.", | |
| output_file="tailored_resume.md", | |
| agent=resume_strategist | |
| ) | |
| # # Task 2: Interview Question Generation Task. | |
| # interview_generation_task = Task( | |
| # description=( | |
| # "Using the optimized resume: {optimized_resume}\n\n" | |
| # "and the job keywords: {job_keywords}, generate a set of interview questions and talking points. " | |
| # "Return the result in markdown format." | |
| # ), | |
| # expected_output="A markdown formatted document containing interview questions and talking points.", | |
| # output_file="interview_materials.md", | |
| # agent=interview_preparer, | |
| # context=[resume_optimization_task] | |
| # ) | |
| # Task for Interview Generation: Use the optimized resume and job description. | |
| interview_generation_task = Task( | |
| description=( | |
| "Using the optimized resume:\n\n{optimized_resume}\n\n" | |
| "and the job description:\n\n{job_description}\n\n" | |
| "Generate a set of interview questions and talking points in markdown format." | |
| ), | |
| expected_output="A markdown formatted document with interview questions and talking points.", | |
| output_file="interview_materials.md", | |
| agent=interview_preparer, | |
| context=[resume_optimization_task] | |
| ) | |
| # Task for Job Description Extraction (for URL mode). | |
| job_desc_extraction_task = Task( | |
| description=( | |
| "Extract and return the job description content from the job posting URL {job_url}." | |
| ), | |
| expected_output="A string containing the job description.", | |
| agent=job_desc_extractor | |
| ) | |
| # Crew for job description extraction (URL mode) | |
| job_desc_crew = Crew( | |
| agents=[job_desc_extractor], | |
| tasks=[job_desc_extraction_task], | |
| verbose=True | |
| ) | |
| # Assemble the Crew. | |
| resume_optimization_crew = Crew( | |
| agents=[resume_strategist], | |
| tasks=[resume_optimization_task], | |
| verbose=True | |
| ) | |
| # Assemble the Crew. | |
| interview_prep_crew = Crew( | |
| agents=[ interview_preparer], | |
| tasks=[ interview_generation_task], | |
| verbose=True | |
| ) | |
| # --------------------------- | |
| # Functions to call the crews | |
| # --------------------------- | |
| def optimize_resume(resume_text: str, job_description: str) -> str: | |
| inputs = {"resume_text": resume_text, "job_description": job_description} | |
| results = resume_optimization_crew .kickoff(inputs=inputs) | |
| return results.raw | |
| def generate_interview_questions(optimized_resume: str, job_description: str) -> str: | |
| inputs = {"optimized_resume": optimized_resume, "job_description": job_description} | |
| results = interview_prep_crew.kickoff(inputs=inputs) | |
| return results.raw | |
| def extract_job_description(job_url: str) -> str: | |
| inputs = {"job_url": job_url} | |
| results = job_desc_crew.kickoff(inputs=inputs) | |
| return results.raw | |
| # def optimize_resume(resume_text: str, job_keywords: str) -> str: | |
| # inputs = {"resume_text": resume_text, "job_keywords": job_keywords} | |
| # results = resume_optimization_crew.kickoff(inputs=inputs) | |
| # return results.raw | |
| # def generate_interview_questions(optimized_resume: str, job_keywords: str) -> str: | |
| # inputs = {"optimized_resume": optimized_resume, "job_keywords": job_keywords} | |
| # results = interview_prep_crew.kickoff(inputs=inputs) | |
| # return results.raw | |
| # if __name__ == "__main__": | |
| # sample_resume = "Sample resume text here..." | |
| # sample_keywords = "Python, Machine Learning, Leadership" | |
| # optimized = optimize_resume(sample_resume, sample_keywords) | |
| # print("Optimized Resume:\n", optimized) | |
| # interview = generate_interview_questions(optimized, sample_keywords) | |
| # print("Interview Questions:\n", interview) | |
| if __name__ == "__main__": | |
| # Test usage | |
| sample_resume = "Sample resume text..." | |
| sample_job_desc = "This job requires Python, machine learning, and leadership." | |
| optimized = optimize_resume(sample_resume, sample_job_desc) | |
| print("Optimized Resume:\n", optimized) | |
| interview = generate_interview_questions(optimized, sample_job_desc) | |
| print("Interview Questions:\n", interview) | |