Spaces:
Sleeping
Sleeping
import gradio as gr | |
import pandas as pd | |
import xgboost as xgb | |
from huggingface_hub import hf_hub_download | |
# Download and load the model from the Hugging Face repository | |
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) | |
# Define the prediction function | |
def predict_price(data): | |
# Parse the input data | |
input_data = pd.DataFrame([data]) | |
# Make a prediction | |
predicted_price = loaded_model.predict(input_data)[0] | |
return {"predicted_price": round(predicted_price, 2)} | |
# Define the API interface with Gradio | |
iface = gr.Interface( | |
fn=predict_price, | |
inputs=gr.JSON(), # Accept JSON input | |
outputs=gr.JSON(), # Return JSON output | |
title="Home Price Prediction API", | |
description="Provide property details in JSON format, and the model will return the predicted adjusted sale price." | |
) | |
iface.launch() |