|
import gradio as gr |
|
import joblib |
|
import numpy as np |
|
import pandas as pd |
|
|
|
model = joblib.load('model.joblib') |
|
unique_values = joblib.load('unique_values.joblib') |
|
neighborhood_values = unique_values['Neighborhood'] |
|
|
|
|
|
def predict(neighborhood, house_size, num_rooms): |
|
|
|
house_size = float(house_size) |
|
num_rooms = int(num_rooms) |
|
|
|
|
|
input_data = pd.DataFrame({ |
|
'Neighborhood': [neighborhood], |
|
'House Size': [house_size], |
|
'Number of Rooms': [num_rooms] |
|
}) |
|
|
|
|
|
prediction = model.predict(input_data) |
|
|
|
return f"The predicted house price is ${prediction[0]:,.2f}" |
|
|
|
|
|
interface = gr.Interface( |
|
fn=predict, |
|
inputs=[ |
|
gr.Dropdown(choices=list(neighborhood_values), label="Neighborhood"), |
|
gr.Textbox(label="House Size (in square feet)"), |
|
gr.Textbox(label="Number of Rooms") |
|
], |
|
outputs="text", |
|
title="House Price Predictor", |
|
description="Enter the neighborhood, house size, and number of rooms to predict the house price." |
|
) |
|
|
|
|
|
|
|
|
|
interface.launch() |