Spaces:
Sleeping
Sleeping
File size: 5,782 Bytes
75d2e54 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
import gradio as gr
import pandas as pd
from datetime import datetime
from gradio.components import Number, Textbox, Dropdown, Button
import warnings
from gradio import Interface # Certifique-se de importar o módulo corretamente
# Suprimir todos os avisos durante a execução do script
warnings.filterwarnings("ignore")
def calcular_valor_imovel(area=100, data_refer_str=None, data_const_str="12/2022", tipo_cub="R 1-N (Res. Unifamiliar)", data_cub_str=None, percentual_cub=1, BDI=22.5, tipologia="APARTAMENTOS", estado="B - entre novo e regular", VR=0.2):
# Carregar dados dos arquivos Excel
df_cub = pd.read_excel('TABELAS.xlsx', sheet_name='CUB')
df_vida = pd.read_excel('TABELAS.xlsx', sheet_name='VUTIL')
df_dep = pd.read_excel('TABELAS.xlsx', sheet_name='DEP')
# Converter datas de entrada
if data_refer_str is None or data_refer_str == "":
data_refer = datetime.now()
else:
data_refer = datetime.strptime(data_refer_str, "%m/%Y")
data_const = datetime.strptime(data_const_str, "%m/%Y")
if data_cub_str is None or data_cub_str == "":
data_cub = datetime.now()
else:
data_cub = datetime.strptime(data_cub_str, "%m/%Y")
# Filtrar por tipo_cub
df_tipo_cub = df_cub[df_cub['CÓDIGO'] == tipo_cub]
# Obter o valor do CUB na coluna correspondente à data
valor_cub_column = data_cub.strftime("%m/%Y")
valor_cub = df_tipo_cub.at[df_tipo_cub.index[0], valor_cub_column]
# Idade
idade = data_refer.toordinal() - data_const.toordinal()
if idade > 1:
idade = idade // 365
else:
idade = 1
# Filtrar por %de Vida
vdu = df_vida.loc[(df_vida['FINAL'] == tipologia)]
# % de vida útil
percentual_vdu = (idade / vdu['VIDAUTIL']) * 100
percentual_vdu = int(round(percentual_vdu, 0))
if percentual_vdu != 1:
percentual_vdu = percentual_vdu
else:
percentual_vdu = 2
print(percentual_vdu,"%")
# Filtrar conforme o % de vida útil
df_conserv = df_dep.loc[df_dep['%deVida'] == percentual_vdu]
# Converter o valor residual de string para número (float)
if VR and VR.strip() != "":
VR = float(VR)
else:
VR = 0.0
# Obter da depreciação
coef_HH = float(df_conserv[estado]/100)
coef_HH = round(coef_HH, 2)
# Valor do "Kd"
kd = VR + (1 - coef_HH) * (1 - VR)
kd = round(kd, 2)
# Cálculos
Valor_sem_deprec = area * valor_cub * percentual_cub * (1 + BDI / 100)
Valor_sem_deprec = round(Valor_sem_deprec, 2)
Valor_com_deprec = Valor_sem_deprec * kd
Valor_com_deprec = round(Valor_com_deprec, 2)
resumo = {
"01":"-------VALOR INICIAL-------",
"Área construída (m²)": area,
"Data de referência": data_refer.strftime("%m/%Y"),
"Data da construção": data_const_str,
"Data do CUB": data_cub.strftime("%m/%Y"),
"Tipo de CUB": tipo_cub,
"Percentual para adequação do CUB (%)": percentual_cub,
"BDI (%)": BDI,
"Valor CUB": round(valor_cub, 2),
"Valor_sem_deprec": Valor_sem_deprec,
"02":"-----VALOR DEPRECIADO-----",
"Tipologia": tipologia,
"Vida útil da tipologia": int(vdu['VIDAUTIL']),
"Estado de conservação": estado,
"% de Vida Útil": percentual_vdu,
"Coeficiente de Depreciação": coef_HH,
"Valor residual (0, 0.1 ou 0.2)": VR,
"Kd": kd,
"Valor final": Valor_com_deprec
}
return resumo
# # Define a function to print the outputs
# def print_outputs(outputs):
# print(outputs)
entradas = [
gr.inputs.Number(label="Área construída (m²)", default=100),
gr.inputs.Textbox(label="Data de referência (mm/aaaa)", default=""),
gr.inputs.Textbox(label="Data da construção (mm/aaaa)", default=""),
# gr.inputs.Textbox(label="Tipo de CUB", default="R 1-N (Res. Unifamiliar)"),
gr.inputs.Dropdown(label="Tipo de CUB", choices=["R 1-B (Res. Unifamiliar)", "R 1-N (Res. Unifamiliar)", "R 1-A (Res. Unifamiliar)", "PP 4-B (Prédio Popular)", "PP 4-N (Prédio Popular)", "R 8-B (Res. Multifamiliar)", "R 8-N (Res. Multifamiliar)", "R 8-A (Res. Multifamiliar)", "R 16-N (Res. Multifamiliar)", "R 16-A (Res. Multifamiliar)", "PIS (Projeto Inter. Social)", "RP1Q (Residência Popular)", "CAL 8-N (Com. Andar Livres)", "CAL 8-A (Com. Andar Livres)", "CSL 8-N (Com.Salas e Lojas)", "CSL 8-A (Com.Salas e Lojas)", "CSL 16-N (Com.Salas e Lojas)", "CSL 16-A (Com.Salas e Lojas)", "GI (Galpão Industrial)"]),
gr.inputs.Textbox(label="Data do CUB (mm/aaaa)", default=""),
gr.inputs.Number(label="Percentual para adequação do CUB (%)", default=1),
gr.inputs.Number(label="BDI (%)", default=22.5),
# gr.inputs.Textbox(label="Tipologia", default="APARTAMENTOS"),
gr.inputs.Dropdown(label="Tipologia", choices=["APARTAMENTOS", "BANCOS", "CASAS DE ALVENARIA", "CASAS DE MADEIRA", "HOTÉIS", "LOJAS", "TEATROS", "ARMAZÉNS", "FÁBRICAS", "CONST. RURAIS", "GARAGENS", "EDIFÍCIOS DE ESCRITÓRIOS", "GALPÕES (DEPÓSITOS)", "SILOS"]),
gr.inputs.Dropdown(label="Estado de conservação", choices=["A - novo", "B - entre novo e regular", "C - regular", "D - entre regular e reparos simples", "E - reparos simples", "F - entre reparos simples e importantes", "G - reparos importantes", "H - entre reparos importantes e sem valor"]),
# gr.inputs.Number(label="Valor residual (0, 0.1 ou 0.2)", default=0.2)
gr.inputs.Dropdown(label="Valor residual (0, 0.1 ou 0.2)", choices=["0", "0.1", "0.2"])
]
saida = gr.outputs.JSON()
# # Add a button to print the outputs
# button_print = Button(label="Print Outputs", onclick=print_outputs)
interface = gr.Interface(fn=calcular_valor_imovel, inputs=entradas, outputs=saida)
interface.launch() |