import gradio as gr from transformers import pipeline import torch def setup_models(): # Usando modelos públicos que não requerem autenticação print("Inicializando modelos...") # Modelo para geração de texto - usando GPT2 pequeno em português question_generator = pipeline( "text-generation", model="pierreguillou/gpt2-small-portuguese", max_length=100 ) # Modelo para análise de sentimento/reflexão reflection_generator = pipeline( "text-generation", model="microsoft/DialoGPT-small", max_length=200 ) return question_generator, reflection_generator # Lista predefinida de perguntas sobre liderança LEADERSHIP_QUESTIONS = [ "Como você lida com conflitos entre membros da sua equipe?", "Qual foi a decisão mais difícil que você já tomou como líder?", "Como você mantém sua equipe motivada em períodos desafiadores?", "De que forma você promove o desenvolvimento profissional da sua equipe?", "Como você equilibra as necessidades individuais com os objetivos organizacionais?", "Como você lida com resistência a mudanças na sua equipe?", "Qual é sua abordagem para dar feedback negativo?", "Como você desenvolve a autonomia dos membros da sua equipe?" ] class LeadershipMentor: def __init__(self, question_gen, reflection_gen): self.question_generator = question_gen self.reflection_generator = reflection_gen self.current_question = 0 def get_next_question(self): """Retorna a próxima pergunta da lista""" if self.current_question < len(LEADERSHIP_QUESTIONS): question = LEADERSHIP_QUESTIONS[self.current_question] return question return None def generate_reflection(self, question, answer): """Gera uma reflexão sobre a resposta do usuário""" prompt = f""" Analisando a resposta sobre liderança: Pergunta: {question} Resposta: {answer} Reflexão construtiva:""" reflection = self.reflection_generator(prompt, max_length=200)[0]['generated_text'] # Limpar e formatar a reflexão reflection = reflection.split("Reflexão construtiva:")[-1].strip() return reflection def process_interaction(self, answer, history): """Processa a interação do usuário""" if not answer: return "", history current_question = LEADERSHIP_QUESTIONS[self.current_question] # Gerar reflexão reflection = self.generate_reflection(current_question, answer) # Atualizar histórico new_history = history + [ (current_question, answer), ("🤔 Reflexão:", reflection) ] # Avançar para próxima pergunta self.current_question += 1 # Verificar se ainda há perguntas if self.current_question < len(LEADERSHIP_QUESTIONS): next_question = LEADERSHIP_QUESTIONS[self.current_question] new_history.append(("📝 Próxima pergunta:", next_question)) else: new_history.append(("✨ Sessão concluída!", "Obrigado por participar!")) return "", new_history def create_interface(): question_gen, reflection_gen = setup_models() mentor = LeadershipMentor(question_gen, reflection_gen) with gr.Blocks(title="Mentor de Liderança AI") as demo: gr.Markdown(""" # 🎯 Mentor de Liderança AI Desenvolva suas habilidades de liderança através de perguntas reflexivas e feedback personalizado. """) chatbot = gr.Chatbot(height=600, label="Sessão de Mentoria") msg = gr.Textbox( label="Sua Resposta", placeholder="Digite sua resposta aqui...", lines=3 ) with gr.Row(): submit = gr.Button("Enviar Resposta") clear = gr.Button("Reiniciar Sessão") # Iniciar com primeira pergunta chatbot.value = [("📝 Primeira pergunta:", LEADERSHIP_QUESTIONS[0])] submit.click( mentor.process_interaction, inputs=[msg, chatbot], outputs=[msg, chatbot] ) def reset_session(): mentor.current_question = 0 return "", [(f"📝 Primeira pergunta:", LEADERSHIP_QUESTIONS[0])] clear.click( reset_session, outputs=[msg, chatbot] ) return demo if __name__ == "__main__": print("Iniciando sistema de mentoria...") demo = create_interface() demo.launch(share=True)