| 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}"
|
|
|
| input_longitude = gr.Slider(label="Longitude")
|
| input_latitude = gr.Slider(label="Latitude")
|
| input_housing_med_age = gr.Slider(label="Housing Median Age")
|
| input_totla_rooms = gr.Slider(label="Total Rooms")
|
| input_total_bedRooms = gr.Slider(label="Total Bedrooms")
|
| input_popu = gr.Slider(label="Population")
|
| input_households = gr.Slider(label="Households")
|
| input_med_income = gr.Slider(label="Median Income")
|
|
|
|
|
|
|
|
|
| output_predicted_value = gr.Textbox(label="Predicted Median House Value")
|
|
|
| gr.Interface(
|
| fn=predict_house_price,
|
| inputs=[
|
| input_longitude,
|
| input_latitude,
|
| input_housing_med_age,
|
| input_totla_rooms,
|
| input_total_bedRooms,
|
| input_popu,
|
| input_households,
|
| input_med_income
|
| ],
|
| outputs=gr.Textbox(label="Predicted Median House Value"),
|
| ).launch() |