def handle_uploaded_file(file): client = Client.emotion(settings.OXFORD_KEY) recognizeResult = client.recognize({"stream": file}) im = Image.open(file) draw = ImageDraw.Draw(im) happyscore = 0 for emotionResult in recognizeResult: rect = emotionResult["faceRectangle"] x = emotionResult["faceRectangle"]["left"] y = emotionResult["faceRectangle"]["top"] x1 = emotionResult["faceRectangle"]["left"] + emotionResult["faceRectangle"]["width"] y1 = emotionResult["faceRectangle"]["top"] + emotionResult["faceRectangle"]["height"] draw.rectangle([x, y, x1, y1]) happiness = emotionResult["scores"]["happiness"] sadness = emotionResult["scores"]["sadness"] if happiness > sadness: happyscore = happyscore + 1 else: happyscore = happyscore - 1 modified = TemporaryFile() im.save(modified, "JPEG") return modified, happyscore
def handle_uploaded_file(file): client = Client.emotion(settings.OXFORD_KEY) recognizeResult = client.recognize({'stream': file}) im = Image.open(file) draw = ImageDraw.Draw(im) happyscore = 0 for emotionResult in recognizeResult: rect = emotionResult['faceRectangle'] x = emotionResult['faceRectangle']['left'] y = emotionResult['faceRectangle']['top'] x1 = emotionResult['faceRectangle']['left'] + emotionResult['faceRectangle']['width'] y1 = emotionResult['faceRectangle']['top'] + emotionResult['faceRectangle']['height'] draw.rectangle([x,y,x1,y1]) happiness = emotionResult['scores']["happiness"] sadness = emotionResult['scores']["sadness"] if (happiness > sadness): happyscore = happyscore + 1 else: happyscore = happyscore - 1 modified = TemporaryFile() im.save(modified,'JPEG') return modified, happyscore
def test_constructor_sets_instrumentation_key(self): face = Client.face('key') vision = Client.vision('key') emotion = Client.emotion('key') self.assertIsNotNone(face) self.assertIsNotNone(vision) self.assertIsNotNone(emotion)
def setUpClass(cls): # set up self.client for tests cls.client = Client.emotion(os.environ['OXFORD_EMOTION_API_KEY']) cls.localFilePrefix = os.path.join(rootDirectory, 'tests', 'images') # set common recognize options cls.recognizeOptions = {'faceRectangles': ''}
def setUpClass(cls): # set up self.client for tests cls.client = Client.emotion(os.environ["OXFORD_EMOTION_API_KEY"]) cls.localFilePrefix = os.path.join(rootDirectory, "tests", "images") # set common recognize options cls.recognizeOptions = {"faceRectangles": ""}