Upload 5 files
Browse files- Dockerfile.dockerfile +12 -0
- app.py +48 -0
- decision_tree_model.pkl +3 -0
- requirements.txt +7 -0
- xgboost_model.pkl +3 -0
Dockerfile.dockerfile
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
COPY requirements.txt .
|
| 6 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
+
|
| 8 |
+
COPY . .
|
| 9 |
+
|
| 10 |
+
EXPOSE 7860
|
| 11 |
+
|
| 12 |
+
CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]
|
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
%%writefile backend_files/app.py
|
| 2 |
+
# app.py
|
| 3 |
+
import numpy as np
|
| 4 |
+
from flask import Flask, request, jsonify
|
| 5 |
+
import joblib
|
| 6 |
+
import pandas as pd
|
| 7 |
+
|
| 8 |
+
# Inititialize Flask app with name
|
| 9 |
+
sales_prediction_api = Flask("Sales Predictor")
|
| 10 |
+
|
| 11 |
+
# Load the trained model predictor model
|
| 12 |
+
dt_model = joblib.load("decision_tree_model.pkl")
|
| 13 |
+
|
| 14 |
+
# Define a route for the home page
|
| 15 |
+
@sales_prediction_api.route('/')
|
| 16 |
+
def home():
|
| 17 |
+
return "Sales Prediction API"
|
| 18 |
+
|
| 19 |
+
# Define an endpoint to predict sales
|
| 20 |
+
@sales_prediction_api.post('/predict')
|
| 21 |
+
def predict():
|
| 22 |
+
# Get the data from the request
|
| 23 |
+
data = request.get_json()
|
| 24 |
+
|
| 25 |
+
# Extract relevant features from the input data
|
| 26 |
+
sample = {
|
| 27 |
+
'product_weight' = data['product_weight']
|
| 28 |
+
'product_sugar_content' = data['product_sugar_content']
|
| 29 |
+
'Product_Allocated_Area ' = data['Product_Allocated_Area']
|
| 30 |
+
'Product_Type' = data['Product_Type]
|
| 31 |
+
'Product_MRP' = data['Product_MRP']
|
| 32 |
+
'Store_Size' = data['Store_Size]
|
| 33 |
+
'Store_Location_City_Type' = data['Store_Location_City_Type']
|
| 34 |
+
'Store_Type' = data['Store_Type']
|
| 35 |
+
'Store_Age' = data['Store_Age']
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
#convert the extracted data into a dataframe
|
| 39 |
+
sample_df = pd.DataFrame(sample, index=[0])
|
| 40 |
+
|
| 41 |
+
#make a sales prediction using the model
|
| 42 |
+
prediction = dt_model.predict(sample_df).tolist()[0]
|
| 43 |
+
|
| 44 |
+
#return the prediction as a JSON response
|
| 45 |
+
return jsonify({'prediction': prediction})
|
| 46 |
+
|
| 47 |
+
if __name__ == '__main__':
|
| 48 |
+
app.run(debug=True)
|
decision_tree_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ea3b7c00e81dc02cf0ab4af6c4714fe8f799da15d9be8158e77c612d096c6663
|
| 3 |
+
size 41201
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
flask
|
| 3 |
+
pandas
|
| 4 |
+
numpy
|
| 5 |
+
scikit-learn
|
| 6 |
+
xgboost
|
| 7 |
+
joblib
|
xgboost_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:eb60b8f8584a03d8f18c14d36e93b36a5c4d75d993630ebcab0b875dd2b9ae15
|
| 3 |
+
size 1938822
|