Spaces:
Sleeping
Sleeping
File size: 4,784 Bytes
0875db0 27a7410 f22733a 27a7410 56b8e80 27a7410 3e5c67c 27a7410 f22733a 3e5c67c 27a7410 f22733a 27a7410 f22733a 27a7410 f22733a 27a7410 f22733a 27a7410 237f4d4 27a7410 f22733a 237f4d4 27a7410 f22733a 237f4d4 27a7410 3e5c67c 27a7410 3e5c67c f22733a 27a7410 f22733a 3e5c67c 27a7410 3e5c67c f22733a 32e190b 27a7410 |
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 |
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) |