| import numpy as np |
| import joblib |
| import gradio as gr |
|
|
| |
| model = joblib.load("knn_house_model.pkl") |
| scaler = joblib.load("scaler.pkl") |
| label_encoder = joblib.load("label_encoder.pkl") |
|
|
| |
| def predict_price(num_rooms, distance, country, build_quality): |
| country_encoded = label_encoder.transform([country])[0] |
| features = np.array([[num_rooms, distance, country_encoded, build_quality]]) |
| features_scaled = scaler.transform(features) |
| predicted_price = model.predict(features_scaled)[0] |
| return f"Predicted House Price: ${predicted_price:,.2f}" |
|
|
| |
| inputs = [ |
| gr.Number(label="Number of Rooms"), |
| gr.Number(label="Distance to Center (km)"), |
| gr.Dropdown(label="Country", choices=label_encoder.classes_.tolist()), |
| gr.Slider(minimum=1, maximum=10, label="Build Quality") |
| ] |
|
|
| outputs = gr.Textbox(label="Prediction Result") |
|
|
| |
| app = gr.Interface(fn=predict_price, inputs=inputs, outputs=outputs, title="House Price Prediction") |
| app.launch() |