Spaces:
Sleeping
Sleeping
| 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") | |
| def home(): | |
| return "SuperKart Sales Forecast API is running successfully!" | |
| 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(debug=True) |