Upload folder using huggingface_hub
Browse files- Dockerfile +10 -0
- app.py +52 -0
- requirements.txt +11 -0
Dockerfile
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM python:3.9-slim
|
| 3 |
+
|
| 4 |
+
WORKDIR/app
|
| 5 |
+
|
| 6 |
+
COPY . .
|
| 7 |
+
|
| 8 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 9 |
+
|
| 10 |
+
CMD ["gunicorn","-w","4","-b","0.0.0.0:7860","app:app"]
|
app.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import joblib
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from flask import Flask, request, jsonify
|
| 4 |
+
|
| 5 |
+
app = Flask('SuperKart Sales Predictor')
|
| 6 |
+
|
| 7 |
+
# Load the saved model
|
| 8 |
+
saved_model = joblib.load(saved_model_path)
|
| 9 |
+
|
| 10 |
+
@app.get('/')
|
| 11 |
+
def home():
|
| 12 |
+
return 'Welcome to SuperKart Sales Predictor'
|
| 13 |
+
|
| 14 |
+
@app.post('/predict')
|
| 15 |
+
def predict_sales():
|
| 16 |
+
store_data = request.get_json()
|
| 17 |
+
|
| 18 |
+
sample = {
|
| 19 |
+
'Product_Weight' : store_data['Product_Weight'],
|
| 20 |
+
'Product_Sugar_Content' : store_data['Product_Sugar_Content'],
|
| 21 |
+
'Product_Allocated_Area' : store_data['Product_Allocated_Area'],
|
| 22 |
+
'Product_Type' : store_data['Product_Type'],
|
| 23 |
+
'Product_MRP' : store_data['Product_MRP'],
|
| 24 |
+
'Store_Id' : store_data['Store_Id'],
|
| 25 |
+
'Store_Size' : store_data['Store_Size'],
|
| 26 |
+
'Store_Location_City_Type' : store_data['Store_Location_City_Type'],
|
| 27 |
+
'Store_Type' : store_data['Store_Type'],
|
| 28 |
+
'Store_Age' : store_data['Store_Age']
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
input_data = pd.DataFrame([sample])
|
| 32 |
+
|
| 33 |
+
predictions = saved_model.predict(input_data).tolist()[0]
|
| 34 |
+
|
| 35 |
+
return jsonify({'prediction': predictions})
|
| 36 |
+
|
| 37 |
+
@app.post('/predict_batch')
|
| 38 |
+
def predict_batch():
|
| 39 |
+
file = request.files['file']
|
| 40 |
+
input_data = pd.read_csv(file)
|
| 41 |
+
|
| 42 |
+
predictions = saved_model.predict(input_data).tolist()
|
| 43 |
+
|
| 44 |
+
store_id_list = input_data.storeID.values.tolist()
|
| 45 |
+
output_dict = dict(zip(store_id_list, predictions))
|
| 46 |
+
|
| 47 |
+
return output_dict
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
if __name__ == '__main__':
|
| 51 |
+
app.run(debug=True)
|
| 52 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
pandas==2.2.2
|
| 3 |
+
numpy==2.0.2
|
| 4 |
+
scikit-learn==1.6.1
|
| 5 |
+
xgboost==2.1.4
|
| 6 |
+
flask==2.2.2
|
| 7 |
+
joblib==1.4.2
|
| 8 |
+
Werkzeug==2.2.2
|
| 9 |
+
gunicorn==20.1.0
|
| 10 |
+
requests==2.32.3
|
| 11 |
+
uvicorn[standard]
|