class EmotionShard(Shard): name = 'emotions' def __init__(self, model_path, logfile=None, **kwargs): """Initialize a Shard to analyze emotions from the webcam stream. kwargs are passed to emotion_recognition.EmotionRecognition.""" self.recognition = EmotionRecognition(model_path=model_path, **kwargs) self.classes = self.recognition.emotions if logfile is not None: self.memory = CSVMemory(logfile=logfile) else: logging.warning("Memory not activated for Shard '%s'." % self.name) self.memory = None self.state = None def reflect(self, rays): if 'faces' in rays: results = [] for face in rays['faces']: result = self.recognition.run_on_face(face['image']) result['position'] = face['bounding_box'] results.append(result) self.state = results return self.state if 'webcam' in rays: results = self.recognition.run(rays['webcam']) self.state = results return self.state else: raise Exception("Need webcam capture to detect emotions!")
user_interface = UserInterface(window) context = ContextRecognition() context.load_corpus("corpus/") context.load_model() emotion = EmotionRecognition(user_interface) emotion.start() # The chatbot will start listening to the user after they say "computer" # The bot will then read your emotion via webcam while input_sentence != "computer": user_interface.update_sprites("Listening...", "Emotion: None", "User: Unknown", "Primary Topics: ") user_interface.render() emotion.run() input_sentence = speech.recognize_speech() print "You said: ", input_sentence meeting_emotion = emotion.get_emotion() print "Emotion read: ", meeting_emotion # Make a call to see whether or not the user is recognized user_name = history_recollection() topic_extract = TopicExtraction() topic_extract.load_history(user_name) # Based on the emotion read from the webcam, the chatbot will respond differently if meeting_emotion is "Happy" or meeting_emotion is "Surprise":