original_docstring: Predict audio classes from input data
docstring: Predict audio classes from input data
docstring_tokens: Predict audio classes from input data
code: def post(self):
          """Predict audio classes from input data"""
          result = {'status': 'error'}
  
          args = input_parser.parse_args()
          print(args)
  
          if not re.match("audio/.*wav", str(args['audio'].mimetype)):
              e = BadRequest()
              e.data = {'status': 'error', 'message': 'Invalid file type/extension: ' + str(args['audio'].mimetype)}
              raise e
  
          audio_data = args['audio']
  
          # Getting the predictions
          try:
              preds = self.model_wrapper._predict(audio_data, args['start_time'])
          except ValueError as ex:
              print(ex)
              traceback.print_exc()
              e = BadRequest()
              e.data = {'status': 'error', 'message': 'Invalid start time: value outside audio clip'}
              raise e
  
          IBM_DF = self.model_wrapper.indices
          LABEL_MAPPING = IBM_DF[['display_name', 'class']].set_index('display_name').T.to_dict('dict')
          glob_df = pd.DataFrame(columns=['sub_label', 'confidence', 'label'])
  
          for el in preds:
              sub_label = el[1]
              num = el[2]
              new_label = LABEL_MAPPING.get(sub_label)['class']
              temp_df = pd.DataFrame([[sub_label, num, new_label]], columns=['sub_label', 'confidence', 'label'])
              glob_df = glob_df.append(temp_df)
  
  
          total_confidence = glob_df['confidence'].sum()
          sub_label = preds[0][1]
          prediction = LABEL_MAPPING.get(sub_label)['class']
  
          pred_df = glob_df.loc[glob_df['label'] == str(prediction)]
          prediction_sum = pred_df['confidence'].sum()
          normalized_ratio = prediction_sum / total_confidence
          
  
          result['prediction'] = str(prediction)
          result['normalized_ratio'] = normalized_ratio
          result['status'] = 'ok'
  
          print(result)
  
          return result
code_tokens: def post ( self ) : result = { 'status' : 'error' } args = input_parser . parse_args ( ) print ( args ) if not re . match ( "audio/.*wav" , str ( args [ 'audio' ] . mimetype ) ) : e = BadRequest ( ) e . data = { 'status' : 'error' , 'message' : 'Invalid file type/extension: ' + str ( args [ 'audio' ] . mimetype ) } raise e audio_data = args [ 'audio' ] try : preds = self . model_wrapper . _predict ( audio_data , args [ 'start_time' ] ) except ValueError as ex : print ( ex ) traceback . print_exc ( ) e = BadRequest ( ) e . data = { 'status' : 'error' , 'message' : 'Invalid start time: value outside audio clip' } raise e IBM_DF = self . model_wrapper . indices LABEL_MAPPING = IBM_DF [ [ 'display_name' , 'class' ] ] . set_index ( 'display_name' ) . T . to_dict ( 'dict' ) glob_df = pd . DataFrame ( columns = [ 'sub_label' , 'confidence' , 'label' ] ) for el in preds : sub_label = el [ 1 ] num = el [ 2 ] new_label = LABEL_MAPPING . get ( sub_label ) [ 'class' ] temp_df = pd . DataFrame ( [ [ sub_label , num , new_label ] ] , columns = [ 'sub_label' , 'confidence' , 'label' ] ) glob_df = glob_df . append ( temp_df ) total_confidence = glob_df [ 'confidence' ] . sum ( ) sub_label = preds [ 0 ] [ 1 ] prediction = LABEL_MAPPING . get ( sub_label ) [ 'class' ] pred_df = glob_df . loc [ glob_df [ 'label' ] == str ( prediction ) ] prediction_sum = pred_df [ 'confidence' ] . sum ( ) normalized_ratio = prediction_sum / total_confidence result [ 'prediction' ] = str ( prediction ) result [ 'normalized_ratio' ] = normalized_ratio result [ 'status' ] = 'ok' print ( result ) return result
short_docstring: Predict audio classes from input data
short_docstring_tokens: Predict audio classes from input data
comment: """Predict audio classes from input data"""$SEP$# Getting the predictions