File size: 6,027 Bytes
fcc1cf1 d10af90 0c25bec e29185d fcc1cf1 d10af90 e29185d d10af90 b33c70a 5a7169e d10af90 e29185d d10af90 0c25bec d10af90 5a7169e d10af90 e29185d d10af90 5a7169e d10af90 5a7169e d10af90 0c25bec d10af90 0c25bec d10af90 0c25bec d10af90 e29185d d10af90 5a7169e d10af90 e29185d 5a7169e d10af90 fcc1cf1 5a7169e e29185d 5a7169e f33f8df 5a7169e e29185d 5a7169e d10af90 0c25bec e29185d d10af90 fcc1cf1 d10af90 |
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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
import gradio as gr
import numpy as np
from transformers import pipeline
import pandas as pd
class DiscAnalyzer:
def __init__(self):
self.disc_profiles = {
'D': 'Dominância',
'I': 'Influência',
'S': 'Estabilidade',
'C': 'Conformidade'
}
# Inicializar modelo mais leve
self.generator = pipeline(
"text-generation",
model="facebook/opt-125m",
device="cpu"
)
def generate_llm_report(self, scores, perfil_principal):
prompt = f"""Analise o perfil DISC:
D:{scores['D']:.1f}% I:{scores['I']:.1f}% S:{scores['S']:.1f}% C:{scores['C']:.1f}%
Perfil Principal: {self.disc_profiles[perfil_principal]}
"""
try:
output = self.generator(
prompt,
max_length=300,
num_return_sequences=1,
temperature=0.7,
top_p=0.9,
do_sample=True
)
return output[0]['generated_text'].replace(prompt, "").strip()
except Exception as e:
return f"Erro ao gerar relatório: {str(e)}"
def avaliar_disc(self, *args):
responses = [int(arg) for arg in args]
scores = {
'D': sum(responses[i] for i in [0, 4, 8, 12]) / 16 * 100,
'I': sum(responses[i] for i in [1, 5, 9, 13]) / 16 * 100,
'S': sum(responses[i] for i in [2, 6, 10, 14]) / 16 * 100,
'C': sum(responses[i] for i in [3, 7, 11, 15]) / 16 * 100
}
perfil_principal = max(scores, key=scores.get)
relatorio_llm = self.generate_llm_report(scores, perfil_principal)
df = pd.DataFrame({
"Dimensão": list(scores.keys()),
"Score": list(scores.values()),
"Descrição": [self.disc_profiles[k] for k in scores.keys()]
})
return (
f"**{self.disc_profiles[perfil_principal]} ({perfil_principal})**",
relatorio_llm,
df,
gr.update(visible=True),
gr.update(visible=False)
)
def create_disc_interface():
analyzer = DiscAnalyzer()
with gr.Blocks(title="Análise de Perfil DISC") as interface:
gr.Markdown(
"""
# 🎯 Analisador de Perfil DISC
#### Descubra seu perfil comportamental
"""
)
with gr.Row() as questionnaire_container:
with gr.Column():
gr.Markdown(
"""
### Questionário DISC
Avalie cada afirmação (1 = Discordo totalmente, 4 = Concordo totalmente)
"""
)
questions = {
"Dominância (D)": [
"Sou direto e decisivo",
"Gosto de assumir riscos",
"Tomo iniciativa",
"Busco resultados"
],
"Influência (I)": [
"Sou sociável e entusiasta",
"Sou bom comunicador",
"Sou persuasivo",
"Sou motivador"
],
"Estabilidade (S)": [
"Sou paciente e cooperativo",
"Sou bom ouvinte",
"Trabalho bem em equipe",
"Sou confiável"
],
"Conformidade (C)": [
"Sou preciso e analítico",
"Sou organizado",
"Sou detalhista",
"Sou sistemático"
]
}
sliders = []
for categoria, perguntas in questions.items():
gr.Markdown(f"#### {categoria}")
for pergunta in perguntas:
slider = gr.Slider(
minimum=1,
maximum=4,
value=2,
step=1,
label=pergunta
)
sliders.append(slider)
analyze_btn = gr.Button("Analisar Perfil", variant="primary")
# Resultados (inicialmente ocultos)
with gr.Row(visible=False) as results_container:
with gr.Column():
gr.Markdown("### Resultados da Análise")
perfil_output = gr.Markdown(label="Perfil Principal")
with gr.Row():
with gr.Column():
plot_output = gr.BarPlot(
x="Dimensão",
y="Score",
title="Perfil DISC",
tooltip=["Descrição", "Score"],
height=400,
width=600
)
with gr.Column():
relatorio_output = gr.Markdown(label="Análise Detalhada")
new_test_btn = gr.Button("Fazer Novo Teste", variant="secondary")
analyze_btn.click(
fn=analyzer.avaliar_disc,
inputs=sliders,
outputs=[
perfil_output,
relatorio_output,
plot_output,
results_container,
questionnaire_container
]
)
new_test_btn.click(
fn=lambda: [2] * 16 + [gr.update(visible=True), gr.update(visible=False)],
inputs=None,
outputs=sliders + [questionnaire_container, results_container]
)
return interface
if __name__ == "__main__":
interface = create_disc_interface()
interface.launch(
server_name="0.0.0.0",
server_port=7860,
share=True
) |