File size: 871 Bytes
6a535fc
d8e3db6
 
 
 
232d70d
155f630
670df98
 
d8e3db6
232d70d
 
 
6a535fc
 
 
d8e3db6
232d70d
6a535fc
232d70d
 
 
6a535fc
 
 
d8e3db6
232d70d
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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()