Spaces:
Sleeping
Sleeping
Download app.py from creativitysupreme/superkart-backend: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/spaces/creativitysupreme/superkart-backend/resolve/main/app.py
- Command line
-
hf download hf://spaces/creativitysupreme/superkart-backend/app.py
-
curl -L -o app.py https://huggingface.co/spaces/creativitysupreme/superkart-backend/resolve/main/app.py
1.01 kB
| from flask import Flask, request, jsonify | |
| import joblib | |
| import pandas as pd | |
| import numpy as np | |
| app = Flask(__name__) | |
| # Load the serialized model pipeline | |
| model = joblib.load('superkart_model.pkl') | |
| def home(): | |
| return jsonify({ | |
| 'message': 'SuperKart Sales Prediction API is running!', | |
| 'status': 'healthy' | |
| }) | |
| def predict(): | |
| try: | |
| data = request.get_json() | |
| # Handle both single and batch predictions | |
| if isinstance(data, dict): | |
| data = [data] | |
| df = pd.DataFrame(data) | |
| # Make predictions | |
| predictions = model.predict(df) | |
| return jsonify({ | |
| 'predictions': predictions.tolist(), | |
| 'status': 'success' | |
| }) | |
| except Exception as e: | |
| return jsonify({'error': str(e), 'status': 'failure'}), 400 | |
| if __name__ == '__main__': | |
| app.run(host='0.0.0.0', port=7860) | |