Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,32 +3,24 @@ import pandas as pd
|
|
3 |
import xgboost as xgb
|
4 |
from huggingface_hub import hf_hub_download
|
5 |
|
6 |
-
# Download and load the model
|
7 |
-
model_path = hf_hub_download(
|
8 |
-
|
9 |
-
|
10 |
-
repo_type='model'
|
11 |
-
)
|
12 |
-
|
13 |
-
loaded_model = xgb.XGBRegressor()
|
14 |
-
loaded_model.load_model(model_path)
|
15 |
|
16 |
# Define the prediction function
|
17 |
-
def predict_price(
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
# Make a prediction
|
22 |
-
predicted_price = loaded_model.predict(input_data)[0]
|
23 |
-
return {"predicted_price": round(predicted_price, 2)}
|
24 |
|
25 |
-
#
|
26 |
iface = gr.Interface(
|
27 |
fn=predict_price,
|
28 |
-
inputs=gr.JSON(),
|
29 |
-
outputs=gr.JSON(),
|
30 |
title="Home Price Prediction API",
|
31 |
-
description="
|
32 |
)
|
33 |
|
34 |
-
iface.launch()
|
|
|
3 |
import xgboost as xgb
|
4 |
from huggingface_hub import hf_hub_download
|
5 |
|
6 |
+
# Download and load the model
|
7 |
+
model_path = hf_hub_download(repo_id="caslabs/xgboost-home-price-predictor", filename="xgboost_model.json")
|
8 |
+
model = xgb.XGBRegressor()
|
9 |
+
model.load_model(model_path)
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
# Define the prediction function
|
12 |
+
def predict_price(features):
|
13 |
+
df = pd.DataFrame([features])
|
14 |
+
predicted_price = model.predict(df)[0]
|
15 |
+
return {"predicted_price": predicted_price}
|
|
|
|
|
|
|
16 |
|
17 |
+
# Set up Gradio interface as an API endpoint
|
18 |
iface = gr.Interface(
|
19 |
fn=predict_price,
|
20 |
+
inputs=gr.JSON(),
|
21 |
+
outputs=gr.JSON(),
|
22 |
title="Home Price Prediction API",
|
23 |
+
description="Predict home price based on features"
|
24 |
)
|
25 |
|
26 |
+
iface.launch()
|