Varun6299 commited on
Commit
3afe213
·
verified ·
1 Parent(s): 84e993b

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. Dockerfile +19 -0
  2. app.py +44 -0
  3. requirements.txt +5 -0
  4. xgb_tuned_model.pkl +3 -0
Dockerfile ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Use a lightweight Python image as the base
3
+ FROM python:3.8-slim
4
+
5
+ # Set the working directory
6
+ WORKDIR /app
7
+
8
+
9
+ # Copy all files from the current directory on the host to the container's /app directory
10
+ COPY . .
11
+
12
+ # Install Python dependencies listed in requirements.txt
13
+ RUN pip install --no-cache-dir -r requirements.txt
14
+
15
+ # Expose the port the app runs on
16
+ EXPOSE 5000
17
+
18
+ # Command to run the application using Gunicorn
19
+ CMD ["gunicorn", "--bind", "0.0.0.0:5000", "app:app"]
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from flask import Flask, request, jsonify
3
+ # Import make_prediction function after creating the predict.py file
4
+ # from predict import make_prediction # This import will work once predict.py is a separate file
5
+ import pandas as pd
6
+ import joblib
7
+ from sklearn.compose import ColumnTransformer
8
+
9
+ app = Flask(__name__)
10
+
11
+ @app.route('/predict', methods=['POST'])
12
+ def predict():
13
+ """
14
+ Receives product and store data, makes a sales prediction, and returns the result.
15
+ """
16
+ try:
17
+ data = request.get_json()
18
+
19
+ if data is None:
20
+ return jsonify({'error': 'Invalid JSON data provided'}), 400
21
+
22
+ model_path = 'xgb_tuned_model.pkl'
23
+
24
+ # Load the model
25
+ model = joblib.load(model_path)
26
+
27
+ # Convert the input data to a pandas DataFrame
28
+ # Assuming the input data dictionary keys match the original DataFrame columns
29
+ input_df = pd.DataFrame([data])
30
+
31
+ # Make prediction using the make_prediction function
32
+ prediction = model.predict(input_df)[0]
33
+
34
+ if prediction is None:
35
+ return jsonify({'error': 'Prediction could not be made'}), 500
36
+
37
+ return jsonify({'predicted_sales': prediction})
38
+
39
+ except Exception as e:
40
+ return jsonify({'error': str(e)}), 500
41
+
42
+ if __name__ == '__main__':
43
+ # This is for running locally, in a production Docker environment, a WSGI server would be used
44
+ app.run(host='0.0.0.0', port=5000) # Commented out to prevent blocking in notebook
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ Flask
2
+ pandas
3
+ scikit-learn
4
+ xgboost
5
+ joblib
xgb_tuned_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:658182bcf828670006557caf1497e397ecc267b68bfc44966006ae08ddb716a1
3
+ size 261993