prisantos's picture
[style] djust text to information what model llm is used
eb55a66
raw
history blame contribute delete
No virus
5.16 kB
import os
import streamlit as st
from crewai import Crew
from crewai_tools import PDFSearchTool, ScrapeWebsiteTool, SerperDevTool
from dotenv import load_dotenv
from PIL import Image
from src.agents import MultiAgents
from src.tasks import MultiTasks
# Load environment variables
load_dotenv()
os.environ["OPENAI_MODEL_NAME"] = "gpt-3.5-turbo"
# Initialize agents and tasks
agents = MultiAgents()
tasks = MultiTasks()
search_tool = SerperDevTool()
scrape_tool = ScrapeWebsiteTool()
# Load icon image
image_icon = Image.open("src/assistente-de-robo.png")
image_icon = image_icon.resize((100, 100))
def save_uploaded_file(uploaded_file):
temp_dir = "tempDir"
if not os.path.exists(temp_dir):
os.makedirs(temp_dir)
temp_file_path = os.path.join(temp_dir, uploaded_file.name)
with open(temp_file_path, "wb") as f:
f.write(uploaded_file.getbuffer())
return temp_file_path
def read_file(file_path):
pdf_search_tool = PDFSearchTool(pdf=file_path)
return pdf_search_tool
def main():
with st.sidebar:
st.title("Hello, I'm Taylor AI!\nYour Career Consultant:")
st.write(
"""I am here to help you highlight your skills and
experiences for the job market.I am currently using the gpt-3.
5-turbo model."""
)
st.session_state.openai_api_key = st.text_input(
"Enter your OpenAI token:", type="password"
)
st.session_state.serper_api_key = st.text_input(
"Enter your SERPER token:", type="password"
)
st.image(image_icon, use_column_width=True)
if st.session_state.openai_api_key:
os.environ["OPENAI_API_KEY"] = st.session_state.openai_api_key
if st.session_state.serper_api_key:
os.environ["SERPER_API_KEY"] = st.session_state.serper_api_key
st.header("Career Consultant")
if "result_done" not in st.session_state:
st.session_state.result_done = False
if "result" not in st.session_state:
st.session_state.result = None
candidate_name = st.text_input("Enter your name:")
job_posting_url = st.text_input("Enter the job posting URL:")
github_url = st.text_input("Enter your GitHub URL:")
uploaded_resume = st.file_uploader(
"Please upload your resume in PDF format",
type=["pdf"],
)
if uploaded_resume:
if uploaded_resume.type == "application/pdf":
temp_file_path = save_uploaded_file(uploaded_resume)
pdf_search_tool = read_file(temp_file_path)
os.remove(temp_file_path)
if st.button("Perform Analysis"):
# Agents
researcher = agents.researcher(search_tool, scrape_tool)
profile_creator = agents.profile_creator(
search_tool, scrape_tool, pdf_search_tool
)
professional_consultant = agents.professional_consultant(
search_tool, scrape_tool, pdf_search_tool
)
interview_preparer = agents.interview_preparer(
search_tool, scrape_tool, pdf_search_tool
)
# Tasks
research_task = tasks.research_task(researcher, job_posting_url)
profile_manager_task = tasks.profile_manager_task(
profile_creator, github_url, candidate_name
)
resume_adaptation_task = tasks.resume_adaptation_task(
candidate_name,
professional_consultant,
profile_manager_task,
profile_manager_task,
)
interview_preparation_task = tasks.interview_preparation_task(
interview_preparer,
research_task,
profile_manager_task,
resume_adaptation_task,
)
crew = Crew(
agents=[
researcher,
profile_creator,
professional_consultant,
interview_preparer,
],
tasks=[
research_task,
profile_manager_task,
resume_adaptation_task,
interview_preparation_task,
],
verbose=True,
)
inputs = {
"candidate_name": candidate_name,
"github_url": github_url,
"job_posting_url": job_posting_url,
"uploaded_resume": uploaded_resume,
}
# Execute the analysis
result = crew.kickoff(inputs=inputs)
st.session_state.result_done = True
st.session_state.result = result
st.session_state.show_success = False
st.write(st.session_state.result)
resume_file_path = os.path.basename(
f"custom_resume_{candidate_name}.md"
)
with open(resume_file_path, "rb") as file:
btn = st.download_button(
label="Download Generated Resume",
data=file,
file_name=os.path.basename(resume_file_path),
mime="text/plain",
)
if btn:
st.success("Download Started!")
st.success(f"Analysis completed! Thank you, {candidate_name}!")
if __name__ == "__main__":
main()