| import gradio as gr |
| import pandas as pd |
| import numpy as np |
| from joblib import load |
|
|
| best_model=load('./RandomForestRegressorVentaCasas.joblib') |
| |
| 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] |
| }) |
| |
| 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) |