histlearn commited on
Commit
5b6efc0
·
verified ·
1 Parent(s): 77049fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +124 -124
app.py CHANGED
@@ -583,136 +583,136 @@ class ReportGenerator:
583
  """
584
  pdf.multi_cell(0, 7, recom_text)
585
 
586
- def process_files(html_file, excel_files) -> Tuple[str, str, str]:
587
- """Processa arquivos e gera relatório."""
588
- try:
589
- temp_dir = "temp_files"
590
- os.makedirs(temp_dir, exist_ok=True)
591
-
592
- # Limpar diretório temporário
593
- for file in os.listdir(temp_dir):
594
- os.remove(os.path.join(temp_dir, file))
595
-
596
- # Salvar arquivos
597
- html_path = os.path.join(temp_dir, "alunos.htm")
598
- with open(html_path, "wb") as f:
599
- f.write(html_file)
600
-
601
- # Processar arquivos Excel
602
- excel_paths = []
603
- for i, excel_file in enumerate(excel_files):
604
- excel_path = os.path.join(temp_dir, f"tarefa_{i}.xlsx")
605
- with open(excel_path, "wb") as f:
606
- f.write(excel_file)
607
- excel_paths.append(excel_path)
608
-
609
- # Processar arquivos
610
- processor = DataProcessor()
611
- alunos_csv_path = os.path.join(temp_dir, "alunos.csv")
612
- processor.normalize_html_to_csv(html_path, alunos_csv_path)
613
-
614
- # Concatenar dados das tarefas
615
- tarefas_df = pd.DataFrame()
616
- for excel_path in excel_paths:
617
- csv_path = excel_path.replace('.xlsx', '.csv')
618
- processor.normalize_excel_to_csv(excel_path, csv_path)
619
- df = pd.read_csv(csv_path)
620
- tarefas_df = pd.concat([tarefas_df, df], ignore_index=True)
621
-
622
- # Análise e geração de relatório
623
- alunos_df = pd.read_csv(alunos_csv_path)
624
- analyzer = StudentAnalyzer(tarefas_df, alunos_df)
625
- results_df = analyzer.prepare_data()
626
-
627
- report_generator = ReportGenerator(results_df)
628
- graphs = report_generator.generate_graphs()
629
 
630
- # Salvar outputs
631
- output_html = os.path.join(temp_dir, "relatorio.html")
632
- output_pdf = os.path.join(temp_dir, "relatorio.pdf")
633
- results_df.to_html(output_html, index=False)
634
- report_generator.generate_pdf(output_pdf, graphs)
635
-
636
- return results_df.to_html(index=False), output_html, output_pdf
637
-
638
- except Exception as e:
639
- logging.error(f"Erro no processamento: {str(e)}")
640
- raise
641
-
642
- def create_interface():
643
- """Cria a interface Gradio."""
644
- theme = gr.themes.Default(
645
- primary_hue="blue",
646
- secondary_hue="gray",
647
- font=["Arial", "sans-serif"],
648
- font_mono=["Courier New", "monospace"],
649
- )
650
-
651
- with gr.Blocks(theme=theme) as interface:
652
- gr.Markdown("""
653
- # Sistema de Análise de Desempenho Acadêmico
654
 
655
- Este sistema analisa o desempenho dos alunos e gera um relatório detalhado com:
656
- - Análise estatística completa
657
- - Visualizações gráficas
658
- - Recomendações personalizadas
659
- """)
660
 
661
- with gr.Row():
662
- with gr.Column():
663
- gr.Markdown("## Lista de Alunos")
664
- html_file = gr.File(
665
- label="Arquivo HTML com lista de alunos (.htm)",
666
- type="binary",
667
- file_types=[".htm", ".html"]
668
- )
669
 
670
- with gr.Column():
671
- gr.Markdown("## Relatórios de Tarefas")
672
- excel_files = gr.Files(
673
- label="Arquivos Excel com dados das tarefas (.xlsx)",
674
- type="binary",
675
- file_count="multiple",
676
- file_types=[".xlsx"]
677
- )
678
-
679
- with gr.Row():
680
- generate_btn = gr.Button(
681
- "Gerar Relatório",
682
- variant="primary",
683
- size="lg"
684
  )
 
 
 
 
 
 
 
685
 
686
- with gr.Row():
687
- output_html = gr.HTML()
688
 
689
- with gr.Row():
690
- with gr.Column():
691
- download_html_btn = gr.File(
692
- label="Download Relatório HTML",
693
- type="filepath",
694
- interactive=False
695
- )
696
- with gr.Column():
697
- download_pdf_btn = gr.File(
698
- label="Download Relatório PDF",
699
- type="filepath",
700
- interactive=False
701
- )
702
-
703
- generate_btn.click(
704
- fn=process_files,
705
- inputs=[html_file, excel_files],
706
- outputs=[output_html, download_html_btn, download_pdf_btn]
707
- )
708
 
709
- return interface
710
 
711
- if __name__ == "__main__":
712
- interface = create_interface()
713
- interface.launch(
714
- share=False,
715
- server_name="0.0.0.0",
716
- server_port=7860,
717
- show_error=True
718
- )
 
583
  """
584
  pdf.multi_cell(0, 7, recom_text)
585
 
586
+ def process_files(html_file, excel_files) -> Tuple[str, str, str]:
587
+ """Processa arquivos e gera relatório."""
588
+ try:
589
+ temp_dir = "temp_files"
590
+ os.makedirs(temp_dir, exist_ok=True)
591
+
592
+ # Limpar diretório temporário
593
+ for file in os.listdir(temp_dir):
594
+ os.remove(os.path.join(temp_dir, file))
595
+
596
+ # Salvar arquivos
597
+ html_path = os.path.join(temp_dir, "alunos.htm")
598
+ with open(html_path, "wb") as f:
599
+ f.write(html_file)
600
+
601
+ # Processar arquivos Excel
602
+ excel_paths = []
603
+ for i, excel_file in enumerate(excel_files):
604
+ excel_path = os.path.join(temp_dir, f"tarefa_{i}.xlsx")
605
+ with open(excel_path, "wb") as f:
606
+ f.write(excel_file)
607
+ excel_paths.append(excel_path)
608
+
609
+ # Processar arquivos
610
+ processor = DataProcessor()
611
+ alunos_csv_path = os.path.join(temp_dir, "alunos.csv")
612
+ processor.normalize_html_to_csv(html_path, alunos_csv_path)
613
+
614
+ # Concatenar dados das tarefas
615
+ tarefas_df = pd.DataFrame()
616
+ for excel_path in excel_paths:
617
+ csv_path = excel_path.replace('.xlsx', '.csv')
618
+ processor.normalize_excel_to_csv(excel_path, csv_path)
619
+ df = pd.read_csv(csv_path)
620
+ tarefas_df = pd.concat([tarefas_df, df], ignore_index=True)
621
+
622
+ # Análise e geração de relatório
623
+ alunos_df = pd.read_csv(alunos_csv_path)
624
+ analyzer = StudentAnalyzer(tarefas_df, alunos_df)
625
+ results_df = analyzer.prepare_data()
626
+
627
+ report_generator = ReportGenerator(results_df)
628
+ graphs = report_generator.generate_graphs()
629
 
630
+ # Salvar outputs
631
+ output_html = os.path.join(temp_dir, "relatorio.html")
632
+ output_pdf = os.path.join(temp_dir, "relatorio.pdf")
633
+ results_df.to_html(output_html, index=False)
634
+ report_generator.generate_pdf(output_pdf, graphs)
635
+
636
+ return results_df.to_html(index=False), output_html, output_pdf
637
+
638
+ except Exception as e:
639
+ logging.error(f"Erro no processamento: {str(e)}")
640
+ raise
641
+
642
+ def create_interface():
643
+ """Cria a interface Gradio."""
644
+ theme = gr.themes.Default(
645
+ primary_hue="blue",
646
+ secondary_hue="gray",
647
+ font=["Arial", "sans-serif"],
648
+ font_mono=["Courier New", "monospace"],
649
+ )
650
+
651
+ with gr.Blocks(theme=theme) as interface:
652
+ gr.Markdown("""
653
+ # Sistema de Análise de Desempenho Acadêmico
654
 
655
+ Este sistema analisa o desempenho dos alunos e gera um relatório detalhado com:
656
+ - Análise estatística completa
657
+ - Visualizações gráficas
658
+ - Recomendações personalizadas
659
+ """)
660
 
661
+ with gr.Row():
662
+ with gr.Column():
663
+ gr.Markdown("## Lista de Alunos")
664
+ html_file = gr.File(
665
+ label="Arquivo HTML com lista de alunos (.htm)",
666
+ type="binary",
667
+ file_types=[".htm", ".html"]
668
+ )
669
 
670
+ with gr.Column():
671
+ gr.Markdown("## Relatórios de Tarefas")
672
+ excel_files = gr.Files(
673
+ label="Arquivos Excel com dados das tarefas (.xlsx)",
674
+ type="binary",
675
+ file_count="multiple",
676
+ file_types=[".xlsx"]
 
 
 
 
 
 
 
677
  )
678
+
679
+ with gr.Row():
680
+ generate_btn = gr.Button(
681
+ "Gerar Relatório",
682
+ variant="primary",
683
+ size="lg"
684
+ )
685
 
686
+ with gr.Row():
687
+ output_html = gr.HTML()
688
 
689
+ with gr.Row():
690
+ with gr.Column():
691
+ download_html_btn = gr.File(
692
+ label="Download Relatório HTML",
693
+ type="filepath",
694
+ interactive=False
695
+ )
696
+ with gr.Column():
697
+ download_pdf_btn = gr.File(
698
+ label="Download Relatório PDF",
699
+ type="filepath",
700
+ interactive=False
701
+ )
702
+
703
+ generate_btn.click(
704
+ fn=process_files,
705
+ inputs=[html_file, excel_files],
706
+ outputs=[output_html, download_html_btn, download_pdf_btn]
707
+ )
708
 
709
+ return interface
710
 
711
+ if __name__ == "__main__":
712
+ interface = create_interface()
713
+ interface.launch(
714
+ share=False,
715
+ server_name="0.0.0.0",
716
+ server_port=7860,
717
+ show_error=True
718
+ )