Dharsh1316's picture
Update app.py
e401172 verified
import gradio as gr
import pandas as pd
import xgboost as xgb
from sklearn.model_selection import train_test_split
import os
# Load dataset safely using file
df = pd.read_csv("house_price1.csv")
# Drop rows with missing values
df.dropna(inplace=True)
# Split features and target
x = df.drop("PRICE", axis=1)
y = df["PRICE"]
# Train-test split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=42)
# Train XGBoost model
model = xgb.XGBRegressor(objective='reg:squarederror', n_estimators=100)
model.fit(x_train, y_train)
# Prediction function
def predict_price(BEDROOMS, BATHROOM_SIZE, SIZE, LOCATION, AGE,PRICE):
input_data = pd.DataFrame([[BEDROOMS, BATHROOM_SIZE, SIZE, LOCATION, AGE,PRICE]],
columns=["BEDROOMS", "BATHROOM_SIZE", "SIZE", "LOCATION", "AGE","PRICE"])
prediction = model.predict(input_data)[0]
return f"Estimated House Price: {prediction:,.2f}"
# Gradio Interface
interface = gr.Interface(
fn=predict_price,
inputs=[
gr.Number(label="BEDROOMS"),
gr.Number(label="BATHROOM_SIZE"),
gr.Number(label="SIZE"),
gr.Number(label="LOCATION"),
gr.Number(label="AGE"),
gr.Number(label="PRICE")
],
outputs="text",
title=" House Price Prediction App",
description="Enter property details to estimate the house price using XGBoost model."
)
# Launch
interface.launch(server_name="0.0.0.0", server_port=7860)