File size: 682 Bytes
b65c5de |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import xgboost as xgb
import json
import numpy as np
def model_fn(model_dir):
# Load the model from Hugging Face Hub
model = xgb.Booster()
model.load_model(f"{model_dir}/xgboost_model.json")
return model
def predict_fn(data, model):
# Convert input data into DMatrix
dmatrix = xgb.DMatrix(np.array(data['inputs']))
prediction = model.predict(dmatrix)
return prediction.tolist()
if __name__ == "__main__":
# Example of testing locally
model = model_fn(".")
sample_data = {"inputs": [[1, 2, 3], [4, 5, 6]]} # Replace with your input features
predictions = predict_fn(sample_data, model)
print(predictions)
|