Upload folder using huggingface_hub
Browse files- Dockerfile +11 -0
- app.py +78 -0
- requirements.txt +11 -0
Dockerfile
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY requirements.txt /app/requirements.txt
|
| 4 |
+
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
|
| 5 |
+
COPY app.py /app/
|
| 6 |
+
COPY gradboost_RSCV.joblib /app/
|
| 7 |
+
COPY RndmFrstReg_RSCV.joblib /app/
|
| 8 |
+
COPY pipeline.joblib /app/
|
| 9 |
+
COPY feature_names.joblib /app/
|
| 10 |
+
EXPOSE 7860
|
| 11 |
+
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "app:app"]
|
app.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask,request,jsonify
|
| 2 |
+
from flask_cors import CORS
|
| 3 |
+
import joblib
|
| 4 |
+
import numpy as np
|
| 5 |
+
import pandas as pd
|
| 6 |
+
import logging
|
| 7 |
+
|
| 8 |
+
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 9 |
+
|
| 10 |
+
app = Flask(__name__)
|
| 11 |
+
#CORS(app)
|
| 12 |
+
CORS(app, resources={r"/predict":{"origins":"*"}})
|
| 13 |
+
|
| 14 |
+
try:
|
| 15 |
+
model_gradbosot = joblib.load('gradboost_RSCV.joblib')
|
| 16 |
+
model_rndmfrst = joblib.load('RndmFrstReg_RSCV.joblib')
|
| 17 |
+
pipeline = joblib.load('pipeline.joblib')
|
| 18 |
+
feature_names = joblib.load('feature_names.joblib')
|
| 19 |
+
except Exception as Ex:
|
| 20 |
+
logging.error(f'Exception in loading joblib file: {Ex}')
|
| 21 |
+
|
| 22 |
+
required_features =['Product_Weight','Product_Sugar_Content','Product_Allocated_Area',
|
| 23 |
+
'Product_Type','Product_MRP',
|
| 24 |
+
'Store_Size','Store_Location_City_Type','Store_Type','Age_Of_Store'
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
@app.get('/')
|
| 28 |
+
def home():
|
| 29 |
+
logging.debug("Accessed endpoint of Home page")
|
| 30 |
+
return "Welcome to Superkart Prediction system"
|
| 31 |
+
|
| 32 |
+
@app.route('/predict', methods=['POST'])
|
| 33 |
+
def predict():
|
| 34 |
+
try:
|
| 35 |
+
|
| 36 |
+
data = request.get_json()
|
| 37 |
+
logging.debug(f"Input received:{data}")
|
| 38 |
+
if not data:
|
| 39 |
+
return jsonify({'Error':'No data provided for prediction'},400)
|
| 40 |
+
|
| 41 |
+
if not all(feature in data for feature in required_features):
|
| 42 |
+
feature_missing = [feature for feature in required_features if feature not in data]
|
| 43 |
+
logging.error(f"Exception feature missing:{feature_missing}")
|
| 44 |
+
return jsonify({'Exception':f'Feature missing {feature_missing}'},400)
|
| 45 |
+
|
| 46 |
+
feature_for_prediction =pd.DataFrame([{
|
| 47 |
+
'Product_Weight':float(data['Product_Weight']),
|
| 48 |
+
'Product_Sugar_Content':data['Product_Sugar_Content'],
|
| 49 |
+
'Product_Allocated_Area':float(data['Product_Allocated_Area']),
|
| 50 |
+
'Product_Type': data['Product_Type'],
|
| 51 |
+
'Product_MRP':float(data['Product_MRP']),
|
| 52 |
+
'Store_Size':data['Store_Size'],
|
| 53 |
+
'Store_Location_City_Type':data['Store_Location_City_Type'],
|
| 54 |
+
'Store_Type':data['Store_Type'],
|
| 55 |
+
'Age_Of_Store':float(data['Age_Of_Store'])
|
| 56 |
+
}],columns=required_features)
|
| 57 |
+
|
| 58 |
+
features_scaled = pipeline.transform(feature_for_prediction)
|
| 59 |
+
logging.debug(f"Features scaled: {features_scaled}")
|
| 60 |
+
|
| 61 |
+
prediction_gradboost = model_gradbosot.predict(features_scaled)[0]
|
| 62 |
+
prediction_randFrst = model_rndmfrst.predict(features_scaled)[0]
|
| 63 |
+
|
| 64 |
+
logging.debug(f"Prediction gradmodel: {prediction_gradboost}")
|
| 65 |
+
logging.debug(f"Prediction RandmFrst: {prediction_randFrst}")
|
| 66 |
+
|
| 67 |
+
return jsonify ({'gradientBoosting':float(prediction_gradboost),
|
| 68 |
+
'randomForest':float(prediction_randFrst)})
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
except Exception as ex:
|
| 72 |
+
logging.error(f'Exception: {ex}')
|
| 73 |
+
return jsonify({'Exception': str(ex) })
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
if __name__ == '__main__':
|
| 78 |
+
app.run(host='0.0.0.0', port=7860, debug=False)
|
requirements.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
numpy==2.0.2
|
| 3 |
+
scikit-learn==1.6.1
|
| 4 |
+
xgboost==2.1.4
|
| 5 |
+
joblib==1.4.2
|
| 6 |
+
flask==2.3.3
|
| 7 |
+
gunicorn==20.1.0
|
| 8 |
+
requests==2.28.1
|
| 9 |
+
uvicorn[standard]
|
| 10 |
+
streamlit==1.43.2
|
| 11 |
+
flask-cors==4.0.1
|