Spaces:
Sleeping
Sleeping
| import joblib | |
| import pandas as pd | |
| from flask import Flask, request, jsonify | |
| # Initialize Flask app with a name | |
| sales_predictor_api = Flask("SuperKart Sales Predictor") | |
| # Load the trained SuperKart Sales prediction model | |
| model = joblib.load("superkart_sales_model.pkl") | |
| # Define a route for the home page | |
| def home(): | |
| return "Welcome to the SuperKart Sales Prediction API!" | |
| # Define an endpoint to predict churn for a single customer | |
| def predict_sales(): | |
| try: | |
| # Get JSON data | |
| sales_data = request.get_json() | |
| # Ensure input is a list of records | |
| if isinstance(sales_data, dict): | |
| sales_data = [sales_data] | |
| # Convert to DataFrame | |
| input_data = pd.DataFrame(sales_data) | |
| # Predict | |
| prediction = model.predict(input_data).tolist()[0] | |
| return jsonify({"prediction": float(prediction)}) | |
| except Exception as e: | |
| return jsonify({"error": str(e)}) | |
| # Run the Flask app in debug mode | |
| if __name__ == '__main__': | |
| sales_predictor_api.run(debug=True) |