File size: 1,147 Bytes
4cf5a45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()