Spaces:
Sleeping
Sleeping
File size: 688 Bytes
99ed953 |
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 |
from flask import Flask, request, jsonify
import joblib
import pandas as pd
# Load model
model = joblib.load("best_model.pkl")
# Initialize app
app = Flask(__name__)
@app.route("/", methods=["GET"])
def root():
return jsonify({"message": "Sales Forecasting API is live!"})
@app.route("/predict", methods=["POST"])
def predict():
try:
input_data = request.get_json()
input_df = pd.DataFrame([input_data])
prediction = model.predict(input_df)[0]
return jsonify({"predicted_sales": round(prediction, 2)})
except Exception as e:
return jsonify({"error": str(e)}), 400
if __name__ == "__main__":
app.run(host="0.0.0.0", port=7860)
|