prisantos's picture
[chore] variable naming adjustment
a26c578
raw
history blame
5.2 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
# Carregar variáveis de ambiente
load_dotenv()
os.environ["OPENAI_MODEL_NAME"] = "gpt-3.5-turbo"
# Inicializar agentes e tarefas
agents = MultiAgents()
tasks = MultiTasks()
search_tool = SerperDevTool()
scrape_tool = ScrapeWebsiteTool()
# Carregar imagem do ícone
imagem_icon = Image.open("src/assistente-de-robo.png")
imagem_icon = imagem_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("Olá, Sou o Taylor IA, seu Consultor de carreira:")
st.write(
"""Estou aqui para ajudá-lo a destacar suas habilidades e
experiências para o mercado de trabalho."""
)
st.session_state.openai_api_key = st.text_input(
"Insira seu token da OpenAI:", type="password"
)
st.session_state.serper_api_key = st.text_input(
"Insira seu token da SERPER:", type="password"
)
st.image(imagem_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("Consultor de Carreira")
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("Digite seu nome:")
job_posting_url = st.text_input("Informe a URL da vaga desejada:")
github_url = st.text_input("Informe a URL do seu Github:")
uploaded_resume = st.file_uploader(
"Por favor, faça o upload do seu currículo nos formatos PDF",
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("Realizar Análise"):
# Agentes
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
)
# Tarefas
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,
}
# Executar a análise
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"curriculo_personalizado_{candidate_name}.md"
)
with open(resume_file_path, "rb") as file:
btn = st.download_button(
label="Baixar Currículo Gerado",
data=file,
file_name=os.path.basename(resume_file_path),
mime="text/plain",
)
if btn:
st.success("Download Iniciado!")
st.success(f"Análise concluída! Obrigado, {candidate_name}!")
if __name__ == "__main__":
main()