Spaces:
Sleeping
Sleeping
removed code that depends on tabulate
Browse files- src/app/app.py +8 -3
src/app/app.py
CHANGED
@@ -23,7 +23,7 @@ DIRPATH = os.path.dirname(os.path.realpath(__file__))
|
|
23 |
# set path for ml files
|
24 |
ml_contents_path = os.path.join(DIRPATH, '..', 'assets', 'ml_components', 'toolkit_folder')
|
25 |
|
26 |
-
|
27 |
ml_contents = load_file(ml_contents_path)
|
28 |
|
29 |
Encoder = ml_contents["OneHotEncoder"]
|
@@ -32,6 +32,8 @@ features_ = ml_contents['feature_names']
|
|
32 |
|
33 |
|
34 |
|
|
|
|
|
35 |
@app.get('/')
|
36 |
def root():
|
37 |
return 'Welcome to the Gorecery Sales Forecasting API'
|
@@ -44,6 +46,7 @@ def check_health():
|
|
44 |
async def predict_sales( store_id: int, category_id: int, onpromotion: int,
|
45 |
city: str, store_type: int, cluster: int, date_: Annotated[datetime.date, "The date of sales"] = datetime.date.today()):
|
46 |
|
|
|
47 |
input = {
|
48 |
'store_id':[store_id],
|
49 |
'category_id':[category_id],
|
@@ -54,10 +57,12 @@ async def predict_sales( store_id: int, category_id: int, onpromotion: int,
|
|
54 |
'date_': [date_]
|
55 |
}
|
56 |
|
|
|
57 |
input_data = pd.DataFrame(input)
|
58 |
date_extracts(input_data)
|
59 |
-
|
60 |
-
|
|
|
61 |
sales = make_predcition(Encoder, model, input)
|
62 |
sales_value = float(sales[0])
|
63 |
return {'sales': sales_value}
|
|
|
23 |
# set path for ml files
|
24 |
ml_contents_path = os.path.join(DIRPATH, '..', 'assets', 'ml_components', 'toolkit_folder')
|
25 |
|
26 |
+
# get contents
|
27 |
ml_contents = load_file(ml_contents_path)
|
28 |
|
29 |
Encoder = ml_contents["OneHotEncoder"]
|
|
|
32 |
|
33 |
|
34 |
|
35 |
+
# define endpoints
|
36 |
+
|
37 |
@app.get('/')
|
38 |
def root():
|
39 |
return 'Welcome to the Gorecery Sales Forecasting API'
|
|
|
46 |
async def predict_sales( store_id: int, category_id: int, onpromotion: int,
|
47 |
city: str, store_type: int, cluster: int, date_: Annotated[datetime.date, "The date of sales"] = datetime.date.today()):
|
48 |
|
49 |
+
# create a dictionary of inputs
|
50 |
input = {
|
51 |
'store_id':[store_id],
|
52 |
'category_id':[category_id],
|
|
|
57 |
'date_': [date_]
|
58 |
}
|
59 |
|
60 |
+
# convert to dataframe and extract datetime features
|
61 |
input_data = pd.DataFrame(input)
|
62 |
date_extracts(input_data)
|
63 |
+
|
64 |
+
|
65 |
+
# make prediction
|
66 |
sales = make_predcition(Encoder, model, input)
|
67 |
sales_value = float(sales[0])
|
68 |
return {'sales': sales_value}
|