File size: 1,464 Bytes
4cf5a45
 
 
 
 
 
 
 
 
 
 
 
 
 
381f844
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4cf5a45
 
381f844
 
 
 
 
 
 
 
4cf5a45
381f844
 
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
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}"

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 modules

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()