Spaces:
Sleeping
Sleeping
| 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 | |
| def index(): | |
| return "SuperKart Sales Prediction Project" | |
| # Prediction endpoint | |
| 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) | |