Update app.py
Browse files
app.py
CHANGED
@@ -3,24 +3,25 @@ import pandas as pd
|
|
3 |
import xgboost as xgb
|
4 |
from huggingface_hub import hf_hub_download
|
5 |
|
6 |
-
#
|
7 |
-
model_path = hf_hub_download(repo_id="caslabs/
|
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
|
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()
|
|
|
3 |
import xgboost as xgb
|
4 |
from huggingface_hub import hf_hub_download
|
5 |
|
6 |
+
# Load the model from the Hugging Face Hub
|
7 |
+
model_path = hf_hub_download(repo_id="caslabs/home-price-predictor-mockup", 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 |
+
# Convert the JSON input to a DataFrame
|
14 |
df = pd.DataFrame([features])
|
15 |
predicted_price = model.predict(df)[0]
|
16 |
return {"predicted_price": predicted_price}
|
17 |
|
18 |
+
# Set up the Gradio interface
|
19 |
iface = gr.Interface(
|
20 |
fn=predict_price,
|
21 |
+
inputs=gr.JSON(), # Accept JSON input
|
22 |
+
outputs=gr.JSON(), # Return JSON output
|
23 |
title="Home Price Prediction API",
|
24 |
+
description="Predict home price based on input features"
|
25 |
)
|
26 |
|
27 |
iface.launch()
|