Persano commited on
Commit
fa92e71
·
verified ·
1 Parent(s): cc97f27

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -38
app.py CHANGED
@@ -66,46 +66,32 @@ def gerar_pdf_arquivo(valor_imovel, investimento_proprio, aluguel_mensal, tempo_
66
 
67
  return pdf_path
68
 
69
- # Interface Gradio
70
- def main_interface(valor_imovel, investimento_proprio, aluguel_mensal, tempo_anos, taxa_juros):
71
- roi_resultado = calcular_gerar_roi(valor_imovel, investimento_proprio, aluguel_mensal, tempo_anos, taxa_juros)
72
- return roi_resultado
73
-
74
- iface = gr.Interface(
75
- fn=main_interface,
76
- inputs=[
77
- gr.Number(label="Valor do Imóvel (R$)", value=500000),
78
- gr.Number(label="Investimento Próprio (R$)", value=100000),
79
- gr.Number(label="Aluguel Mensal (R$)", value=2500),
80
- gr.Number(label="Tempo (anos)", value=20),
81
- gr.Number(label="Taxa de Juros (%)", value=8)
82
- ],
83
- outputs=[
84
- gr.Textbox(label="Resultado do Cálculo do ROI", lines=3),
85
- ],
86
- live=True,
87
- title="Cálculo de ROI de Aluguel",
88
- description="Insira os valores abaixo e calcule o retorno sobre investimento (ROI) de aluguel."
89
- )
90
-
91
- # Criando o botão para gerar o PDF
92
- pdf_button = gr.Button("Gerar PDF", variant="primary")
93
-
94
- # Função de callback para o botão Gerar PDF
95
- def on_pdf_button_click(valor_imovel, investimento_proprio, aluguel_mensal, tempo_anos, taxa_juros):
96
- # Gerar PDF
97
- return gerar_pdf_arquivo(valor_imovel, investimento_proprio, aluguel_mensal, tempo_anos, taxa_juros)
98
-
99
- # Associando a função ao botão Gerar PDF
100
- pdf_button.click(on_pdf_button_click, inputs=[
101
- gr.Number(label="Valor do Imóvel (R$)", value=500000),
102
- gr.Number(label="Investimento Próprio (R$)", value=100000),
103
- gr.Number(label="Aluguel Mensal (R$)", value=2500),
104
- gr.Number(label="Tempo (anos)", value=20),
105
- gr.Number(label="Taxa de Juros (%)", value=8)
106
- ], outputs=[gr.File(label="Baixar PDF")])
107
 
108
  # Rodar a interface Gradio
109
  iface.launch(share=True)
110
 
111
 
 
 
66
 
67
  return pdf_path
68
 
69
+ # Interface Gradio com gr.Blocks
70
+ with gr.Blocks() as iface:
71
+ # Inputs para os dados
72
+ valor_imovel = gr.Number(label="Valor do Imóvel (R$)", value=500000)
73
+ investimento_proprio = gr.Number(label="Investimento Próprio (R$)", value=100000)
74
+ aluguel_mensal = gr.Number(label="Aluguel Mensal (R$)", value=2500)
75
+ tempo_anos = gr.Number(label="Tempo (anos)", value=20)
76
+ taxa_juros = gr.Number(label="Taxa de Juros (%)", value=8)
77
+
78
+ # Resultado do cálculo ROI
79
+ roi_resultado = gr.Textbox(label="Resultado do Cálculo do ROI", lines=3)
80
+
81
+ # Botão Gerar ROI
82
+ gerar_roi_button = gr.Button("Gerar ROI")
83
+ gerar_pdf_button = gr.Button("Gerar PDF")
84
+
85
+ # Funções de callback para os botões
86
+ gerar_roi_button.click(fn=calcular_gerar_roi, inputs=[valor_imovel, investimento_proprio, aluguel_mensal, tempo_anos, taxa_juros], outputs=roi_resultado)
87
+ gerar_pdf_button.click(fn=gerar_pdf_arquivo, inputs=[valor_imovel, investimento_proprio, aluguel_mensal, tempo_anos, taxa_juros], outputs=gr.File(label="Baixar PDF"))
88
+
89
+ # Configuração do tema e título
90
+ iface.title = "Cálculo de ROI de Aluguel"
91
+ iface.description = "Insira os valores abaixo e calcule o retorno sobre investimento (ROI) de aluguel."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
 
93
  # Rodar a interface Gradio
94
  iface.launch(share=True)
95
 
96
 
97
+