import gradio as gr import pandas as pd import xgboost as xgb from huggingface_hub import hf_hub_download # Load the model from the Hugging Face Hub model_path = hf_hub_download(repo_id="caslabs/xgboost-home-price-predictor", filename="xgboost_model.json") model = xgb.XGBRegressor() model.load_model(model_path) # Define the prediction function def predict_price(features): # Convert the JSON input to a DataFrame df = pd.DataFrame([features]) predicted_price = model.predict(df)[0] return {"predicted_price": predicted_price} # Set up the Gradio interface iface = gr.Interface( fn=predict_price, inputs=gr.JSON(), # Accept JSON input outputs=gr.JSON(), # Return JSON output title="Home Price Prediction API", description="Predict home price based on input features" ) # Launch the interface without 'enable_api' iface.launch()