Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -44,15 +44,27 @@ def predict_churn():
|
|
| 44 |
@app.post('/v1/customerbatch')
|
| 45 |
def predict_churn_batch():
|
| 46 |
try:
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
return jsonify({str(i): float(p) for i, p in zip(df["Store_Id"], preds)})
|
| 54 |
except Exception as e:
|
| 55 |
-
return jsonify({
|
| 56 |
|
| 57 |
# Run the Flask app in debug mode
|
| 58 |
if __name__ == '__main__':
|
|
|
|
| 44 |
@app.post('/v1/customerbatch')
|
| 45 |
def predict_churn_batch():
|
| 46 |
try:
|
| 47 |
+
# Get the uploaded CSV file from the request
|
| 48 |
+
file = request.files['file']
|
| 49 |
+
if not file:
|
| 50 |
+
return jsonify({'error': 'No file uploaded'}), 400
|
| 51 |
|
| 52 |
+
# Read the file into a DataFrame
|
| 53 |
+
input_data = pd.read_csv(file)
|
| 54 |
+
|
| 55 |
+
# Make predictions using the model
|
| 56 |
+
predictions = model.predict(input_data.drop(columns=["Product_Id", "Store_Id","Product_Store_Sales_Total"], errors='ignore'))
|
| 57 |
+
|
| 58 |
+
# Pair predictions with Store_Id or Product_Id
|
| 59 |
+
output = {
|
| 60 |
+
str(store_id): float(pred)
|
| 61 |
+
for store_id, pred in zip(input_data["Store_Id"], predictions.round(2))
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
return jsonify(output)
|
| 65 |
|
|
|
|
| 66 |
except Exception as e:
|
| 67 |
+
return jsonify({'error': str(e)}), 500
|
| 68 |
|
| 69 |
# Run the Flask app in debug mode
|
| 70 |
if __name__ == '__main__':
|