Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,13 +1,33 @@
|
|
| 1 |
import joblib
|
| 2 |
import pandas as pd
|
| 3 |
from flask import Flask, request, jsonify
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
#initialise flask app
|
| 6 |
sales_forecast_api = Flask('Sales forecasting')
|
| 7 |
|
| 8 |
# load the model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
model = joblib.load('sales_forecast_v1_0.joblib')
|
| 11 |
|
| 12 |
#define home page
|
| 13 |
@sales_forecast_api.get('/')
|
|
@@ -17,6 +37,9 @@ def home():
|
|
| 17 |
#define an endpoint for prediction
|
| 18 |
@sales_forecast_api.post('/v1/sales')
|
| 19 |
def sales_predict():
|
|
|
|
|
|
|
|
|
|
| 20 |
#get data from json request
|
| 21 |
sales_data = request.get_json()
|
| 22 |
|
|
@@ -49,6 +72,9 @@ def sales_predict():
|
|
| 49 |
@sales_forecast_api.post('/v1/salesbatch')
|
| 50 |
|
| 51 |
def sales_batch_predict():
|
|
|
|
|
|
|
|
|
|
| 52 |
#get the file from the request
|
| 53 |
file = request.files['file']
|
| 54 |
#read the file to df
|
|
|
|
| 1 |
import joblib
|
| 2 |
import pandas as pd
|
| 3 |
from flask import Flask, request, jsonify
|
| 4 |
+
import os
|
| 5 |
+
import logging
|
| 6 |
+
|
| 7 |
+
# Configure logging
|
| 8 |
+
logging.basicConfig(level=logging.INFO)
|
| 9 |
+
logger = logging.getLogger(__name__)
|
| 10 |
|
| 11 |
#initialise flask app
|
| 12 |
sales_forecast_api = Flask('Sales forecasting')
|
| 13 |
|
| 14 |
# load the model
|
| 15 |
+
try:
|
| 16 |
+
# Log current working directory and files
|
| 17 |
+
current_dir = os.getcwd()
|
| 18 |
+
logger.info(f"Current working directory: {current_dir}")
|
| 19 |
+
files_in_dir = os.listdir(current_dir)
|
| 20 |
+
logger.info(f"Files in current directory: {files_in_dir}")
|
| 21 |
+
|
| 22 |
+
model = joblib.load('sales_forecast_v1_0.joblib')
|
| 23 |
+
logger.info("Model loaded successfully.")
|
| 24 |
+
except FileNotFoundError:
|
| 25 |
+
logger.error("Model file not found!")
|
| 26 |
+
model = None # Or handle the error as appropriate
|
| 27 |
+
except Exception as e:
|
| 28 |
+
logger.error(f"Error loading model: {e}")
|
| 29 |
+
model = None # Or handle the error as appropriate
|
| 30 |
|
|
|
|
| 31 |
|
| 32 |
#define home page
|
| 33 |
@sales_forecast_api.get('/')
|
|
|
|
| 37 |
#define an endpoint for prediction
|
| 38 |
@sales_forecast_api.post('/v1/sales')
|
| 39 |
def sales_predict():
|
| 40 |
+
if model is None:
|
| 41 |
+
return jsonify({"error": "Model not loaded"}), 500
|
| 42 |
+
|
| 43 |
#get data from json request
|
| 44 |
sales_data = request.get_json()
|
| 45 |
|
|
|
|
| 72 |
@sales_forecast_api.post('/v1/salesbatch')
|
| 73 |
|
| 74 |
def sales_batch_predict():
|
| 75 |
+
if model is None:
|
| 76 |
+
return jsonify({"error": "Model not loaded"}), 500
|
| 77 |
+
|
| 78 |
#get the file from the request
|
| 79 |
file = request.files['file']
|
| 80 |
#read the file to df
|