import numpy as np import pandas as pd from sklearn.neighbors import KNeighborsRegressor from joblib import dump, load import gradio as gr scaler = load('scaler_lab4.joblib') KNN_Regressor = load('knn_lab4.joblib') ## Building a Fubction for prediction: def predictPrice(input1, input2, input3, input4, input5, input6, input7, input8): features = np.array([[input1, input2, input3, input4, input5, input6, input7, input8]]) features_scaled = scaler.transform(features) prediction = KNN_Regressor.predict(features_scaled) return round(prediction.item(), 2) ## Buidling inputs and outputs: input1 = gr.Slider(-124.35, -114.31, step=5, label = "Longitude") input2 = gr.Slider(32.54, 41.95, step=5, label = "Latitude") input3 = gr.Slider(1, 52.0, step=5, label = "Housing_median_age (Year)") input4 = gr.Slider(1, 39320.0, step=5, label = "Total_rooms") input5 = gr.Slider(1, 6445.0, step=5, label = "Total_bedrooms") input6 = gr.Slider(1, 35682.0, step=5, label = "Population") input7 = gr.Slider(1, 6082.0, step=5, label = "Households") input8 = gr.Slider(0, 15.0, step=5, label = "Median_income") output1 = gr.Textbox(label = "House Value") ##title Putting it all together: gr.Interface(fn=predictPrice, inputs=[input1, input2, input3, input4, input5, input6, input7, input8], outputs=output1).launch(show_error=True, share=True)