lab04 / app.py
karthik55's picture
files uploaded
4cf5a45 verified
raw
history blame
1.15 kB
import gradio as gr
from joblib import load
# Load your saved model and scaler
scaler = load('scaler.joblib')
best_knn_model = load('best_knn_model.joblib')
# Define the prediction function
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}"
# Define the Gradio interface
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")
)
# Launch the interface
interface.launch()