-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_hume.py
26 lines (20 loc) · 909 Bytes
/
run_hume.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from hume import HumeBatchClient
from hume.models.config import FaceConfig
import time
from dotenv import dotenv_values
env = dotenv_values(".env.local")
def detect_sentiment():
client = HumeBatchClient(env["HUME_API_KEY"])
config = FaceConfig()
files = ["captured_image.jpg"]
job = client.submit_job([], [config], files=files)
time.sleep(5)
predictions = job.get_predictions()
emotions = predictions[0]['results']['predictions'][0]['models']['face']['grouped_predictions'][0]['predictions'][0]['emotions']
sorted_emotions = sorted(emotions, key=lambda x: x['score'], reverse=True)[:6]
emotion_list = [emotion['name'] for emotion in sorted_emotions]
emotion_list = [emotion['name'] for emotion in sorted_emotions]
joined_emotions = ', '.join(emotion_list)
joined_emotions = ', '.join(emotion_list)
return joined_emotions
return joined_emotions