Spaces:
Sleeping
Sleeping
Download app.py from HacksterT/GreatLearningProject: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/spaces/HacksterT/GreatLearningProject/resolve/bf05af002fa1954111e8fcf90fab4ea989d30c19/app.py
- Command line
-
hf download hf://spaces/HacksterT/GreatLearningProject@bf05af002fa1954111e8fcf90fab4ea989d30c19/app.py
-
curl -L -o app.py https://huggingface.co/spaces/HacksterT/GreatLearningProject/resolve/bf05af002fa1954111e8fcf90fab4ea989d30c19/app.py
1.12 kB
| from flask import Flask, request, jsonify | |
| from flask_cors import CORS | |
| import joblib | |
| import pandas as pd | |
| import numpy as np | |
| from datetime import datetime | |
| app = Flask(__name__) | |
| CORS(app) | |
| # Load model on startup | |
| deployment_package = joblib.load('models/superkart_deployment_package_20250809_122306.pkl') | |
| model = deployment_package['model'] | |
| def home(): | |
| return jsonify({ | |
| 'status': 'healthy', | |
| 'message': 'SuperKart Sales Forecasting API', | |
| 'model_loaded': True | |
| }) | |
| def predict_sales(): | |
| try: | |
| data = request.get_json() | |
| input_df = pd.DataFrame([data]) | |
| prediction = model.predict(input_df) | |
| return jsonify({ | |
| 'prediction': float(prediction[0]), | |
| 'prediction_formatted': f"${prediction[0]:.2f}", | |
| 'status': 'success' | |
| }) | |
| except Exception as e: | |
| return jsonify({'error': str(e), 'status': 'failed'}), 500 | |
| if __name__ == '__main__': | |
| app.run(host='0.0.0.0', port=5000, debug=True) | |