histlearn commited on
Commit
314a79c
verified
1 Parent(s): 4f229bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -28
app.py CHANGED
@@ -284,43 +284,42 @@ theme = gr.themes.Default(
284
  # --- Interface Gradio ---
285
  with gr.Blocks(theme=theme) as interface:
286
  gr.Markdown("# Processamento de Relat贸rios de Tarefas")
 
 
 
 
 
 
 
 
 
 
 
287
  with gr.Row(): # Crie uma nova linha para os bot玫es
288
  download_html_btn = gr.Button("Baixar Relat贸rio HTML")
289
  download_pdf_btn = gr.Button("Baixar Relat贸rio PDF")
290
- pdf_output = gr.File(label="Download PDF Report", visible=False, elem_id="pdf_output")
291
- html_output = gr.File(label="Download HTML Report", visible=False, elem_id="html_output")
292
 
293
  def wrapper(html_file, excel_files):
294
  html_content, html_path, pdf_path = processar_relatorio(html_file, excel_files)
295
- return {
296
- output_html: html_path, # Retorna o caminho do arquivo HTML
297
- pdf_output: pdf_path, # Retorna o caminho do PDF para o componente oculto
298
- }
299
 
 
300
  generate_btn.click(
301
  fn=wrapper,
302
  inputs=[html_file, excel_files],
303
- outputs=[html_output, pdf_output]
 
 
 
 
 
 
 
 
 
 
 
 
304
  )
305
 
306
- # Workaround for older Gradio versions
307
- download_html_btn.click(None, [], [], _js="downloadHTML")
308
- download_pdf_btn.click(None, [], [], _js="downloadPDF")
309
-
310
- interface.launch(
311
- _js="""
312
- function downloadHTML() {
313
- const a = document.createElement('a');
314
- a.href = document.getElementById('html_output').href;
315
- a.download = 'relatorio_final.html';
316
- a.click();
317
- }
318
-
319
- function downloadPDF() {
320
- const a = document.createElement('a');
321
- a.href = document.getElementById('pdf_output').href;
322
- a.download = 'relatorio_final.pdf';
323
- a.click();
324
- }
325
- """
326
- )
 
284
  # --- Interface Gradio ---
285
  with gr.Blocks(theme=theme) as interface:
286
  gr.Markdown("# Processamento de Relat贸rios de Tarefas")
287
+ with gr.Row():
288
+ with gr.Column():
289
+ gr.Markdown("## Arquivo HTML (alunos.htm)")
290
+ html_file = gr.File(label="Arraste o arquivo .htm aqui", type="binary")
291
+ with gr.Column():
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
+ pdf_output = gr.File(label="Download PDF Report", visible=False, elem_id="pdf_output")
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
+ # Move the button click events inside the gr.Blocks() context
307
  generate_btn.click(
308
  fn=wrapper,
309
  inputs=[html_file, excel_files],
310
+ outputs=[output_html, pdf_output]
311
+ )
312
+ download_html_btn.click(
313
+ None,
314
+ [],
315
+ [],
316
+ _js="() => {const a = document.createElement('a'); a.href = document.getElementById('html_output').href; a.download = 'relatorio_final.html'; a.click();}"
317
+ )
318
+ download_pdf_btn.click(
319
+ None,
320
+ [],
321
+ [],
322
+ _js="() => {const a = document.createElement('a'); a.href = document.getElementById('pdf_output').href; a.download = 'relatorio_final.pdf'; a.click();}"
323
  )
324
 
325
+ interface.launch()