histlearn commited on
Commit
9422a26
verified
1 Parent(s): 6c7a189

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -32
app.py CHANGED
@@ -6,7 +6,6 @@ import matplotlib.pyplot as plt
6
  from datetime import timedelta
7
  from fpdf import FPDF
8
  import numpy as np
9
- import tabula
10
 
11
  def parse_duration(duration_str):
12
  try:
@@ -151,30 +150,28 @@ def generate_pdf_report(dataframe, media_tempo_medio_turma, output_pdf_path):
151
  self.cell(0, 10, f'Page {self.page_no()}', 0, 0, 'C')
152
 
153
  def add_table(self, dataframe):
154
- self.set_font("Arial", "B", 10)
155
-
156
- # Calcular larguras din芒micas das colunas
157
- col_widths = []
158
- for col in dataframe.columns:
159
- max_width = max(self.get_string_width(str(cell)) for cell in dataframe[col])
160
- col_widths.append(max_width + 4) # Adicionar um pequeno espa莽amento
161
-
162
- row_height = self.font_size * 2
163
 
164
  # Adiciona os cabe莽alhos
165
- for i, col in enumerate(dataframe.columns):
166
- self.cell(col_widths[i], row_height, col, border=1, align="C")
167
- self.ln(row_height)
168
 
169
- # Adiciona os dados com quebra de linha na coluna "Nome do Aluno"
170
- self.set_font("Arial", "", 10)
171
  for row in dataframe.itertuples(index=False):
172
- for i, item in enumerate(row):
173
- if i == 0: # Coluna "Nome do Aluno"
174
- self.multi_cell(col_widths[i], row_height, str(item), border=1, align="C")
175
- else:
176
- self.cell(col_widths[i], row_height, str(item), border=1, align="C")
177
- self.ln(row_height)
 
 
 
 
178
 
179
  def add_image(self, image_path):
180
  self.add_page()
@@ -295,18 +292,15 @@ with gr.Blocks(theme=theme) as interface:
295
  gr.Markdown("## Arquivos Excel (Relat贸rios de Tarefas)")
296
  excel_files = gr.Files(label="Arraste os arquivos .xlsx aqui", type="binary", file_count="multiple")
297
 
298
- generate_btn = gr.Button("Gerar Relat贸rio", variant="primary")
299
  output_html = gr.HTML()
300
- pdf_output = gr.File(label="Download PDF Report")
 
301
 
302
  def wrapper(html_file, excel_files):
303
  html_content, html_path, pdf_path = processar_relatorio(html_file, excel_files)
304
- return {output_html: html_content, pdf_output: pdf_path}
305
-
306
- generate_btn.click(
307
- fn=wrapper,
308
- inputs=[html_file, excel_files],
309
- outputs=[output_html, pdf_output]
310
- )
311
-
312
- interface.launch()
 
6
  from datetime import timedelta
7
  from fpdf import FPDF
8
  import numpy as np
 
9
 
10
  def parse_duration(duration_str):
11
  try:
 
150
  self.cell(0, 10, f'Page {self.page_no()}', 0, 0, 'C')
151
 
152
  def add_table(self, dataframe):
153
+ self.set_font('Arial', 'B', 10)
154
+ col_width = self.w / len(dataframe.columns)
155
+ row_height = self.font_size
 
 
 
 
 
 
156
 
157
  # Adiciona os cabe莽alhos
158
+ for col in dataframe.columns:
159
+ self.cell(col_width, row_height * 2, col, border=1)
160
+ self.ln(row_height * 2)
161
 
162
+ # Adiciona os dados com quebras de p谩gina
163
+ self.set_font('Arial', '', 10)
164
  for row in dataframe.itertuples(index=False):
165
+ for item in row:
166
+ self.cell(col_width, row_height * 2, str(item), border=1)
167
+ self.ln(row_height * 2)
168
+ if self.get_y() > self.page_break_trigger - 2 * row_height:
169
+ self.add_page()
170
+ self.set_font('Arial', 'B', 10)
171
+ for col in dataframe.columns:
172
+ self.cell(col_width, row_height * 2, col, border=1)
173
+ self.ln(row_height * 2)
174
+ self.set_font('Arial', '', 10)
175
 
176
  def add_image(self, image_path):
177
  self.add_page()
 
292
  gr.Markdown("## Arquivos Excel (Relat贸rios de Tarefas)")
293
  excel_files = gr.Files(label="Arraste os arquivos .xlsx aqui", type="binary", file_count="multiple")
294
 
295
+ generate_btn = gr.Button("Gerar Relat贸rio", variant="primary") # Destaque no bot茫o
296
  output_html = gr.HTML()
297
+ download_html_btn = gr.File(label="Download HTML Report")
298
+ download_pdf_btn = gr.File(label="Download PDF Report")
299
 
300
  def wrapper(html_file, excel_files):
301
  html_content, html_path, pdf_path = processar_relatorio(html_file, excel_files)
302
+ return html_content, html_path, pdf_path
303
+
304
+ generate_btn.click(fn=wrapper, inputs=[html_file, excel_files], outputs=[output_html, download_html_btn, download_pdf_btn])
305
+
306
+ interface.launch()