Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,28 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import joblib
|
| 3 |
-
import
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import joblib
|
| 3 |
+
import numpy as np
|
| 4 |
|
| 5 |
+
# Load trained model
|
| 6 |
+
model = joblib.load("model/house_price_model.pkl")
|
| 7 |
|
| 8 |
+
# Define prediction function
|
| 9 |
+
def predict_price(rm, lstat, ptratio):
|
| 10 |
+
input_data = np.array([[rm, lstat, ptratio]])
|
| 11 |
+
prediction = model.predict(input_data)[0]
|
| 12 |
+
return round(prediction, 2)
|
| 13 |
|
| 14 |
+
# Define Gradio interface
|
| 15 |
+
iface = gr.Interface(
|
| 16 |
+
fn=predict_price,
|
| 17 |
+
inputs=[
|
| 18 |
+
gr.Slider(3.0, 9.0, step=0.1, label="Average Rooms (RM)"),
|
| 19 |
+
gr.Slider(1.0, 40.0, step=0.1, label="Lower Status Population (%) (LSTAT)"),
|
| 20 |
+
gr.Slider(12.0, 22.0, step=0.1, label="Pupil-Teacher Ratio (PTRATIO)")
|
| 21 |
+
],
|
| 22 |
+
outputs=gr.Number(label="Predicted House Price (in $1000s)"),
|
| 23 |
+
title="🏠 Boston Housing Price Predictor",
|
| 24 |
+
description="Enter the house features to predict the price using a linear regression model.",
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# Launch app
|
| 28 |
+
iface.launch()
|