Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
from sklearn.ensemble import RandomForestRegressor
|
| 5 |
+
best_model=load('./model_LogisticRegression.joblib')
|
| 6 |
+
# Suponiendo que 'best_model' y 'X_train' están definidos en tu entorno
|
| 7 |
+
|
| 8 |
+
def predict_price(size, bathroom, parking, rooms):
|
| 9 |
+
new_property_data = pd.DataFrame({
|
| 10 |
+
'Tamaño': [size],
|
| 11 |
+
'Baño': [bathroom],
|
| 12 |
+
'Estacionamiento': [parking],
|
| 13 |
+
'Habitaciones': [rooms]
|
| 14 |
+
})
|
| 15 |
+
# Asegúrate de que las columnas estén en el mismo orden que X_train
|
| 16 |
+
new_property_data = new_property_data[X_train.columns]
|
| 17 |
+
predicted_price = best_model.predict(new_property_data)
|
| 18 |
+
return f"${predicted_price[0]:,.2f}"
|
| 19 |
+
|
| 20 |
+
iface = gr.Interface(
|
| 21 |
+
fn=predict_price,
|
| 22 |
+
inputs=[
|
| 23 |
+
gr.Number(label="Tamaño (m²)", value=150),
|
| 24 |
+
gr.Number(label="Baños", value=2.5),
|
| 25 |
+
gr.Number(label="Estacionamiento", value=2),
|
| 26 |
+
gr.Number(label="Habitaciones", value=3),
|
| 27 |
+
],
|
| 28 |
+
outputs=gr.Textbox(label="Precio Estimado"),
|
| 29 |
+
title="Predictor de Precios de Inmuebles",
|
| 30 |
+
description="Ingresa las características del inmueble para obtener una estimación de su precio."
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
iface.launch(debug=True)
|