-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathemotion-txt-reader.py
21 lines (18 loc) · 936 Bytes
/
emotion-txt-reader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import datetime, os, traceback
# Description: Reads the last line of a text file and converts it to an integer to pass to unreal engine.
# Replace the file path with the path to your 'common_emotions.txt' text file path, created using emotional-detection-main.py when in production mode.
txtFilePath = 'C:/Users/Frost/Desktop/CodingProjects/EmotionDetection-main/common_emotions.txt'
global output
emotion_classes = {0: 'Angry', 1: 'Fear', 2: 'Happy',
3: 'Neutral', 4: 'Sad', 5: 'Surprise'}
with open(txtFilePath, 'r') as file:
lines = file.readlines()
lines.reverse()
for line in lines:
if line.strip():
try:
output = int(line)
print(f"Common Index: {output}\t\tEmotion: {emotion_classes[output]}\t{datetime.datetime.now()}\n")
break
except ValueError:
print(traceback.format_exc())