Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ import matplotlib.pyplot as plt
|
|
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,28 +151,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(
|
154 |
-
col_width = self.w / len(dataframe.columns)
|
155 |
-
row_height = self.font_size
|
156 |
|
157 |
-
#
|
|
|
158 |
for col in dataframe.columns:
|
159 |
-
self.cell
|
160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
|
162 |
-
# Adiciona os dados com
|
163 |
-
self.set_font(
|
164 |
for row in dataframe.itertuples(index=False):
|
165 |
-
for item in row:
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
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 +295,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")
|
296 |
output_html = gr.HTML()
|
297 |
-
|
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,
|
303 |
-
|
304 |
-
generate_btn.click(
|
305 |
-
|
306 |
-
|
|
|
|
|
|
|
|
|
|
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 |
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 |
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()
|