Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -316,10 +316,9 @@ def batch_predict():
|
|
| 316 |
logger.error(f"Batch prediction error: {str(e)}")
|
| 317 |
return jsonify({"error": f"Batch prediction failed: {str(e)}"}), 500
|
| 318 |
|
| 319 |
-
# Initialize the model when the app starts
|
| 320 |
-
@app.before_first_request
|
| 321 |
def initialize():
|
| 322 |
-
"""Initialize the model on
|
| 323 |
logger.info("Initializing SuperKart Sales Forecasting API...")
|
| 324 |
success = load_model()
|
| 325 |
if success:
|
|
@@ -327,6 +326,10 @@ def initialize():
|
|
| 327 |
else:
|
| 328 |
logger.error("API initialization failed - model could not be loaded")
|
| 329 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
if __name__ == '__main__':
|
| 331 |
# Load model
|
| 332 |
if load_model():
|
|
|
|
| 316 |
logger.error(f"Batch prediction error: {str(e)}")
|
| 317 |
return jsonify({"error": f"Batch prediction failed: {str(e)}"}), 500
|
| 318 |
|
| 319 |
+
# Initialize the model when the app starts (Flask 3.x compatible)
|
|
|
|
| 320 |
def initialize():
|
| 321 |
+
"""Initialize the model on app startup."""
|
| 322 |
logger.info("Initializing SuperKart Sales Forecasting API...")
|
| 323 |
success = load_model()
|
| 324 |
if success:
|
|
|
|
| 326 |
else:
|
| 327 |
logger.error("API initialization failed - model could not be loaded")
|
| 328 |
|
| 329 |
+
# Call initialization immediately when module loads
|
| 330 |
+
with app.app_context():
|
| 331 |
+
initialize()
|
| 332 |
+
|
| 333 |
if __name__ == '__main__':
|
| 334 |
# Load model
|
| 335 |
if load_model():
|