Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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(
|
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 +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")
|
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 |
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()
|