Update product_return_prediction/api.py
Browse files
product_return_prediction/api.py
CHANGED
@@ -126,10 +126,6 @@ async def root():
|
|
126 |
|
127 |
@app.post("/predict/")
|
128 |
async def predict(products: ProductRequest):
|
129 |
-
inventory_path: Path = EXTERNAL_DATA_DIR / "inventory.tsv"
|
130 |
-
model_path: Path = MODELS_DIR / "svm.pkl"
|
131 |
-
scaler_file: Path = MODELS_DIR / "scaler.pkl"
|
132 |
-
|
133 |
hf_token = os.getenv("inventory_data")
|
134 |
dataset = load_dataset("molinari135/armani-inventory", token=hf_token, data_files="inventory.tsv")
|
135 |
inventory = pd.DataFrame(dataset['train'])
|
@@ -145,9 +141,12 @@ async def predict(products: ProductRequest):
|
|
145 |
filtered_inventory, products.total_customer_purchases, products.total_customer_returns
|
146 |
)
|
147 |
|
148 |
-
|
149 |
-
|
|
|
|
|
150 |
scaled_inventory = apply_scaling(prepared_inventory, scaler_file)
|
|
|
151 |
predictions, probabilities = make_predictions(model, scaled_inventory)
|
152 |
|
153 |
result = [
|
|
|
126 |
|
127 |
@app.post("/predict/")
|
128 |
async def predict(products: ProductRequest):
|
|
|
|
|
|
|
|
|
129 |
hf_token = os.getenv("inventory_data")
|
130 |
dataset = load_dataset("molinari135/armani-inventory", token=hf_token, data_files="inventory.tsv")
|
131 |
inventory = pd.DataFrame(dataset['train'])
|
|
|
141 |
filtered_inventory, products.total_customer_purchases, products.total_customer_returns
|
142 |
)
|
143 |
|
144 |
+
model_file = hf_hub_download(repo_id="molinari135/se4ai-models", filename="svm.pkl")
|
145 |
+
model = load_model(model_file)
|
146 |
+
|
147 |
+
scaler_file = hf_hub_download(repo_id="molinari135/se4ai-models", filename="scaler.pkl")
|
148 |
scaled_inventory = apply_scaling(prepared_inventory, scaler_file)
|
149 |
+
|
150 |
predictions, probabilities = make_predictions(model, scaled_inventory)
|
151 |
|
152 |
result = [
|