Supreeth15 commited on
Commit
5b5e689
·
verified ·
1 Parent(s): 073d6fa

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +13 -0
  2. app.py +63 -0
  3. requirements.txt +8 -0
  4. superkart_best_model.pkl +3 -0
Dockerfile ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ FROM python:3.9-slim
3
+
4
+ WORKDIR /app
5
+
6
+ COPY requirements.txt .
7
+ RUN pip install --no-cache-dir -r requirements.txt
8
+
9
+ COPY . .
10
+
11
+ EXPOSE 7860
12
+
13
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from flask import Flask, request, jsonify
3
+ import joblib
4
+ import pandas as pd
5
+ import numpy as np
6
+
7
+ app = Flask(__name__)
8
+
9
+ # Load the trained model
10
+ try:
11
+ model = joblib.load('superkart_best_model.pkl')
12
+ print("Model loaded successfully!")
13
+ except Exception as e:
14
+ print(f"Error loading model: {e}")
15
+ model = None
16
+
17
+ @app.route('/')
18
+ def home():
19
+ return jsonify({
20
+ 'message': 'SuperKart Sales Prediction API',
21
+ 'status': 'active',
22
+ 'endpoints': {
23
+ 'predict': '/predict (POST)',
24
+ 'health': '/health (GET)'
25
+ }
26
+ })
27
+
28
+ @app.route('/predict', methods=['POST'])
29
+ def predict():
30
+ try:
31
+ if model is None:
32
+ return jsonify({'error': 'Model not loaded', 'status': 'error'}), 500
33
+
34
+ # Get data from request
35
+ data = request.get_json()
36
+
37
+ # Create DataFrame from input
38
+ df = pd.DataFrame([data])
39
+
40
+ # Make prediction
41
+ prediction = model.predict(df)[0]
42
+
43
+ return jsonify({
44
+ 'predicted_sales': float(prediction),
45
+ 'input_data': data,
46
+ 'status': 'success'
47
+ })
48
+
49
+ except Exception as e:
50
+ return jsonify({
51
+ 'error': str(e),
52
+ 'status': 'error'
53
+ }), 400
54
+
55
+ @app.route('/health', methods=['GET'])
56
+ def health():
57
+ return jsonify({
58
+ 'status': 'healthy',
59
+ 'model_loaded': model is not None
60
+ })
61
+
62
+ if __name__ == '__main__':
63
+ app.run(host='0.0.0.0', port=7860, debug=True)
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+
2
+ flask==2.3.3
3
+ pandas==1.5.3
4
+ numpy==1.24.3
5
+ scikit-learn==1.3.0
6
+ joblib==1.3.2
7
+ streamlit==1.28.0
8
+ plotly==5.17.0
superkart_best_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f3eb5e0488c2478745f3230f0ab7e9ed02c8e7c3efc91bfa7a1242ad5b8f3341
3
+ size 26038563