Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -30,13 +30,22 @@ def predict_sales():
|
|
| 30 |
# Predict for a batch (CSV upload)
|
| 31 |
@sales_forecast_api.post('/v1/predict_batch')
|
| 32 |
def predict_sales_batch():
|
|
|
|
| 33 |
file = request.files['file']
|
| 34 |
input_data = pd.read_csv(file)
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
preds = model.predict(input_data).tolist()
|
| 37 |
|
| 38 |
-
# Map row index → prediction
|
| 39 |
-
results =
|
| 40 |
|
| 41 |
return jsonify(results)
|
| 42 |
|
|
|
|
| 30 |
# Predict for a batch (CSV upload)
|
| 31 |
@sales_forecast_api.post('/v1/predict_batch')
|
| 32 |
def predict_sales_batch():
|
| 33 |
+
# Read uploaded CSV file
|
| 34 |
file = request.files['file']
|
| 35 |
input_data = pd.read_csv(file)
|
| 36 |
|
| 37 |
+
# Check for optional Product_Id column
|
| 38 |
+
if "Product_Id" in input_data.columns:
|
| 39 |
+
ids = input_data["Product_Id"].astype(str)
|
| 40 |
+
input_data = input_data.drop(columns=["Product_Id"])
|
| 41 |
+
else:
|
| 42 |
+
ids = input_data.index.astype(str) # fallback to row indices
|
| 43 |
+
|
| 44 |
+
# Make predictions
|
| 45 |
preds = model.predict(input_data).tolist()
|
| 46 |
|
| 47 |
+
# Map Product_Id (or row index) → prediction
|
| 48 |
+
results = dict(zip(ids, preds))
|
| 49 |
|
| 50 |
return jsonify(results)
|
| 51 |
|