|
import gradio as gr |
|
import pandas as pd |
|
import xgboost as xgb |
|
from huggingface_hub import hf_hub_download |
|
|
|
|
|
model_path = hf_hub_download(repo_id="caslabs/xgboost-home-price-predictor", filename="xgboost_model.json") |
|
model = xgb.XGBRegressor() |
|
model.load_model(model_path) |
|
|
|
|
|
def predict_price(features): |
|
|
|
df = pd.DataFrame([features]) |
|
predicted_price = model.predict(df)[0] |
|
return {"predicted_price": predicted_price} |
|
|
|
|
|
iface = gr.Interface( |
|
fn=predict_price, |
|
inputs=gr.JSON(), |
|
outputs=gr.JSON(), |
|
title="Home Price Prediction API", |
|
description="Predict home price based on input features" |
|
) |
|
|
|
|
|
iface.launch() |
|
|