jpkarthikeyan commited on
Commit
403a2e5
·
verified ·
1 Parent(s): 334889e

Upload folder using huggingface_hub

Browse files
BagReg_RSCV.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bd9c526bddd1dfa2f55dbad013f113e4c8a1857bd60d339babc712947fceba5c
3
+ size 1092152
DTree_RSCV.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:be4004c902f4e13371eb90fc79241c0fadeac14177bd6a5877a897cbb53afdd8
3
+ size 169889
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 scalar.joblib /app/
9
+ COPY feature_names.joblib /app/
10
+ EXPOSE 7860
11
+ CMD ["gunicorn", "--bind", "0.0.0.0:7860", "app:app"]
RndmFrstReg_RSCV.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:58bdda6bcee5c0927741e6f3edb0adc87567118f812c72941e1f6e405abd2fa1
3
+ size 6684337
adaboost_RSCV.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:486d2a718dc85f26ada16f554409d0ad8fcdc9d256df4478dc0b8b2b873aaafe
3
+ size 105720
app.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ from flask_cors import CORS
3
+ import joblib
4
+ import pandas as pd
5
+ import numpy as np
6
+ import logging
7
+
8
+
9
+ app = Flask(__name__)
10
+ CORS(app)
11
+ try:
12
+ model = joblib.load('gradboost_RSCV.joblib')
13
+ model_rf = joblib.load('RndmFrstReg_RSCV.joblib')
14
+ pipeline = joblib.load('pipeline.joblib')
15
+ feature_names = joblib.load('feature_names.joblib')
16
+ except Exception as ex:
17
+ logging.error(f"Exception in loading the model: {ex}")
18
+
19
+ valid_store_size =['Small','Medium','High']
20
+ valid_city_types =['Tier 1','Tier 2','Tier 3']
21
+ valid_sugar_content = ['Low Sugar', 'Regular', 'High Sugar']
22
+ valid_product_type = ['Frozen Foods','Dairy','Canned', 'Baking Goods',
23
+ 'Health and Hygiene','Snack Foods', 'Meat',
24
+ 'Household','Hard Drinks','Fruits and Vegetables','Breads',
25
+ 'Soft Drinks','Breakfast','Others','Starchy Foods','Seafood']
26
+ valid_store_types = ['Supermarket Type2','Supermarket Type1','Departmental Store','Food Mart']
27
+ required_features = ['Product_Weight','Product_Allocated_Area',
28
+ 'Product_MRP','Age_Of_Store','Store_Size',
29
+ 'Store_Location_City_Type','Product_Type',
30
+ 'Product_Sugar_Content','Store_Type']
31
+
32
+ @app.route('/predict', methods=['POST'])
33
+ def predict():
34
+ try:
35
+ data = request.get_json()
36
+ if not data:
37
+ return jsonify({'Exception':'No data provided for prediction'}),400
38
+
39
+
40
+ if not all(featr in data for featr in required_features):
41
+ missing_features = [featr for featr in required_features if featr not in data]
42
+ return jsonify({'Exception':f'Missing required features: {missing_features}'}),400
43
+
44
+ input_data = pd.DataFrame([{
45
+ 'Product_Type':data['Product_Type'],
46
+ 'Product_Sugar_Content':data['Product_Sugar_Content'],
47
+ 'Store_Type':data['Store_Type'],
48
+ 'Store_Size':data['Store_Size'],
49
+ 'Store_Location_City_Type':data['Store_Location_City_Type'],
50
+ 'Product_Weight':float(data['Product_Weight']),
51
+ 'Product_Allocated_Area':float(data['Product_Allocated_Area']),
52
+ 'Product_MRP':float(data['Product_MRP']),
53
+ 'Age_Of_Store':int(data['Age_Of_Store'])
54
+ }])
55
+
56
+ if input_data['Store_Size'].iloc[0] not in valid_store_size:
57
+ return jsonify({'Exception':f'Invallid Store size: must be in {valid_store_size}'})
58
+ if input_data['Store_Location_City_Type'].iloc[0] not in valid_city_types:
59
+ return jsonify({'Exception':f'Invallid Store size: must be in {valid_city_types}'})
60
+ if input_data['Store_Type'].iloc[0] not in valid_store_types:
61
+ return jsonify({'Exception':f'Invallid Store size: must be in {valid_store_types}'})
62
+ if input_data['Product_Sugar_Content'].iloc[0] not in valid_sugar_content:
63
+ return jsonify({'Exception':f'Invallid Store size: must be in {valid_sugar_content}'})
64
+ if input_data['Product_Type'].iloc[0] not in valid_product_type:
65
+ return jsonify({'Exception':f'Invallid Store size: must be in {valid_product_type}'})
66
+
67
+ scaled_features = pipeline.transform(input_data)
68
+
69
+ grad_prediction = model.predict(scaled_features)
70
+ Rf_Prediction = model_rf.predict(scaled_features)
71
+
72
+ return jsonify({'Gradient Bossting Model':grad_prediction.tolist()[0],
73
+ 'Random Forest Model': Rf_Prediction.tolist()[0]
74
+ })
75
+
76
+ except Exception as ex:
77
+ logging.error(f"Exception:{ex}")
78
+ return jsonify({'Exception':ex}),500
79
+
80
+
81
+ if __name__ == '__main__':
82
+ app.run(host='0.0.0.0',port=7860, debug=False)
feature_names.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:236dab046323140493cba8360cd1b44de3f5b2828bbd060494ed3c749b43ab0b
3
+ size 666
gradboost_RSCV.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f30fdc5ef7807e6eebb51a3e40e36fdc2c731cc787f9e832adf55b42ee11410b
3
+ size 569801
pipeline.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9d33b2639b50b24df13f49d5c2b45dd4aa78ba7292940b5ef3132ebc7d33f829
3
+ size 5896
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