Spaces:
Runtime error
Runtime error
File size: 1,236 Bytes
2b97390 eb18e4a 2b97390 81d595a 2b97390 81d595a 2b97390 81d595a 2b97390 | 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
from flask import Flask, request, jsonify
import joblib
import numpy as np
import os
from huggingface_hub import hf_hub_download
import joblib
model_path = hf_hub_download(
repo_id="affanthinks/superkart",
filename="AGreatLearning/tuned_bagging_model.pkl", # include directory
revision="main", # ensures correct branch
token=os.getenv("HF_TOKEN") # authentication
)
model = joblib.load(model_path)
print("✅ Model loaded successfully from", model_path)
# Initialize app
app = Flask("predict_revenue")
@app.route("/")
def home():
return jsonify({"message": "Supermarket Revenue Prediction API is running!"})
@app.route("/predict", methods=["POST"])
def predict():
try:
# Get JSON input
data = request.get_json(force=True)
features = np.array(data["features"]).reshape(1, -1)
# Predict
prediction = model.predict(features)[0]
return jsonify({"predicted_revenue": float(prediction)})
except Exception as e:
return jsonify({"error": str(e)})
if "predict_revenue" == "__main__":
app.run(host="0.0.0.0", port=7860, debug=True)
|