def construct_message(labels, face_annotations):
 response_text = PRETEXT
 label_desc = ''
 pos_labels = ['very likely', 'likely', 'possibly']
 for i in range(len(labels)):
  label_desc += ('\nScore is %s for %s' % (labels[i]['score'], labels[i]['description']))
 (joy, anger, sorrow, surprise) = extract_sentiment(face_annotations)
 for i in range(len(pos_labels)):
  if (joy[i] > 0):
   label_desc += ('\nWe found %s people who are %s experiencing joy' % (joy[i], pos_labels[i]))
  if (anger[i] > 0):
   label_desc += ('\nWe found %s people who are %s experiencing anger' % (anger[i], pos_labels[i]))
  if (sorrow[i] > 0):
   label_desc += ('\nWe found %s people who are %s experiencing sorrow' % (sorrow[i], pos_labels[i]))
  if (surprise[i] > 0):
   label_desc += ('\nWe found %s people who are %s experiencing surprise' % (surprise[i], pos_labels[i]))
 if (not label_desc):
  label_desc = ' No labels found.'
 response_text += label_desc
 resp = twilio.twiml.Response()
 resp.message(response_text)
 return resp

def construct_message ( labels , face_annotations ) : response_text = PRETEXT label_desc = '' pos_labels = [ 'very likely' , 'likely' , 'possibly' ] for i in range ( len ( labels ) ) : label_desc += ( '\nScore is %s for %s' % ( labels [ i ] [ 'score' ] , labels [ i ] [ 'description' ] ) ) ( joy , anger , sorrow , surprise ) = extract_sentiment ( face_annotations ) for i in range ( len ( pos_labels ) ) : if ( joy [ i ] > 0 ) : label_desc += ( '\nWe found %s people who are %s experiencing joy' % ( joy [ i ] , pos_labels [ i ] ) ) if ( anger [ i ] > 0 ) : label_desc += ( '\nWe found %s people who are %s experiencing anger' % ( anger [ i ] , pos_labels [ i ] ) ) if ( sorrow [ i ] > 0 ) : label_desc += ( '\nWe found %s people who are %s experiencing sorrow' % ( sorrow [ i ] , pos_labels [ i ] ) ) if ( surprise [ i ] > 0 ) : label_desc += ( '\nWe found %s people who are %s experiencing surprise' % ( surprise [ i ] , pos_labels [ i ] ) ) if ( not label_desc ) : label_desc = ' No labels found.' response_text += label_desc resp = twilio . twiml . Response ( ) resp . message ( response_text ) return resp
build up the response from the labels found .