crewai / app.py
Prathamesh1420's picture
Update app.py
ef8f66f verified
raw
history blame
No virus
7.51 kB
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 = "AIzaSyCHHl4LgpZIBw3_Zf15XWuuLSWWIlLROdQ"
# 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())
# Ensure the SERPER API key is correctly passed during initialization
serper_api_key = "42e088db08191f8f2f7d516a9016f579306b5d6d3940d86d840d5370207a5b6c" # Replace with your actual API key
search_tool = SerperDevTool(api_key=serper_api_key)
# Initialize tools
scrape_tool = ScrapeWebsiteTool()
# Initialize read_resume
read_resume = FileReadTool(file_path='fake_resume.md')
# Initialize semantic_search_resume with error handling
semantic_search_resume = None
try:
semantic_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, semantic_search_resume] if semantic_search_resume else [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, semantic_search_resume] if semantic_search_resume else [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, semantic_search_resume] if semantic_search_resume else [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://jobs.lever.co/AIFund/6c82e23e-d954-4dd8-a734-c0c2c5ee00f1?lever-origin=applied&lever-source%5B%5D=AI+Fund',
'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.kickoff(inputs=job_application_inputs)
# Display Results
st.write(results)