Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -52,7 +52,7 @@ def match_alunos(tarefas_csv_path, alunos_csv_path, contador_csv_path):
|
|
52 |
tarefas_df.columns = tarefas_df.columns.str.strip()
|
53 |
alunos_df.columns = alunos_df.columns.str.strip()
|
54 |
|
55 |
-
if 'Aluno' not in tarefas_df.columns or 'Nota' not in tarefas_df.columns
|
56 |
print(f"Colunas 'Aluno', 'Nota' ou 'Duração' não encontradas no arquivo {tarefas_csv_path}. Pulando este arquivo.")
|
57 |
return
|
58 |
|
@@ -151,12 +151,12 @@ def generate_pdf_report(dataframe, media_tempo_medio_turma, output_pdf_path):
|
|
151 |
|
152 |
def add_table(self, dataframe):
|
153 |
self.set_font('Arial', 'B', 10)
|
154 |
-
col_widths = [30,
|
155 |
row_height = self.font_size * 2
|
156 |
|
157 |
# Adiciona os cabeçalhos
|
158 |
for i, col in enumerate(dataframe.columns):
|
159 |
-
self.
|
160 |
self.ln(row_height)
|
161 |
|
162 |
# Adiciona os dados com quebras de página
|
@@ -166,11 +166,11 @@ def generate_pdf_report(dataframe, media_tempo_medio_turma, output_pdf_path):
|
|
166 |
self.add_page()
|
167 |
self.set_font('Arial', 'B', 10)
|
168 |
for i, col in enumerate(dataframe.columns):
|
169 |
-
self.
|
170 |
self.ln(row_height)
|
171 |
self.set_font('Arial', '', 10)
|
172 |
for i, item in enumerate(row):
|
173 |
-
self.
|
174 |
self.ln(row_height)
|
175 |
|
176 |
def add_image(self, image_path):
|
@@ -271,7 +271,7 @@ def processar_relatorio(html_file, tarefa_files):
|
|
271 |
pdf_output_path = os.path.join(output_directory, "relatorio_final.pdf")
|
272 |
generate_pdf_report(df, media_tempo_medio_turma, pdf_output_path)
|
273 |
|
274 |
-
return df.to_html(index=False),
|
275 |
|
276 |
# Tema personalizado
|
277 |
theme = gr.themes.Default(
|
@@ -294,13 +294,30 @@ with gr.Blocks(theme=theme) as interface:
|
|
294 |
|
295 |
generate_btn = gr.Button("Gerar Relatório", variant="primary") # Destaque no botão
|
296 |
output_html = gr.HTML()
|
297 |
-
|
298 |
-
|
|
|
|
|
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(
|
305 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
306 |
interface.launch()
|
|
|
52 |
tarefas_df.columns = tarefas_df.columns.str.strip()
|
53 |
alunos_df.columns = alunos_df.columns.str.strip()
|
54 |
|
55 |
+
if 'Aluno' not in tarefas_df.columns or 'Nota' not in tarefas_df.columns ou 'Duração' não in tarefas_df.columns:
|
56 |
print(f"Colunas 'Aluno', 'Nota' ou 'Duração' não encontradas no arquivo {tarefas_csv_path}. Pulando este arquivo.")
|
57 |
return
|
58 |
|
|
|
151 |
|
152 |
def add_table(self, dataframe):
|
153 |
self.set_font('Arial', 'B', 10)
|
154 |
+
col_widths = [30, 40, 40, 30, 30, 40]
|
155 |
row_height = self.font_size * 2
|
156 |
|
157 |
# Adiciona os cabeçalhos
|
158 |
for i, col in enumerate(dataframe.columns):
|
159 |
+
self.multi_cell(col_widths[i], row_height, col, border=1, align='C', ln=3)
|
160 |
self.ln(row_height)
|
161 |
|
162 |
# Adiciona os dados com quebras de página
|
|
|
166 |
self.add_page()
|
167 |
self.set_font('Arial', 'B', 10)
|
168 |
for i, col in enumerate(dataframe.columns):
|
169 |
+
self.multi_cell(col_widths[i], row_height, col, border=1, align='C', ln=3)
|
170 |
self.ln(row_height)
|
171 |
self.set_font('Arial', '', 10)
|
172 |
for i, item in enumerate(row):
|
173 |
+
self.multi_cell(col_widths[i], row_height, str(item), border=1, align='C', ln=3)
|
174 |
self.ln(row_height)
|
175 |
|
176 |
def add_image(self, image_path):
|
|
|
271 |
pdf_output_path = os.path.join(output_directory, "relatorio_final.pdf")
|
272 |
generate_pdf_report(df, media_tempo_medio_turma, pdf_output_path)
|
273 |
|
274 |
+
return df.to_html(index=False), html_path, pdf_path
|
275 |
|
276 |
# Tema personalizado
|
277 |
theme = gr.themes.Default(
|
|
|
294 |
|
295 |
generate_btn = gr.Button("Gerar Relatório", variant="primary") # Destaque no botão
|
296 |
output_html = gr.HTML()
|
297 |
+
|
298 |
+
with gr.Row(): # Crie uma nova linha para os botões
|
299 |
+
download_html_btn = gr.Button("Baixar Relatório HTML")
|
300 |
+
download_pdf_btn = gr.Button("Baixar Relatório PDF")
|
301 |
|
302 |
def wrapper(html_file, excel_files):
|
303 |
html_content, html_path, pdf_path = processar_relatorio(html_file, excel_files)
|
304 |
return html_content, html_path, pdf_path
|
305 |
|
306 |
+
generate_btn.click(
|
307 |
+
fn=wrapper,
|
308 |
+
inputs=[html_file, excel_files],
|
309 |
+
outputs=[output_html, download_html_btn, download_pdf_btn]
|
310 |
+
)
|
311 |
+
download_html_btn.click(
|
312 |
+
fn=None,
|
313 |
+
inputs=None,
|
314 |
+
outputs=None,
|
315 |
+
_js="(x) => window.location.href = x[1]", # Define a ação JavaScript para download
|
316 |
+
)
|
317 |
+
download_pdf_btn.click(
|
318 |
+
fn=None,
|
319 |
+
inputs=None,
|
320 |
+
outputs=None,
|
321 |
+
_js="(x) => window.location.href = x[2]", # Define a ação JavaScript para download
|
322 |
+
)
|
323 |
interface.launch()
|