11from flask_restplus import Namespace , Resource , fields
22from werkzeug .datastructures import FileStorage
33from werkzeug .exceptions import BadRequest
4-
54from config import MODEL_META_DATA
6-
75from core .backend import ModelWrapper
86import os
9- import numpy as np
10- import pandas as pd
117
128api = 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+
3027label_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
3633predict_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
4239audio_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'
0 commit comments