molinari135
commited on
Update product_return_prediction/api.py
Browse files
product_return_prediction/api.py
CHANGED
@@ -1,18 +1,12 @@
|
|
|
|
|
|
1 |
from fastapi import FastAPI, HTTPException
|
2 |
from pydantic import BaseModel, Field
|
3 |
from datasets import load_dataset
|
4 |
-
import pandas as pd
|
5 |
-
import json
|
6 |
-
import os
|
7 |
-
import pickle
|
8 |
-
import requests
|
9 |
from pathlib import Path
|
10 |
from product_return_prediction.dataset import prepare_inventory, scale_data_with_trained_scaler
|
11 |
from product_return_prediction.monitoring import instrumentator
|
12 |
-
from
|
13 |
-
from huggingface_hub import hf_hub_download
|
14 |
-
|
15 |
-
from huggingface_hub import login
|
16 |
|
17 |
login(token=os.getenv("HUGGINGFACE_TOKEN"))
|
18 |
|
@@ -151,18 +145,7 @@ async def predict(products: ProductRequest):
|
|
151 |
filtered_inventory, products.total_customer_purchases, products.total_customer_returns
|
152 |
)
|
153 |
|
154 |
-
# models_uri = "https://huggingface.co/molinari135/se4ai-models/resolve/main/"
|
155 |
-
# model_path = MODELS_DIR / model_name
|
156 |
-
# scaler_path = MODELS_DIR / scaler_name
|
157 |
-
|
158 |
-
# headers = f"Authorization: Bearer {hf_token}"
|
159 |
-
|
160 |
-
# download_file(f"{models_uri}{model_name}", model_path, headers)
|
161 |
-
# download_file(f"{models_uri}{scaler_name}", scaler_path, headers)
|
162 |
-
|
163 |
model = load_model(hf_hub_download(repo_id="molinari135/se4ai-models", filename="svm.pkl"))
|
164 |
-
|
165 |
-
# model = pickle.load(hf_hub_download(repo_id="molinari135/se4ai-models", filename="svm.pkl"))
|
166 |
|
167 |
scaled_inventory = apply_scaling(prepared_inventory, scaler_file)
|
168 |
predictions, probabilities = make_predictions(model, scaled_inventory)
|
|
|
1 |
+
import json, os, pickle, requests
|
2 |
+
import pandas as pd
|
3 |
from fastapi import FastAPI, HTTPException
|
4 |
from pydantic import BaseModel, Field
|
5 |
from datasets import load_dataset
|
|
|
|
|
|
|
|
|
|
|
6 |
from pathlib import Path
|
7 |
from product_return_prediction.dataset import prepare_inventory, scale_data_with_trained_scaler
|
8 |
from product_return_prediction.monitoring import instrumentator
|
9 |
+
from huggingface_hub import hf_hub_download, login
|
|
|
|
|
|
|
10 |
|
11 |
login(token=os.getenv("HUGGINGFACE_TOKEN"))
|
12 |
|
|
|
145 |
filtered_inventory, products.total_customer_purchases, products.total_customer_returns
|
146 |
)
|
147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
model = load_model(hf_hub_download(repo_id="molinari135/se4ai-models", filename="svm.pkl"))
|
|
|
|
|
149 |
|
150 |
scaled_inventory = apply_scaling(prepared_inventory, scaler_file)
|
151 |
predictions, probabilities = make_predictions(model, scaled_inventory)
|