File size: 5,582 Bytes
0875db0
27a7410
f22733a
 
27a7410
56b8e80
9728982
 
27a7410
 
 
 
3e5c67c
9728982
 
27a7410
9728982
27a7410
f22733a
3e5c67c
9728982
f22733a
9728982
 
 
 
 
 
 
 
 
 
27a7410
 
 
9728982
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27a7410
 
f22733a
9728982
27a7410
9728982
 
 
 
27a7410
 
9728982
 
 
 
27a7410
9728982
 
 
 
 
 
 
 
 
f22733a
27a7410
9728982
27a7410
 
f22733a
9728982
 
27a7410
 
 
9728982
27a7410
 
 
9728982
 
27a7410
9728982
 
 
27a7410
 
 
 
 
237f4d4
27a7410
9728982
 
 
27a7410
 
f22733a
 
237f4d4
9728982
 
 
 
f22733a
237f4d4
9728982
 
 
 
 
27a7410
 
 
 
 
3e5c67c
 
27a7410
 
 
 
9728982
 
3e5c67c
f22733a
27a7410
f22733a
 
 
3e5c67c
27a7410
9728982
 
 
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
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
import gradio as gr
from transformers import pipeline

def setup_models():
    print("Inicializando modelos...")
    
    # Modelo 1: Geração de perguntas sobre liderança
    question_model = pipeline(
        "text-generation",
        model="pierreguillou/gpt2-small-portuguese",
        max_length=100
    )
    
    # Modelo 2: Análise e reflexão sobre respostas
    reflection_model = pipeline(
        "text-generation",
        model="pierreguillou/gpt2-small-portuguese",
        max_length=200
    )
    
    return question_model, reflection_model

# Prompts para geração de diferentes tipos de perguntas sobre liderança
QUESTION_PROMPTS = [
    "Gere uma pergunta sobre como um líder deve gerenciar conflitos na equipe:",
    "Crie uma pergunta sobre como motivar equipes em momentos difíceis:",
    "Elabore uma pergunta sobre desenvolvimento de pessoas na liderança:",
    "Formule uma pergunta sobre tomada de decisão em situações críticas:",
    "Gere uma pergunta sobre comunicação efetiva na liderança:",
    "Crie uma pergunta sobre gestão de mudanças organizacionais:",
    "Elabore uma pergunta sobre feedback e avaliação de desempenho:",
    "Formule uma pergunta sobre delegação e empoderamento da equipe:"
]

class LeadershipMentor:
    def __init__(self, question_model, reflection_model):
        self.question_model = question_model
        self.reflection_model = reflection_model
        self.current_prompt_index = 0
        self.current_question = None
        
    def generate_question(self):
        """Gera uma nova pergunta usando o prompt atual"""
        if self.current_prompt_index < len(QUESTION_PROMPTS):
            prompt = QUESTION_PROMPTS[self.current_prompt_index]
            
            # Gerar pergunta usando o modelo
            response = self.question_model(prompt, max_length=100, num_return_sequences=1)
            question = response[0]['generated_text'].split(":")[-1].strip()
            
            # Garantir que a pergunta termine com ?
            if not question.endswith("?"):
                question += "?"
                
            self.current_question = question
            return question
        return None
    
    def generate_reflection(self, answer):
        """Gera uma reflexão sobre a resposta do usuário"""
        reflection_prompt = f"""
        Analise esta resposta de liderança e forneça uma reflexão construtiva:
        
        Pergunta: {self.current_question}
        Resposta: {answer}
        
        Considere:
        1. Pontos fortes demonstrados
        2. Áreas para desenvolvimento
        3. Sugestões práticas
        
        Reflexão:"""
        
        reflection = self.reflection_model(
            reflection_prompt, 
            max_length=200, 
            num_return_sequences=1
        )[0]['generated_text']
        
        return reflection.split("Reflexão:")[-1].strip()
    
    def process_interaction(self, answer, history):
        """Processa a interação do usuário e gera a próxima etapa"""
        if not answer:
            return "", history
            
        # Gerar reflexão sobre a resposta atual
        reflection = self.generate_reflection(answer)
        
        # Atualizar histórico
        new_history = history + [
            (self.current_question, answer),
            ("🤔 Reflexão:", reflection)
        ]
        
        # Avançar para próximo prompt
        self.current_prompt_index += 1
        
        # Gerar próxima pergunta se houver
        next_question = self.generate_question()
        if next_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():
    # Configurar modelos
    question_model, reflection_model = setup_models()
    mentor = LeadershipMentor(question_model, reflection_model)
    
    with gr.Blocks(title="Mentor de Liderança AI") as demo:
        gr.Markdown("""
        # 🎯 Mentor de Liderança AI
        
        Sistema interativo de desenvolvimento de liderança que:
        - Gera perguntas personalizadas sobre diferentes aspectos da liderança
        - Analisa suas respostas
        - Fornece reflexões construtivas para seu desenvolvimento
        """)
        
        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
        first_question = mentor.generate_question()
        chatbot.value = [("📝 Primeira pergunta:", first_question)]
        
        submit.click(
            mentor.process_interaction,
            inputs=[msg, chatbot],
            outputs=[msg, chatbot]
        )
        
        def reset_session():
            mentor.current_prompt_index = 0
            first_question = mentor.generate_question()
            return "", [(f"📝 Primeira pergunta:", first_question)]
        
        clear.click(
            reset_session,
            outputs=[msg, chatbot]
        )
    
    return demo

if __name__ == "__main__":
    print("Iniciando sistema de mentoria...")
    demo = create_interface()
    demo.launch(share=True)