Skip to content

Commit a0d2a28

Browse files
authored
update requests params and install from requirements.txt (#15)
resolves #8, resolves #9
1 parent f1b3cb3 commit a0d2a28

File tree

4 files changed

+18
-26
lines changed

4 files changed

+18
-26
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
Dockerfile
21
README.*
32
docs/
43
.git/

Dockerfile

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,8 @@ RUN wget -nv --show-progress --progress=bar:force:noscroll http://max-assets.s3-
44
RUN wget -nv --show-progress --progress=bar:force:noscroll http://max-assets.s3-api.us-geo.objectstorage.softlayer.net/audioset/vggish_pca_params.npz && mv vggish_pca_params.npz /workspace/assets/
55
RUN wget -nv --show-progress --progress=bar:force:noscroll http://max-assets.s3-api.us-geo.objectstorage.softlayer.net/audioset/classifier_model.h5 && mv classifier_model.h5 /workspace/assets/
66

7-
# Python package versions
8-
ARG numpy_version=1.13.1
9-
ARG tf_version=1.8.0
10-
ARG scipy_version=0.19.1
11-
ARG six_version=1.10.0
12-
13-
RUN pip install numpy==${numpy_version} && \
14-
pip install tensorflow==${tf_version} && \
15-
pip install scipy==${scipy_version} && \
16-
pip install resampy && \
17-
pip install six==${six_version} && \
18-
pip install pandas && \
19-
pip install keras && \
20-
pip install h5py && \
21-
pip install json_tricks
7+
COPY requirements.txt /workspace
8+
RUN pip install -r requirements.txt
229

2310
COPY . /workspace
2411

api/model.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
from flask_restplus import Namespace, Resource, fields
22
from werkzeug.datastructures import FileStorage
33
from werkzeug.exceptions import BadRequest
4-
54
from config import MODEL_META_DATA
6-
75
from core.backend import ModelWrapper
86
import os
9-
import numpy as np
10-
import pandas as pd
117

128
api = Namespace('model', description='Model information and inference operations')
139

@@ -27,20 +23,22 @@ def get(self):
2723
"""Return the metadata associated with the model"""
2824
return MODEL_META_DATA
2925

26+
3027
label_prediction = api.model('LabelPrediction', {
3128
'label_id': fields.String(required=False, description='Label identifier'),
32-
'label': fields.String(required=True, description='Class label'),
29+
'label': fields.String(required=True, description='Audio class label'),
3330
'probability': fields.Float(required=True)
3431
})
3532

3633
predict_response = api.model('ModelPredictResponse', {
3734
'status': fields.String(required=True, description='Response status message'),
38-
'predictions': fields.List(fields.Nested(label_prediction), description='Predicted labels and probabilities')
35+
'predictions': fields.List(fields.Nested(label_prediction), description='Predicted audio classes and probabilities')
3936
})
4037

4138
# set up parser for audio input data
4239
audio_parser = api.parser()
43-
audio_parser.add_argument('audio', type=FileStorage, location='files', required=True)
40+
audio_parser.add_argument('audio', type=FileStorage, location='files', required=True,
41+
help="signed 16-bit PCM WAV audio file")
4442

4543

4644
@api.route('/predict')
@@ -61,7 +59,7 @@ def post(self):
6159
if os.path.exists("/audio.wav"):
6260
os.remove("/audio.wav")
6361

64-
if('.wav' in str(args['audio'])):
62+
if '.wav' in str(args['audio']):
6563
file = open("/audio.wav", "wb")
6664
file.write(audio_data)
6765
file.close()
@@ -70,10 +68,10 @@ def post(self):
7068
e.data = {'status': 'error', 'message': 'Invalid file type/extension'}
7169
raise e
7270

73-
#Getting the predicions
71+
# Getting the predictions
7472
preds = self.mw.predict("/audio.wav")
7573

76-
#Aligning the predictions to the required API format
74+
# Aligning the predictions to the required API format
7775
label_preds = [{'label_id': p[0], 'label': p[1], 'probability': p[2]} for p in preds]
7876
result['predictions'] = label_preds
7977
result['status'] = 'ok'

requirements.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
numpy==1.13.1
2+
tensorflow==1.8.0
3+
scipy==0.19.1
4+
resampy
5+
six==1.10.0
6+
pandas
7+
keras
8+
h5py

0 commit comments

Comments
 (0)