|
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' |
|
} |
|
|
|
|
|
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") |
|
|
|
|
|
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 |
|
) |