import streamlit as st import os import asyncio import warnings from crewai import Agent, Task, Crew from langchain_google_genai import ChatGoogleGenerativeAI from crewai_tools import FileReadTool, ScrapeWebsiteTool, MDXSearchTool, SerperDevTool # Warning control warnings.filterwarnings('ignore') # Set the Google API key directly in the code google_api_key = "AIzaSyCeZHse0Jr8PXBQoKFJg7fZkV_t5w6ViBM" # Function to initialize the Gemini model with an event loop async def initialize_llm(): return ChatGoogleGenerativeAI( model="gemini-1.5-flash", verbose=True, temperature=0.5, google_api_key=google_api_key ) # Run the initialization within the event loop if not hasattr(st, 'llm'): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) st.llm = loop.run_until_complete(initialize_llm()) # Initialize tools search_tool = SerperDevTool() scrape_tool = ScrapeWebsiteTool() read_resume = FileReadTool(file_path='./fake_resume.md') # Attempt to initialize MDXSearchTool try: emantic_search_resume = MDXSearchTool( config=dict( llm=dict( provider="ollama", config=dict( model="llama2", ), ), embedder=dict( provider="google", config=dict( model="models/embedding-001", task_type="retrieval_document", ), ), ), mdx='./fake_resume.md' ) except Exception as e: st.error(f"Failed to initialize MDXSearchTool: {e}") # Define agents researcher = Agent( role="Tech Job Researcher", goal="Make sure to do amazing analysis on job posting to help job applicants", tools=[scrape_tool, search_tool], verbose=True, backstory=( "As a Job Researcher, your prowess in navigating and extracting critical " "information from job postings is unmatched. Your skills help pinpoint the necessary " "qualifications and skills sought by employers, forming the foundation for effective application tailoring." ), llm=st.llm ) profiler = Agent( role="Personal Profiler for Engineers", goal="Do incredible research on job applicants to help them stand out in the job market", tools=[scrape_tool, search_tool, read_resume], verbose=True, backstory=( "Equipped with analytical prowess, you dissect and synthesize information " "from diverse sources to craft comprehensive personal and professional profiles, laying the " "groundwork for personalized resume enhancements." ), llm=st.llm ) resume_strategist = Agent( role="Resume Strategist for Engineers", goal="Find all the best ways to make a resume stand out in the job market.", tools=[scrape_tool, search_tool, read_resume], verbose=True, backstory=( "With a strategic mind and an eye for detail, you excel at refining resumes to highlight the most " "relevant skills and experiences, ensuring they resonate perfectly with the job's requirements." ), llm=st.llm ) interview_preparer = Agent( role="Engineering Interview Preparer", goal="Create interview questions and talking points based on the resume and job requirements", tools=[scrape_tool, search_tool, read_resume], verbose=True, backstory=( "Your role is crucial in anticipating the dynamics of interviews. With your ability to formulate key questions " "and talking points, you prepare candidates for success, ensuring they can confidently address all aspects of the " "job they are applying for." ), llm=st.llm ) # Define tasks research_task = Task( description=( "Analyze the job posting URL provided ({job_posting_url}) " "to extract key skills, experiences, and qualifications required. Use the tools to gather content and identify " "and categorize the requirements." ), expected_output=( "A structured list of job requirements, including necessary skills, qualifications, and experiences." ), agent=researcher, async_execution=True ) profile_task = Task( description=( "Compile a detailed personal and professional profile using the GitHub ({github_url}) URLs, LinkedIn ({linkedin_url}) URL, and personal write-up " "({personal_writeup}). Utilize tools to extract and synthesize information from these sources." ), expected_output=( "A comprehensive profile document that includes skills, project experiences, contributions, interests, and " "communication style." ), agent=profiler, async_execution=True ) resume_strategy_task = Task( description=( "Using the profile and job requirements obtained from previous tasks, tailor the resume to highlight the most " "relevant areas. Employ tools to adjust and enhance the resume content. Make sure this is the best resume even but " "don't make up any information. Update every section, including the initial summary, work experience, skills, " "and education. All to better reflect the candidate's abilities and how it matches the job posting." ), expected_output=( "An updated resume that effectively highlights the candidate's qualifications and experiences relevant to the job." ), output_file="tailored_resume.md", context=[research_task, profile_task], agent=resume_strategist ) interview_preparation_task = Task( description=( "Create a set of potential interview questions and talking points based on the tailored resume and job requirements. " "Utilize tools to generate relevant questions and discussion points. Make sure to use these questions and talking points to " "help the candidate highlight the main points of the resume and how it matches the job posting." ), expected_output=( "A document containing key questions and talking points that the candidate should prepare for the initial interview." ), output_file="interview_materials.md", context=[research_task, profile_task, resume_strategy_task], agent=interview_preparer ) # Crew Setup job_application_crew = Crew( agents=[researcher, profiler, resume_strategist, interview_preparer], tasks=[research_task, profile_task, resume_strategy_task, interview_preparation_task], verbose=True ) # Job Application Inputs job_application_inputs = { 'job_posting_url': 'https://www.linkedin.com/jobs/search/?alertAction=viewjobs¤tJobId=3971168247&distance=25&f_TPR=a1720706267-&f_WT=1%2C3%2C2&geoId=105524837&keywords=data%20scientist&origin=JOB_ALERT_IN_APP_NOTIFICATION&originToLandingJobPostings=3971101316%2C3971168247%2C3967271270&searchSessionId=8zvx%2B0XyTXGBHQHqUmPRDQ%3D%3D', 'github_url': 'https://github.com/PrathameshK', 'linkedin_url': 'https://www.linkedin.com/in/prathameshkhade/', 'personal_writeup': './fake_resume.md' } # Running Tasks results = job_application_crew.run_tasks(inputs=job_application_inputs) # Display Results st.write(results)