Update app.py
Browse files
app.py
CHANGED
@@ -79,38 +79,132 @@ def calcular_perfil(respostas):
|
|
79 |
total = sum(contagem.values())
|
80 |
return {k: (v/total)*100 if total > 0 else 0 for k, v in contagem.items()}
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
def create_disc_plot(percentuais):
|
83 |
cores = {'D': '#FF4B4B', 'I': '#FFD700', 'S': '#4CAF50', 'C': '#2196F3'}
|
84 |
-
|
|
|
85 |
marker_color=[cores[k] for k in percentuais.keys()],
|
86 |
text=[f'{v:.1f}%' for v in percentuais.values()],
|
87 |
-
textposition='auto')])
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
def create_interface():
|
100 |
-
with gr.Blocks(
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
def process_results(*answers):
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
-
analyze_btn.click(
|
111 |
-
|
112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
return iface
|
114 |
|
115 |
if __name__ == "__main__":
|
116 |
-
create_interface()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
total = sum(contagem.values())
|
80 |
return {k: (v/total)*100 if total > 0 else 0 for k, v in contagem.items()}
|
81 |
|
82 |
+
import gradio as gr
|
83 |
+
import plotly.graph_objects as go
|
84 |
+
from sentence_transformers import SentenceTransformer
|
85 |
+
import numpy as np
|
86 |
+
|
87 |
+
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
|
88 |
+
|
89 |
+
# [Previous constants DISC_QUESTIONS and DISC_INSIGHTS remain the same]
|
90 |
+
|
91 |
def create_disc_plot(percentuais):
|
92 |
cores = {'D': '#FF4B4B', 'I': '#FFD700', 'S': '#4CAF50', 'C': '#2196F3'}
|
93 |
+
fig = go.Figure(data=[go.Bar(x=list(percentuais.keys()),
|
94 |
+
y=list(percentuais.values()),
|
95 |
marker_color=[cores[k] for k in percentuais.keys()],
|
96 |
text=[f'{v:.1f}%' for v in percentuais.values()],
|
97 |
+
textposition='auto')])
|
98 |
+
|
99 |
+
fig.update_layout(
|
100 |
+
title={
|
101 |
+
'text': 'Perfil DISC',
|
102 |
+
'y':0.95,
|
103 |
+
'x':0.5,
|
104 |
+
'xanchor': 'center',
|
105 |
+
'yanchor': 'top',
|
106 |
+
'font': {'size': 24, 'color': '#333333'}
|
107 |
+
},
|
108 |
+
yaxis_range=[0, 100],
|
109 |
+
template='plotly_white',
|
110 |
+
height=400,
|
111 |
+
margin=dict(l=40, r=40, t=60, b=40),
|
112 |
+
paper_bgcolor='rgba(0,0,0,0)',
|
113 |
+
plot_bgcolor='rgba(0,0,0,0)',
|
114 |
+
yaxis_title="Percentual (%)",
|
115 |
+
xaxis_title="Dimensões DISC"
|
116 |
+
)
|
117 |
+
|
118 |
+
return fig
|
119 |
|
120 |
def create_interface():
|
121 |
+
with gr.Blocks(theme=gr.themes.Soft(
|
122 |
+
primary_hue="blue",
|
123 |
+
secondary_hue="purple",
|
124 |
+
neutral_hue="slate",
|
125 |
+
font=["Inter", "ui-sans-serif", "system-ui"]
|
126 |
+
)) as iface:
|
127 |
+
gr.Markdown(
|
128 |
+
"""
|
129 |
+
# 🎯 Análise de Perfil DISC
|
130 |
+
### Descubra suas características comportamentais dominantes
|
131 |
+
|
132 |
+
Este teste ajuda a identificar seu estilo comportamental baseado na metodologia DISC:
|
133 |
+
- **D (Dominância)**: Foco em resultados e assertividade
|
134 |
+
- **I (Influência)**: Foco em relacionamentos e comunicação
|
135 |
+
- **S (Estabilidade)**: Foco em cooperação e consistência
|
136 |
+
- **C (Conformidade)**: Foco em qualidade e precisão
|
137 |
+
""")
|
138 |
|
139 |
+
with gr.Row():
|
140 |
+
with gr.Column():
|
141 |
+
radios = []
|
142 |
+
for i, q in enumerate(DISC_QUESTIONS):
|
143 |
+
with gr.Box():
|
144 |
+
radio = gr.Radio(
|
145 |
+
choices=[f"{p} - {d}" for p, d in q['opcoes']],
|
146 |
+
label=f"{i+1}. {q['pergunta']}",
|
147 |
+
container=True
|
148 |
+
)
|
149 |
+
radios.append(radio)
|
150 |
+
|
151 |
+
with gr.Row():
|
152 |
+
analyze_btn = gr.Button("📊 Analisar Perfil", size="lg", variant="primary")
|
153 |
+
reset_btn = gr.Button("🔄 Novo Teste", size="lg", variant="secondary")
|
154 |
+
|
155 |
+
with gr.Row():
|
156 |
+
with gr.Column():
|
157 |
+
plot = gr.Plot(label="Gráfico de Perfil DISC")
|
158 |
+
|
159 |
+
with gr.Row():
|
160 |
+
output = gr.Markdown()
|
161 |
+
|
162 |
def process_results(*answers):
|
163 |
+
if any(a is None for a in answers):
|
164 |
+
gr.Warning("Por favor, responda todas as questões antes de prosseguir.")
|
165 |
+
return None, None
|
166 |
+
|
167 |
+
perfil = calcular_perfil(answers)
|
168 |
+
plot = create_disc_plot(perfil)
|
169 |
+
report = gerar_relatorio(perfil)
|
170 |
+
|
171 |
+
return plot, report
|
172 |
|
173 |
+
analyze_btn.click(
|
174 |
+
fn=process_results,
|
175 |
+
inputs=radios,
|
176 |
+
outputs=[plot, output],
|
177 |
+
api_name="analyze"
|
178 |
+
)
|
179 |
+
|
180 |
+
reset_btn.click(
|
181 |
+
fn=lambda: [None]*(len(radios)+2),
|
182 |
+
outputs=radios+[plot, output],
|
183 |
+
api_name="reset"
|
184 |
+
)
|
185 |
+
|
186 |
+
# Add example inputs
|
187 |
+
gr.Examples(
|
188 |
+
examples=[
|
189 |
+
["D - Assume a liderança e toma decisões rápidas",
|
190 |
+
"I - Discute com outros e busca diferentes perspectivas",
|
191 |
+
"S - Ouvir atentamente e contribuir quando solicitado",
|
192 |
+
"C - Analisa os impactos antes de aceitar",
|
193 |
+
"D - Tornar-se mais direto e focado em resultados"]
|
194 |
+
],
|
195 |
+
inputs=radios,
|
196 |
+
outputs=[plot, output],
|
197 |
+
fn=process_results,
|
198 |
+
label="Exemplo de Respostas"
|
199 |
+
)
|
200 |
+
|
201 |
return iface
|
202 |
|
203 |
if __name__ == "__main__":
|
204 |
+
iface = create_interface()
|
205 |
+
iface.launch(
|
206 |
+
share=True,
|
207 |
+
show_error=True,
|
208 |
+
server_name="0.0.0.0",
|
209 |
+
server_port=7860,
|
210 |
+
)
|