File size: 1,469 Bytes
cd09536
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
513df81
7b613bb
 
cd09536
 
 
 
 
 
 
 
7b613bb
cd09536
 
e401172
cd09536
 
 
 
 
 
 
 
 
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
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)