Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,123 +1,96 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
# Modelo 2: Análise e reflexão sobre respostas
|
| 15 |
-
reflection_model = pipeline(
|
| 16 |
-
"text-generation",
|
| 17 |
-
model="pierreguillou/gpt2-small-portuguese",
|
| 18 |
-
max_length=200
|
| 19 |
-
)
|
| 20 |
-
|
| 21 |
-
return question_model, reflection_model
|
| 22 |
-
|
| 23 |
-
# Prompts para geração de diferentes tipos de perguntas sobre liderança
|
| 24 |
-
QUESTION_PROMPTS = [
|
| 25 |
-
"Gere uma pergunta sobre como um líder deve gerenciar conflitos na equipe:",
|
| 26 |
-
"Crie uma pergunta sobre como motivar equipes em momentos difíceis:",
|
| 27 |
-
"Elabore uma pergunta sobre desenvolvimento de pessoas na liderança:",
|
| 28 |
-
"Formule uma pergunta sobre tomada de decisão em situações críticas:",
|
| 29 |
-
"Gere uma pergunta sobre comunicação efetiva na liderança:",
|
| 30 |
-
"Crie uma pergunta sobre gestão de mudanças organizacionais:",
|
| 31 |
-
"Elabore uma pergunta sobre feedback e avaliação de desempenho:",
|
| 32 |
-
"Formule uma pergunta sobre delegação e empoderamento da equipe:"
|
| 33 |
]
|
| 34 |
|
| 35 |
class LeadershipMentor:
|
| 36 |
-
def __init__(self
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
self.
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
# Gerar pergunta usando o modelo
|
| 48 |
-
response = self.question_model(prompt, max_length=100, num_return_sequences=1)
|
| 49 |
-
question = response[0]['generated_text'].split(":")[-1].strip()
|
| 50 |
-
|
| 51 |
-
# Garantir que a pergunta termine com ?
|
| 52 |
-
if not question.endswith("?"):
|
| 53 |
-
question += "?"
|
| 54 |
-
|
| 55 |
-
self.current_question = question
|
| 56 |
-
return question
|
| 57 |
-
return None
|
| 58 |
-
|
| 59 |
-
def generate_reflection(self, answer):
|
| 60 |
"""Gera uma reflexão sobre a resposta do usuário"""
|
| 61 |
reflection_prompt = f"""
|
| 62 |
-
Analise esta resposta
|
| 63 |
|
| 64 |
-
Pergunta: {
|
| 65 |
Resposta: {answer}
|
| 66 |
|
| 67 |
Considere:
|
| 68 |
1. Pontos fortes demonstrados
|
| 69 |
-
2.
|
| 70 |
-
3. Sugestões práticas
|
| 71 |
|
| 72 |
Reflexão:"""
|
| 73 |
|
| 74 |
reflection = self.reflection_model(
|
| 75 |
reflection_prompt,
|
| 76 |
max_length=200,
|
| 77 |
-
num_return_sequences=1
|
|
|
|
| 78 |
)[0]['generated_text']
|
| 79 |
|
| 80 |
return reflection.split("Reflexão:")[-1].strip()
|
| 81 |
|
| 82 |
def process_interaction(self, answer, history):
|
| 83 |
-
"""Processa a
|
| 84 |
if not answer:
|
| 85 |
return "", history
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
| 89 |
|
| 90 |
# Atualizar histórico
|
| 91 |
new_history = history + [
|
| 92 |
-
(
|
| 93 |
("🤔 Reflexão:", reflection)
|
| 94 |
]
|
| 95 |
|
| 96 |
-
# Avançar para
|
| 97 |
-
self.
|
| 98 |
|
| 99 |
-
#
|
| 100 |
-
|
| 101 |
-
|
| 102 |
new_history.append(("📝 Próxima pergunta:", next_question))
|
| 103 |
else:
|
| 104 |
-
new_history.append(("✨ Sessão concluída!", "
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
return "", new_history
|
| 107 |
|
| 108 |
def create_interface():
|
| 109 |
-
|
| 110 |
-
question_model, reflection_model = setup_models()
|
| 111 |
-
mentor = LeadershipMentor(question_model, reflection_model)
|
| 112 |
|
| 113 |
with gr.Blocks(title="Mentor de Liderança AI") as demo:
|
| 114 |
gr.Markdown("""
|
| 115 |
# 🎯 Mentor de Liderança AI
|
| 116 |
|
| 117 |
-
Sistema interativo
|
| 118 |
-
-
|
| 119 |
-
-
|
| 120 |
-
-
|
| 121 |
""")
|
| 122 |
|
| 123 |
chatbot = gr.Chatbot(
|
|
@@ -127,7 +100,7 @@ def create_interface():
|
|
| 127 |
|
| 128 |
msg = gr.Textbox(
|
| 129 |
label="Sua Resposta",
|
| 130 |
-
placeholder="Digite sua resposta aqui...",
|
| 131 |
lines=3
|
| 132 |
)
|
| 133 |
|
|
@@ -136,8 +109,7 @@ def create_interface():
|
|
| 136 |
clear = gr.Button("Reiniciar Sessão")
|
| 137 |
|
| 138 |
# Iniciar com primeira pergunta
|
| 139 |
-
|
| 140 |
-
chatbot.value = [("📝 Primeira pergunta:", first_question)]
|
| 141 |
|
| 142 |
submit.click(
|
| 143 |
mentor.process_interaction,
|
|
@@ -146,9 +118,8 @@ def create_interface():
|
|
| 146 |
)
|
| 147 |
|
| 148 |
def reset_session():
|
| 149 |
-
mentor.
|
| 150 |
-
|
| 151 |
-
return "", [(f"📝 Primeira pergunta:", first_question)]
|
| 152 |
|
| 153 |
clear.click(
|
| 154 |
reset_session,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Perguntas sequenciais sobre liderança
|
| 5 |
+
LEADERSHIP_QUESTIONS = [
|
| 6 |
+
"Como você lida com conflitos entre membros da sua equipe?",
|
| 7 |
+
"Qual foi a decisão mais difícil que você já tomou como líder e o que aprendeu com ela?",
|
| 8 |
+
"Como você mantém sua equipe motivada durante períodos desafiadores?",
|
| 9 |
+
"De que forma você promove o desenvolvimento profissional da sua equipe?",
|
| 10 |
+
"Como você equilibra as necessidades individuais com os objetivos organizacionais?",
|
| 11 |
+
"Como você lida com resistência a mudanças na sua equipe?",
|
| 12 |
+
"Qual é sua abordagem para dar feedback construtivo?",
|
| 13 |
+
"Como você desenvolve a autonomia dos membros da sua equipe?"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
]
|
| 15 |
|
| 16 |
class LeadershipMentor:
|
| 17 |
+
def __init__(self):
|
| 18 |
+
print("Inicializando modelo de reflexão...")
|
| 19 |
+
# Modelo para análise e reflexão sobre respostas
|
| 20 |
+
self.reflection_model = pipeline(
|
| 21 |
+
"text-generation",
|
| 22 |
+
model="pierreguillou/gpt2-small-portuguese",
|
| 23 |
+
max_length=200
|
| 24 |
+
)
|
| 25 |
+
self.current_question = 0
|
| 26 |
+
|
| 27 |
+
def generate_reflection(self, question, answer):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
"""Gera uma reflexão sobre a resposta do usuário"""
|
| 29 |
reflection_prompt = f"""
|
| 30 |
+
Analise esta resposta sobre liderança e forneça feedback construtivo:
|
| 31 |
|
| 32 |
+
Pergunta: {question}
|
| 33 |
Resposta: {answer}
|
| 34 |
|
| 35 |
Considere:
|
| 36 |
1. Pontos fortes demonstrados
|
| 37 |
+
2. Oportunidades de desenvolvimento
|
| 38 |
+
3. Sugestões práticas específicas
|
| 39 |
|
| 40 |
Reflexão:"""
|
| 41 |
|
| 42 |
reflection = self.reflection_model(
|
| 43 |
reflection_prompt,
|
| 44 |
max_length=200,
|
| 45 |
+
num_return_sequences=1,
|
| 46 |
+
temperature=0.7
|
| 47 |
)[0]['generated_text']
|
| 48 |
|
| 49 |
return reflection.split("Reflexão:")[-1].strip()
|
| 50 |
|
| 51 |
def process_interaction(self, answer, history):
|
| 52 |
+
"""Processa a resposta do usuário e avança para próxima pergunta"""
|
| 53 |
if not answer:
|
| 54 |
return "", history
|
| 55 |
+
|
| 56 |
+
current_question = LEADERSHIP_QUESTIONS[self.current_question]
|
| 57 |
+
|
| 58 |
+
# Gerar reflexão sobre a resposta
|
| 59 |
+
reflection = self.generate_reflection(current_question, answer)
|
| 60 |
|
| 61 |
# Atualizar histórico
|
| 62 |
new_history = history + [
|
| 63 |
+
(current_question, answer),
|
| 64 |
("🤔 Reflexão:", reflection)
|
| 65 |
]
|
| 66 |
|
| 67 |
+
# Avançar para próxima pergunta
|
| 68 |
+
self.current_question += 1
|
| 69 |
|
| 70 |
+
# Verificar se ainda há perguntas
|
| 71 |
+
if self.current_question < len(LEADERSHIP_QUESTIONS):
|
| 72 |
+
next_question = LEADERSHIP_QUESTIONS[self.current_question]
|
| 73 |
new_history.append(("📝 Próxima pergunta:", next_question))
|
| 74 |
else:
|
| 75 |
+
new_history.append(("✨ Sessão concluída!", """
|
| 76 |
+
Parabéns por completar todas as perguntas!
|
| 77 |
+
Suas respostas demonstram reflexão sobre diferentes aspectos da liderança.
|
| 78 |
+
Continue desenvolvendo suas habilidades com base nas reflexões fornecidas.
|
| 79 |
+
"""))
|
| 80 |
|
| 81 |
return "", new_history
|
| 82 |
|
| 83 |
def create_interface():
|
| 84 |
+
mentor = LeadershipMentor()
|
|
|
|
|
|
|
| 85 |
|
| 86 |
with gr.Blocks(title="Mentor de Liderança AI") as demo:
|
| 87 |
gr.Markdown("""
|
| 88 |
# 🎯 Mentor de Liderança AI
|
| 89 |
|
| 90 |
+
Sistema interativo para desenvolvimento de habilidades de liderança:
|
| 91 |
+
- Responda a perguntas sequenciais sobre diferentes aspectos da liderança
|
| 92 |
+
- Receba reflexões personalizadas sobre suas respostas
|
| 93 |
+
- Desenvolva seu estilo de liderança através do autoconhecimento
|
| 94 |
""")
|
| 95 |
|
| 96 |
chatbot = gr.Chatbot(
|
|
|
|
| 100 |
|
| 101 |
msg = gr.Textbox(
|
| 102 |
label="Sua Resposta",
|
| 103 |
+
placeholder="Digite sua resposta detalhada aqui...",
|
| 104 |
lines=3
|
| 105 |
)
|
| 106 |
|
|
|
|
| 109 |
clear = gr.Button("Reiniciar Sessão")
|
| 110 |
|
| 111 |
# Iniciar com primeira pergunta
|
| 112 |
+
chatbot.value = [("📝 Primeira pergunta:", LEADERSHIP_QUESTIONS[0])]
|
|
|
|
| 113 |
|
| 114 |
submit.click(
|
| 115 |
mentor.process_interaction,
|
|
|
|
| 118 |
)
|
| 119 |
|
| 120 |
def reset_session():
|
| 121 |
+
mentor.current_question = 0
|
| 122 |
+
return "", [(f"📝 Primeira pergunta:", LEADERSHIP_QUESTIONS[0])]
|
|
|
|
| 123 |
|
| 124 |
clear.click(
|
| 125 |
reset_session,
|