histlearn commited on
Commit
4e2a982
verified
1 Parent(s): d902312

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -25
app.py CHANGED
@@ -150,28 +150,30 @@ def generate_pdf_report(dataframe, media_tempo_medio_turma, output_pdf_path):
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,15 +294,18 @@ with gr.Blocks(theme=theme) as interface:
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()
 
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
 
155
+ # Calcular larguras din芒micas das colunas
156
+ col_widths = []
157
  for col in dataframe.columns:
158
+ max_width = max(self.get_string_width(str(cell)) for cell in dataframe[col])
159
+ col_widths.append(max_width + 4) # Adicionar um pequeno espa莽amento
160
+
161
+ row_height = self.font_size * 2
162
+
163
+ # Adiciona os cabe莽alhos
164
+ for i, col in enumerate(dataframe.columns):
165
+ self.cell(col_widths[i], row_height, col, border=1, align="C")
166
+ self.ln(row_height)
167
 
168
+ # Adiciona os dados com quebra de linha na coluna "Nome do Aluno"
169
+ self.set_font("Arial", "", 10)
170
  for row in dataframe.itertuples(index=False):
171
+ for i, item in enumerate(row):
172
+ if i == 0: # Coluna "Nome do Aluno"
173
+ self.multi_cell(col_widths[i], row_height, str(item), border=1, align="C", ln=3, max_line_height=row_height)
174
+ else:
175
+ self.cell(col_widths[i], row_height, str(item), border=1, align="C")
176
+ self.ln(row_height)
 
 
 
 
177
 
178
  def add_image(self, image_path):
179
  self.add_page()
 
294
  gr.Markdown("## Arquivos Excel (Relat贸rios de Tarefas)")
295
  excel_files = gr.Files(label="Arraste os arquivos .xlsx aqui", type="binary", file_count="multiple")
296
 
297
+ generate_btn = gr.Button("Gerar Relat贸rio", variant="primary")
298
  output_html = gr.HTML()
299
+ pdf_output = gr.File(label="Download PDF Report")
 
300
 
301
  def wrapper(html_file, excel_files):
302
  html_content, html_path, pdf_path = processar_relatorio(html_file, excel_files)
303
+ return {output_html: html_content, pdf_output: pdf_path}
304
+
305
+ generate_btn.click(
306
+ fn=wrapper,
307
+ inputs=[html_file, excel_files],
308
+ outputs=[output_html, pdf_output]
309
+ )
310
+
311
  interface.launch()