File size: 1,235 Bytes
9ca70f9
 
 
1c8123f
0932e5c
305d2d2
9ca70f9
130a4db
9ca70f9
384abaf
9ca70f9
384abaf
9ca70f9
384abaf
 
9ca70f9
 
130a4db
9ca70f9
 
 
 
 
 
384abaf
9ca70f9
384abaf
9ca70f9
 
 
 
 
 
 
 
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
import gradio as gr
import pandas as pd
import numpy as np
from joblib import load

best_model=load('./RandomForestRegressorVentaCasas.joblib')
# Suponiendo que 'best_model' y 'X_train' están definidos en tu entorno
feature_order = ['Habitaciones', 'Baño', 'Tamaño', 'Estacionamiento']

def predict_price(rooms, bathroom, size, parking):
    new_property_data = pd.DataFrame({
        'Habitaciones': [rooms],
        'Baño': [bathroom],
        'Tamaño': [size],
        'Estacionamiento': [parking]
    })
    # Asegúrate de que las columnas estén en el mismo orden que X_train
    new_property_data = new_property_data[feature_order]
    predicted_price = best_model.predict(new_property_data)
    return f"${predicted_price[0]:,.2f}"

iface = gr.Interface(
    fn=predict_price,
    inputs=[
        gr.Number(label="Habitaciones", value=3),
        gr.Number(label="Baños", value=2.5),
        gr.Number(label="Tamaño m2", value=150),
        gr.Number(label="Estacionamiento", value=2),
    ],
    outputs=gr.Textbox(label="Precio Estimado"),
    title="Predictor de Precios de Inmuebles",
    description="Ingresa las características del inmueble para obtener una estimación de su precio."
)

iface.launch(debug=True)