Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,88 +1,104 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
-
import torch
|
| 4 |
|
| 5 |
def setup_models():
|
| 6 |
-
# Usando modelos públicos que não requerem autenticação
|
| 7 |
print("Inicializando modelos...")
|
| 8 |
|
| 9 |
-
# Modelo
|
| 10 |
-
|
| 11 |
"text-generation",
|
| 12 |
model="pierreguillou/gpt2-small-portuguese",
|
| 13 |
max_length=100
|
| 14 |
)
|
| 15 |
|
| 16 |
-
# Modelo
|
| 17 |
-
|
| 18 |
"text-generation",
|
| 19 |
-
model="
|
| 20 |
max_length=200
|
| 21 |
)
|
| 22 |
|
| 23 |
-
return
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
-
"
|
| 28 |
-
"
|
| 29 |
-
"
|
| 30 |
-
"
|
| 31 |
-
"
|
| 32 |
-
"
|
| 33 |
-
"
|
| 34 |
-
"
|
| 35 |
]
|
| 36 |
|
| 37 |
class LeadershipMentor:
|
| 38 |
-
def __init__(self,
|
| 39 |
-
self.
|
| 40 |
-
self.
|
| 41 |
-
self.
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
return question
|
| 48 |
return None
|
| 49 |
|
| 50 |
-
def generate_reflection(self,
|
| 51 |
"""Gera uma reflexão sobre a resposta do usuário"""
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
| 55 |
Resposta: {answer}
|
| 56 |
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
reflection =
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
def process_interaction(self, answer, history):
|
| 65 |
-
"""Processa a interação do usuário"""
|
| 66 |
if not answer:
|
| 67 |
return "", history
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
# Gerar reflexão
|
| 72 |
-
reflection = self.generate_reflection(current_question, answer)
|
| 73 |
|
| 74 |
# Atualizar histórico
|
| 75 |
new_history = history + [
|
| 76 |
-
(current_question, answer),
|
| 77 |
("🤔 Reflexão:", reflection)
|
| 78 |
]
|
| 79 |
|
| 80 |
-
# Avançar para
|
| 81 |
-
self.
|
| 82 |
|
| 83 |
-
#
|
| 84 |
-
|
| 85 |
-
|
| 86 |
new_history.append(("📝 Próxima pergunta:", next_question))
|
| 87 |
else:
|
| 88 |
new_history.append(("✨ Sessão concluída!", "Obrigado por participar!"))
|
|
@@ -90,18 +106,25 @@ class LeadershipMentor:
|
|
| 90 |
return "", new_history
|
| 91 |
|
| 92 |
def create_interface():
|
| 93 |
-
|
| 94 |
-
|
|
|
|
| 95 |
|
| 96 |
with gr.Blocks(title="Mentor de Liderança AI") as demo:
|
| 97 |
gr.Markdown("""
|
| 98 |
# 🎯 Mentor de Liderança AI
|
| 99 |
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
| 102 |
""")
|
| 103 |
|
| 104 |
-
chatbot = gr.Chatbot(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
msg = gr.Textbox(
|
| 106 |
label="Sua Resposta",
|
| 107 |
placeholder="Digite sua resposta aqui...",
|
|
@@ -113,7 +136,8 @@ def create_interface():
|
|
| 113 |
clear = gr.Button("Reiniciar Sessão")
|
| 114 |
|
| 115 |
# Iniciar com primeira pergunta
|
| 116 |
-
|
|
|
|
| 117 |
|
| 118 |
submit.click(
|
| 119 |
mentor.process_interaction,
|
|
@@ -122,8 +146,9 @@ def create_interface():
|
|
| 122 |
)
|
| 123 |
|
| 124 |
def reset_session():
|
| 125 |
-
mentor.
|
| 126 |
-
|
|
|
|
| 127 |
|
| 128 |
clear.click(
|
| 129 |
reset_session,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
def setup_models():
|
|
|
|
| 5 |
print("Inicializando modelos...")
|
| 6 |
|
| 7 |
+
# Modelo 1: Geração de perguntas sobre liderança
|
| 8 |
+
question_model = pipeline(
|
| 9 |
"text-generation",
|
| 10 |
model="pierreguillou/gpt2-small-portuguese",
|
| 11 |
max_length=100
|
| 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, question_model, reflection_model):
|
| 37 |
+
self.question_model = question_model
|
| 38 |
+
self.reflection_model = reflection_model
|
| 39 |
+
self.current_prompt_index = 0
|
| 40 |
+
self.current_question = None
|
| 41 |
+
|
| 42 |
+
def generate_question(self):
|
| 43 |
+
"""Gera uma nova pergunta usando o prompt atual"""
|
| 44 |
+
if self.current_prompt_index < len(QUESTION_PROMPTS):
|
| 45 |
+
prompt = QUESTION_PROMPTS[self.current_prompt_index]
|
| 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 de liderança e forneça uma reflexão construtiva:
|
| 63 |
+
|
| 64 |
+
Pergunta: {self.current_question}
|
| 65 |
Resposta: {answer}
|
| 66 |
|
| 67 |
+
Considere:
|
| 68 |
+
1. Pontos fortes demonstrados
|
| 69 |
+
2. Áreas para desenvolvimento
|
| 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 interação do usuário e gera a próxima etapa"""
|
| 84 |
if not answer:
|
| 85 |
return "", history
|
| 86 |
|
| 87 |
+
# Gerar reflexão sobre a resposta atual
|
| 88 |
+
reflection = self.generate_reflection(answer)
|
|
|
|
|
|
|
| 89 |
|
| 90 |
# Atualizar histórico
|
| 91 |
new_history = history + [
|
| 92 |
+
(self.current_question, answer),
|
| 93 |
("🤔 Reflexão:", reflection)
|
| 94 |
]
|
| 95 |
|
| 96 |
+
# Avançar para próximo prompt
|
| 97 |
+
self.current_prompt_index += 1
|
| 98 |
|
| 99 |
+
# Gerar próxima pergunta se houver
|
| 100 |
+
next_question = self.generate_question()
|
| 101 |
+
if next_question:
|
| 102 |
new_history.append(("📝 Próxima pergunta:", next_question))
|
| 103 |
else:
|
| 104 |
new_history.append(("✨ Sessão concluída!", "Obrigado por participar!"))
|
|
|
|
| 106 |
return "", new_history
|
| 107 |
|
| 108 |
def create_interface():
|
| 109 |
+
# Configurar modelos
|
| 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 de desenvolvimento de liderança que:
|
| 118 |
+
- Gera perguntas personalizadas sobre diferentes aspectos da liderança
|
| 119 |
+
- Analisa suas respostas
|
| 120 |
+
- Fornece reflexões construtivas para seu desenvolvimento
|
| 121 |
""")
|
| 122 |
|
| 123 |
+
chatbot = gr.Chatbot(
|
| 124 |
+
height=600,
|
| 125 |
+
label="Sessão de Mentoria"
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
msg = gr.Textbox(
|
| 129 |
label="Sua Resposta",
|
| 130 |
placeholder="Digite sua resposta aqui...",
|
|
|
|
| 136 |
clear = gr.Button("Reiniciar Sessão")
|
| 137 |
|
| 138 |
# Iniciar com primeira pergunta
|
| 139 |
+
first_question = mentor.generate_question()
|
| 140 |
+
chatbot.value = [("📝 Primeira pergunta:", first_question)]
|
| 141 |
|
| 142 |
submit.click(
|
| 143 |
mentor.process_interaction,
|
|
|
|
| 146 |
)
|
| 147 |
|
| 148 |
def reset_session():
|
| 149 |
+
mentor.current_prompt_index = 0
|
| 150 |
+
first_question = mentor.generate_question()
|
| 151 |
+
return "", [(f"📝 Primeira pergunta:", first_question)]
|
| 152 |
|
| 153 |
clear.click(
|
| 154 |
reset_session,
|