Spaces:
Sleeping
Sleeping
Update app.py
#2
by
fschwartzer
- opened
app.py
CHANGED
|
@@ -5,6 +5,33 @@ import gradio as gr
|
|
| 5 |
from gradio import components
|
| 6 |
from gradio import Interface
|
| 7 |
import xlsxwriter
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def renderizar_dataframe(df):
|
| 10 |
try:
|
|
@@ -444,8 +471,12 @@ def avaliacao_imovel(planilha, num_linhas_desejadas=10):
|
|
| 444 |
|
| 445 |
#-----------------#
|
| 446 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 447 |
# Retorna tanto a planilha quanto os resultados formatados
|
| 448 |
-
return 'relatório.xlsx', result_render, resultados_formatados, intervalo_confiança, valores_finais
|
| 449 |
|
| 450 |
|
| 451 |
# Interface do Gradio com input como arquivo XLS ou XLSX
|
|
@@ -457,6 +488,7 @@ interface = gr.Interface(
|
|
| 457 |
],
|
| 458 |
outputs=[
|
| 459 |
gr.components.File(label="Download planilha"),
|
|
|
|
| 460 |
gr.outputs.HTML(label="Resultado Renderizado"),
|
| 461 |
gr.components.Textbox(label="Resultados estatísticos"),
|
| 462 |
gr.components.Textbox(label="Intervalo de confiança de 80%"),
|
|
@@ -471,4 +503,4 @@ interface = gr.Interface(
|
|
| 471 |
|
| 472 |
# Executar o aplicativo Gradio
|
| 473 |
if __name__ == "__main__":
|
| 474 |
-
interface.launch()
|
|
|
|
| 5 |
from gradio import components
|
| 6 |
from gradio import Interface
|
| 7 |
import xlsxwriter
|
| 8 |
+
from reportlab.lib.pagesizes import letter
|
| 9 |
+
from reportlab.platypus import SimpleDocTemplate, Paragraph
|
| 10 |
+
from reportlab.lib.styles import getSampleStyleSheet
|
| 11 |
+
import shutil
|
| 12 |
+
|
| 13 |
+
# Function to save results in a PDF file
|
| 14 |
+
def save_results_to_pdf(results_formatados, intervalo_confiança, valores_finais):
|
| 15 |
+
doc = SimpleDocTemplate("resultados.pdf", pagesize=letter)
|
| 16 |
+
styles = getSampleStyleSheet()
|
| 17 |
+
|
| 18 |
+
# Create a list of elements to include in the PDF
|
| 19 |
+
elements = []
|
| 20 |
+
|
| 21 |
+
# Add the formatted results to the PDF
|
| 22 |
+
formatted_results = Paragraph(results_formatados, styles["Normal"])
|
| 23 |
+
elements.append(formatted_results)
|
| 24 |
+
|
| 25 |
+
# Add the intervalo de confianca to the PDF
|
| 26 |
+
confianca = Paragraph(intervalo_confiança, styles["Normal"])
|
| 27 |
+
elements.append(confianca)
|
| 28 |
+
|
| 29 |
+
# Add the valores calculados to the PDF
|
| 30 |
+
calculados = Paragraph(valores_finais, styles["Normal"])
|
| 31 |
+
elements.append(calculados)
|
| 32 |
+
|
| 33 |
+
# Build the PDF
|
| 34 |
+
doc.build(elements)
|
| 35 |
|
| 36 |
def renderizar_dataframe(df):
|
| 37 |
try:
|
|
|
|
| 471 |
|
| 472 |
#-----------------#
|
| 473 |
|
| 474 |
+
save_results_to_pdf(resultados_formatados, intervalo_confiança, valores_finais)
|
| 475 |
+
|
| 476 |
+
#-----------------#
|
| 477 |
+
|
| 478 |
# Retorna tanto a planilha quanto os resultados formatados
|
| 479 |
+
return 'relatório.xlsx', 'resultados.pdf', result_render, resultados_formatados, intervalo_confiança, valores_finais
|
| 480 |
|
| 481 |
|
| 482 |
# Interface do Gradio com input como arquivo XLS ou XLSX
|
|
|
|
| 488 |
],
|
| 489 |
outputs=[
|
| 490 |
gr.components.File(label="Download planilha"),
|
| 491 |
+
gr.components.File(label="Download Relatório em PDF"),
|
| 492 |
gr.outputs.HTML(label="Resultado Renderizado"),
|
| 493 |
gr.components.Textbox(label="Resultados estatísticos"),
|
| 494 |
gr.components.Textbox(label="Intervalo de confiança de 80%"),
|
|
|
|
| 503 |
|
| 504 |
# Executar o aplicativo Gradio
|
| 505 |
if __name__ == "__main__":
|
| 506 |
+
interface.launch(debug=True)
|