sid22669 commited on
Commit
00b66d9
·
verified ·
1 Parent(s): 0b7049c

Upload 4 files

Browse files
Files changed (4) hide show
  1. DockerFile +18 -0
  2. app.py +36 -0
  3. random_forest_model.joblib +3 -0
  4. requirements.txt +3 -0
DockerFile ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use the official Python image
2
+ FROM python:3.9-slim
3
+
4
+ # Set the working directory in the container
5
+ WORKDIR /app
6
+
7
+ # Copy the current directory contents into the container at /app
8
+ COPY . /app
9
+
10
+ # Install any needed dependencies specified in requirements.txt
11
+ RUN pip install --no-cache-dir -r requirements.txt
12
+
13
+ # Make port 5000 available to the world outside this container
14
+ EXPOSE 7820
15
+
16
+ # Run app.py when the container launches
17
+ CMD ["python", "app.py"]
18
+
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, jsonify, request, render_template
2
+ import numpy as np
3
+ import joblib
4
+
5
+ app = Flask(__name__)
6
+
7
+ try:
8
+ model = joblib.load('random_forest_model.joblib')
9
+ status = 'Loaded'
10
+ except:
11
+ status= 'Not loaded'
12
+
13
+ @app.route('/', methods = ['GET'])
14
+ def health_check():
15
+ return render_template('index.html')
16
+
17
+ @app.route('/predict', methods = ['POST'])
18
+ def predict():
19
+ try:
20
+
21
+ data = np.array([[float(request.form.get('input1', 0)),
22
+ float(request.form.get('input2', 0)),
23
+ float(request.form.get('input3', 0)),
24
+ float(request.form.get('input4', 0)),
25
+ float(request.form.get('input5', 0)),
26
+ float(request.form.get('input6', 0)),
27
+ float(request.form.get('input7', 0))]])
28
+
29
+ prediction = model.predict(data).tolist()
30
+ return render_template('output.html', prediction = prediction)
31
+ except Exception as e:
32
+ return jsonify({'data': e})
33
+
34
+
35
+ if __name__ == '__main__':
36
+ app.run(debug=True, port = 7820)
random_forest_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:659ff6618b8604bafb159401806901f91d9ca0fc62311fa8b5785982a15ed76a
3
+ size 6781057
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ flask
2
+ numpy
3
+ joblib