Update app.py
Browse files
app.py
CHANGED
|
@@ -48,20 +48,27 @@ def gerar_pdf(valor_imovel, investimento_proprio, aluguel_mensal, tempo_anos, ta
|
|
| 48 |
|
| 49 |
return pdf_file_path
|
| 50 |
|
| 51 |
-
#
|
| 52 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
# Calcular ROI
|
| 54 |
roi, parcela_mensal, lucro = calcular_roi(valor_imovel, investimento_proprio, aluguel_mensal, tempo_anos, taxa_juros)
|
| 55 |
|
| 56 |
-
# Gerar PDF
|
| 57 |
pdf_path = gerar_pdf(valor_imovel, investimento_proprio, aluguel_mensal, tempo_anos, taxa_juros, roi, parcela_mensal, lucro)
|
| 58 |
|
| 59 |
-
|
| 60 |
-
return f"Aqui está o seu cálculo de ROI. Clique no link abaixo para baixar o PDF:", pdf_path
|
| 61 |
|
| 62 |
-
#
|
| 63 |
iface = gr.Interface(
|
| 64 |
-
fn=
|
| 65 |
inputs=[
|
| 66 |
gr.Number(label="Valor do Imóvel (R$)", value=500000),
|
| 67 |
gr.Number(label="Investimento Próprio (R$)", value=100000),
|
|
@@ -71,35 +78,26 @@ iface = gr.Interface(
|
|
| 71 |
],
|
| 72 |
outputs=[
|
| 73 |
gr.Textbox(label="Resultado do Cálculo do ROI", lines=3),
|
| 74 |
-
gr.File(label="Baixar PDF", elem_id="download-pdf")
|
| 75 |
],
|
| 76 |
live=True,
|
| 77 |
title="Cálculo de ROI de Aluguel",
|
| 78 |
-
description="Insira os valores abaixo e calcule o retorno sobre investimento (ROI) de aluguel."
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
.
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
font-size: 16px;
|
| 96 |
-
border-radius: 5px;
|
| 97 |
-
text-align: center;
|
| 98 |
-
}
|
| 99 |
-
#download-pdf:hover {
|
| 100 |
-
background-color: #0056b3;
|
| 101 |
-
}
|
| 102 |
-
"""
|
| 103 |
)
|
| 104 |
|
| 105 |
# Rodar a interface Gradio
|
|
@@ -107,4 +105,3 @@ iface.launch(share=True)
|
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
-
|
|
|
|
| 48 |
|
| 49 |
return pdf_file_path
|
| 50 |
|
| 51 |
+
# Função para o botão "Gerar ROI"
|
| 52 |
+
def calcular_gerar_roi(valor_imovel, investimento_proprio, aluguel_mensal, tempo_anos, taxa_juros):
|
| 53 |
+
# Calcular ROI
|
| 54 |
+
roi, parcela_mensal, lucro = calcular_roi(valor_imovel, investimento_proprio, aluguel_mensal, tempo_anos, taxa_juros)
|
| 55 |
+
|
| 56 |
+
# Exibir resultado
|
| 57 |
+
return f"ROI Calculado: {roi:.2f}%\nParcela Mensal: R$ {parcela_mensal:,.2f}\nLucro Total: R$ {lucro:,.2f}"
|
| 58 |
+
|
| 59 |
+
# Função para o botão "Gerar PDF"
|
| 60 |
+
def gerar_pdf_arquivo(valor_imovel, investimento_proprio, aluguel_mensal, tempo_anos, taxa_juros):
|
| 61 |
# Calcular ROI
|
| 62 |
roi, parcela_mensal, lucro = calcular_roi(valor_imovel, investimento_proprio, aluguel_mensal, tempo_anos, taxa_juros)
|
| 63 |
|
| 64 |
+
# Gerar o PDF com os dados
|
| 65 |
pdf_path = gerar_pdf(valor_imovel, investimento_proprio, aluguel_mensal, tempo_anos, taxa_juros, roi, parcela_mensal, lucro)
|
| 66 |
|
| 67 |
+
return pdf_path
|
|
|
|
| 68 |
|
| 69 |
+
# Interface Gradio
|
| 70 |
iface = gr.Interface(
|
| 71 |
+
fn=calcular_gerar_roi,
|
| 72 |
inputs=[
|
| 73 |
gr.Number(label="Valor do Imóvel (R$)", value=500000),
|
| 74 |
gr.Number(label="Investimento Próprio (R$)", value=100000),
|
|
|
|
| 78 |
],
|
| 79 |
outputs=[
|
| 80 |
gr.Textbox(label="Resultado do Cálculo do ROI", lines=3),
|
|
|
|
| 81 |
],
|
| 82 |
live=True,
|
| 83 |
title="Cálculo de ROI de Aluguel",
|
| 84 |
+
description="Insira os valores abaixo e calcule o retorno sobre investimento (ROI) de aluguel."
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
# Adicionando o botão de "Gerar PDF"
|
| 88 |
+
iface.add_button(
|
| 89 |
+
"Gerar PDF",
|
| 90 |
+
fn=gerar_pdf_arquivo,
|
| 91 |
+
inputs=[
|
| 92 |
+
gr.Number(label="Valor do Imóvel (R$)", value=500000),
|
| 93 |
+
gr.Number(label="Investimento Próprio (R$)", value=100000),
|
| 94 |
+
gr.Number(label="Aluguel Mensal (R$)", value=2500),
|
| 95 |
+
gr.Number(label="Tempo (anos)", value=20),
|
| 96 |
+
gr.Number(label="Taxa de Juros (%)", value=8)
|
| 97 |
+
],
|
| 98 |
+
outputs=[
|
| 99 |
+
gr.File(label="Baixar PDF")
|
| 100 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
)
|
| 102 |
|
| 103 |
# Rodar a interface Gradio
|
|
|
|
| 105 |
|
| 106 |
|
| 107 |
|
|
|