Spaces:
Sleeping
Sleeping
File size: 5,197 Bytes
3d312b2 41395df 3d312b2 a26c578 3d312b2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
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()
|