|
import gradio as gr
|
|
from joblib import load
|
|
|
|
|
|
scaler = load('scaler.joblib')
|
|
best_knn_model = load('best_knn_model.joblib')
|
|
|
|
|
|
def predict_house_price(longitude, latitude, housing_median_age, total_rooms, total_bedrooms, population, households, median_income):
|
|
inputs = [[longitude, latitude, housing_median_age, total_rooms, total_bedrooms, population, households, median_income]]
|
|
scaled_inputs = scaler.transform(inputs)
|
|
prediction = best_knn_model.predict(scaled_inputs)[0]
|
|
return f"${prediction:,.2f}"
|
|
|
|
|
|
interface = gr.Interface(
|
|
fn=predict_house_price,
|
|
inputs=[
|
|
gr.Number(label="Longitude"),
|
|
gr.Number(label="Latitude"),
|
|
gr.Number(label="Housing Median Age"),
|
|
gr.Number(label="Total Rooms"),
|
|
gr.Number(label="Total Bedrooms"),
|
|
gr.Number(label="Population"),
|
|
gr.Number(label="Households"),
|
|
gr.Number(label="Median Income")
|
|
],
|
|
outputs=gr.Textbox(label="Predicted House Price")
|
|
)
|
|
|
|
|
|
interface.launch()
|
|
|