DHEIVER commited on
Commit
5bfab3a
·
verified ·
1 Parent(s): ea388f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +205 -31
app.py CHANGED
@@ -290,35 +290,209 @@ def processar_questionario(*args):
290
 
291
  # Manter o resto do código original (interface Gradio) como está...
292
 
293
- # Interface Gradio
294
- with gr.Blocks(title="Análise de Perfil DISC") as iface:
295
- gr.Markdown("# Análise de Perfil Comportamental DISC")
296
- gr.Markdown("### Responda às questões abaixo conforme seu comportamento mais natural")
297
-
298
- # Lista para armazenar os componentes de rádio
299
- radio_components = []
300
-
301
- # Criar questões
302
- for i, questao in enumerate(DISC_QUESTIONS):
303
- gr.Markdown(f"### {questao['pergunta']}")
304
- radio = gr.Radio(
305
- choices=[f"{perfil} - {desc}" for perfil, desc in questao['opcoes']],
306
- label=f"Questão {i+1}"
307
- )
308
- radio_components.append(radio)
309
-
310
- # Saída
311
- output = gr.Textbox(label="Relatório de Perfil DISC", lines=20)
312
-
313
- # Botão
314
- btn = gr.Button("Gerar Relatório")
315
-
316
- # Conectar função aos componentes
317
- btn.click(
318
- fn=processar_questionario,
319
- inputs=radio_components,
320
- outputs=output
321
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322
 
323
- # Iniciar a interface
324
- iface.launch()
 
 
 
290
 
291
  # Manter o resto do código original (interface Gradio) como está...
292
 
293
+ import gradio as gr
294
+ from sentence_transformers import SentenceTransformer
295
+ import numpy as np
296
+
297
+ # Manter a base DISC_PROFILES do código anterior...
298
+
299
+ # Temas e estilos personalizados
300
+ CUSTOM_CSS = """
301
+ .container {
302
+ max-width: 800px;
303
+ margin: auto;
304
+ }
305
+ .question-card {
306
+ padding: 20px;
307
+ margin: 15px 0;
308
+ border-radius: 10px;
309
+ background-color: #f8f9fa;
310
+ }
311
+ .result-card {
312
+ padding: 25px;
313
+ margin-top: 20px;
314
+ border-radius: 10px;
315
+ background-color: #ffffff;
316
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
317
+ }
318
+ """
319
+
320
+ THEME = gr.themes.Soft(
321
+ primary_hue="blue",
322
+ secondary_hue="gray",
323
+ neutral_hue="slate",
324
+ font=["Source Sans Pro", "ui-sans-serif", "system-ui"]
325
+ ).set(
326
+ button_primary_background_fill="*primary_500",
327
+ button_primary_background_fill_hover="*primary_600",
328
+ button_secondary_background_fill="*neutral_100",
329
+ block_label_text_size="lg",
330
+ block_title_text_size="xl",
331
+ )
332
+
333
+ # Componente de progresso
334
+ def update_progress(progress, total_questions=5):
335
+ """Atualiza a barra de progresso."""
336
+ answered = sum(1 for p in progress if p is not None)
337
+ return f"{answered}/{total_questions} questões respondidas", answered / total_questions
338
+
339
+ def create_interface():
340
+ """Cria interface moderna do Gradio."""
341
+ with gr.Blocks(theme=THEME, css=CUSTOM_CSS) as iface:
342
+ # Cabeçalho
343
+ with gr.Row():
344
+ with gr.Column():
345
+ gr.Markdown("""
346
+ # 🎯 Análise de Perfil Comportamental DISC
347
+ Descubra seu perfil comportamental respondendo às questões abaixo.
348
+ Escolha as opções que melhor representam seu comportamento natural.
349
+ """)
350
+
351
+ # Container principal
352
+ with gr.Column(elem_classes="container"):
353
+ # Barra de progresso
354
+ with gr.Row():
355
+ progress_text = gr.Markdown("0/5 questões respondidas")
356
+ progress_bar = gr.Progress()
357
+
358
+ # Questões
359
+ radio_components = []
360
+ for i, questao in enumerate(DISC_QUESTIONS, 1):
361
+ with gr.Box(elem_classes="question-card"):
362
+ gr.Markdown(f"### Questão {i}: {questao['pergunta']}")
363
+ radio = gr.Radio(
364
+ choices=[f"{perfil} - {desc}" for perfil, desc in questao['opcoes']],
365
+ label="Selecione a opção mais adequada",
366
+ scale=0,
367
+ interactive=True
368
+ )
369
+ radio_components.append(radio)
370
+
371
+ # Botão de análise
372
+ with gr.Row():
373
+ analyze_btn = gr.Button(
374
+ "Analisar Perfil",
375
+ variant="primary",
376
+ scale=0,
377
+ min_width=200
378
+ )
379
+
380
+ # Área de resultados
381
+ with gr.Box(visible=False, elem_classes="result-card") as result_box:
382
+ gr.Markdown("### 📊 Resultado da Análise")
383
+
384
+ with gr.Row():
385
+ # Gráfico de distribuição
386
+ plot = gr.Plot(label="Distribuição DISC")
387
+
388
+ # Métricas principais
389
+ with gr.Column():
390
+ perfil_dominante = gr.Textbox(
391
+ label="Perfil Dominante",
392
+ show_label=True,
393
+ interactive=False
394
+ )
395
+ perfil_secundario = gr.Textbox(
396
+ label="Perfil Secundário",
397
+ show_label=True,
398
+ interactive=False
399
+ )
400
+
401
+ # Relatório detalhado
402
+ with gr.Accordion("📝 Relatório Detalhado", open=True):
403
+ output = gr.Markdown()
404
+
405
+ # Botões de ação
406
+ with gr.Row():
407
+ reset_btn = gr.Button("🔄 Reiniciar", variant="secondary")
408
+ download_btn = gr.Button("⬇️ Download PDF", variant="secondary")
409
+
410
+ # Lógica de atualização da interface
411
+ def update_display(*answers):
412
+ if all(a is not None for a in answers):
413
+ return {
414
+ result_box: gr.update(visible=True),
415
+ analyze_btn: gr.update(interactive=False)
416
+ }
417
+ return {
418
+ result_box: gr.update(visible=False),
419
+ analyze_btn: gr.update(interactive=True)
420
+ }
421
+
422
+ # Funções de processamento
423
+ def process_and_visualize(*answers):
424
+ """Processa respostas e gera visualizações."""
425
+ percentuais = calcular_perfil(answers)
426
+
427
+ # Criar gráfico
428
+ fig = create_disc_plot(percentuais)
429
+
430
+ # Gerar relatório
431
+ report = gerar_relatorio_personalizado(percentuais)
432
+
433
+ # Identificar perfis principais
434
+ sorted_profiles = dict(sorted(percentuais.items(), key=lambda x: x[1], reverse=True))
435
+ main_profile = list(sorted_profiles.keys())[0]
436
+ secondary_profile = list(sorted_profiles.keys())[1]
437
+
438
+ return {
439
+ plot: fig,
440
+ perfil_dominante: f"{main_profile} ({sorted_profiles[main_profile]:.1f}%)",
441
+ perfil_secundario: f"{secondary_profile} ({sorted_profiles[secondary_profile]:.1f}%)",
442
+ output: report
443
+ }
444
+
445
+ def reset_interface():
446
+ """Reinicia a interface."""
447
+ return [None] * len(radio_components) + [
448
+ gr.update(visible=False),
449
+ gr.update(interactive=True),
450
+ None, None, None, None,
451
+ "0/5 questões respondidas"
452
+ ]
453
+
454
+ # Event listeners
455
+ for radio in radio_components:
456
+ radio.change(
457
+ lambda *args: update_progress(args),
458
+ inputs=radio_components,
459
+ outputs=[progress_text, progress_bar]
460
+ )
461
+ radio.change(
462
+ update_display,
463
+ inputs=radio_components,
464
+ outputs=[result_box, analyze_btn]
465
+ )
466
+
467
+ analyze_btn.click(
468
+ process_and_visualize,
469
+ inputs=radio_components,
470
+ outputs=[plot, perfil_dominante, perfil_secundario, output]
471
+ )
472
+
473
+ reset_btn.click(
474
+ reset_interface,
475
+ outputs=radio_components + [
476
+ result_box,
477
+ analyze_btn,
478
+ plot,
479
+ perfil_dominante,
480
+ perfil_secundario,
481
+ output,
482
+ progress_text
483
+ ]
484
+ )
485
+
486
+ # Download handler (exemplo simples)
487
+ download_btn.click(
488
+ lambda x: f"disc_report_{x}.pdf",
489
+ inputs=[perfil_dominante],
490
+ outputs=gr.File()
491
+ )
492
+
493
+ return iface
494
 
495
+ # Criar e lançar a interface
496
+ if __name__ == "__main__":
497
+ iface = create_interface()
498
+ iface.launch(share=True)