File size: 798 Bytes
375acd7 7f442da 83b7a47 7f442da 83b7a47 7f442da 83b7a47 7f442da 375acd7 7f442da 69a72ce 7f442da 69a72ce | 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 |
import pandas as pd
import joblib
from flask import Flask, request, jsonify
# Initialize Flask app
app = Flask(__name__)
# Load the saved model
model = joblib.load("superkart_model.joblib")
@app.route("/")
def home():
return "SuperKart Sales Forecast API is running successfully!"
@app.route("/v1/predict", methods=["POST"])
def predict_sales():
try:
data = request.get_json()
# Convert incoming data to DataFrame
input_data = pd.DataFrame([data])
# Generate prediction
prediction = model.predict(input_data)[0]
return jsonify({"Sales": float(prediction)})
except Exception as e:
return jsonify({"error": str(e)})
if __name__ == '__main__':
# In Docker/Hugging Face container, set host and port explicitly
app.run()
|