charan commited on
Commit
8e3e9e5
1 Parent(s): af230e2

Deployment Ready

Browse files
Files changed (4) hide show
  1. CNN+LSTM.h5 +3 -0
  2. app.py +42 -0
  3. dockerfile +11 -0
  4. requirements.txt +45 -0
CNN+LSTM.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5930dc2a7cc10348608daea68450c70521a31a97bc803143a9b78b40bccec622
3
+ size 81208
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ import numpy as np
3
+ from keras.models import load_model
4
+
5
+ app = Flask(__name__)
6
+
7
+ # Load the trained model
8
+ model = load_model('CNN+LSTM.h5')
9
+
10
+ @app.route('/predict', methods=['POST'])
11
+ def predict():
12
+ try:
13
+ # Get the data from the POST request
14
+ data = request.get_json(force=True)
15
+
16
+ # Convert data into numpy array and reshape for prediction
17
+ data_array = np.array(data['data'])
18
+ data_array = np.reshape(data_array, (data_array.shape[0], data_array.shape[1], 1))
19
+
20
+ # Make prediction using the loaded model
21
+ prediction = model.predict(data_array)
22
+ labels=["Normal","Abnormal"]
23
+
24
+ # Convert prediction to binary (0 or 1)
25
+ prediction_binary = [1 if p >= 0.5 else 0 for p in prediction]
26
+ # lables=["Normal","Abnormal"]
27
+
28
+ # Return the prediction
29
+ return jsonify({'prediction':labels[prediction_binary[0]]})
30
+
31
+ except Exception as e:
32
+ return jsonify({'error': str(e)})
33
+ # # This is the entry point for AWS Lambda
34
+ # def lambda_handler(event, context):
35
+ # return awsgi.response(app, event, context)
36
+
37
+ if __name__ == '__main__':
38
+ # Save the model to a file
39
+ model.save('CNN+LSTM.h5')
40
+
41
+ # Run the Flask app
42
+ app.run(debug=True)
dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ COPY . .
10
+
11
+ CMD ["gunicorn","-b","0.0.0.0:7860","app:app"]
requirements.txt ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ absl-py
2
+ astunparse
3
+ blinker
4
+ botocore
5
+ cachetools
6
+ certifi
7
+ charset-normalizer
8
+ click
9
+ colorama
10
+ Flask
11
+ flatbuffers
12
+ gast
13
+ google-auth
14
+ google-auth-oauthlib
15
+ google-pasta
16
+ grpcio
17
+ h5py
18
+ idna
19
+ itsdangerous
20
+ Jinja2
21
+ jmespath
22
+ keras
23
+ libclang
24
+ Markdown
25
+ MarkupSafe
26
+ numpy
27
+ oauthlib
28
+ opt-einsum
29
+ packaging
30
+ protobuf
31
+ pyasn1
32
+ pyasn1-modules
33
+ python-dateutil
34
+ requests
35
+ requests-oauthlib
36
+ rsa
37
+ s3transfer
38
+ six
39
+ tensorflow
40
+ termcolor
41
+ typing_extensions
42
+ urllib3
43
+ Werkzeug
44
+ wrapt
45
+ gunicorn