|
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', |
|
repo_type='model' |
|
) |
|
|
|
loaded_model = xgb.XGBRegressor() |
|
loaded_model.load_model(model_path) |
|
|
|
|
|
def predict_price(data): |
|
|
|
input_data = pd.DataFrame([data]) |
|
|
|
|
|
predicted_price = loaded_model.predict(input_data)[0] |
|
return {"predicted_price": round(predicted_price, 2)} |
|
|
|
|
|
iface = gr.Interface( |
|
fn=predict_price, |
|
inputs=gr.JSON(), |
|
outputs=gr.JSON(), |
|
title="Home Price Prediction API", |
|
description="Provide property details in JSON format, and the model will return the predicted adjusted sale price." |
|
) |
|
|
|
iface.launch() |