Spaces:
Sleeping
Sleeping
File size: 788 Bytes
0c667e9 |
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 |
from flask import Flask, request, jsonify
import pandas as pd
import joblib
# Load the trained SuperKart model
sales_model = joblib.load("random_forest_pipeline.pkl")
# Initialize Flask application
app = Flask(__name__)
# Root endpoint
@app.route('/')
def index():
return "SuperKart Sales Prediction Project"
# Prediction endpoint
@app.route('/predict', methods=['POST'])
def make_prediction():
try:
input_data = request.get_json()
input_df = pd.DataFrame([input_data])
forecast = sales_model.predict(input_df)[0]
return jsonify({'Predicted_Sales_Product': round(forecast, 2)})
except Exception as err:
return jsonify({'error': str(err)})
# Launch the Flask server
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7860)
|