Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -97,16 +97,21 @@ async def process_file(file_data: FileProcess):
|
|
97 |
|
98 |
|
99 |
def process_video(video_path):
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
confidences = {label: float(probs[i]) for i, label in enumerate(class_dict)}
|
108 |
-
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
if __name__ == "__main__":
|
112 |
logger.info("Starting the Face Emotion Recognition API")
|
|
|
97 |
|
98 |
|
99 |
def process_video(video_path):
|
100 |
+
# Load the image from the provided path
|
101 |
+
img = PILImage.create(video_path)
|
102 |
+
|
103 |
+
# Make the prediction
|
104 |
+
classification, _, probs = learn.predict(img)
|
105 |
+
|
106 |
+
# Convert the prediction to a confidence dictionary
|
107 |
+
confidences = {label: float(probs[i]) for i, label in enumerate(class_dict)}
|
108 |
+
|
109 |
+
# If classification is not formal, return 'informal'
|
110 |
+
if classification != 'formal':
|
111 |
+
informal_confidence = sum(confidences[label] for label in class_dict if label != 'formal')
|
112 |
+
return {'informal': informal_confidence}
|
113 |
+
else:
|
114 |
+
return {'formal': confidences['formal']}
|
115 |
|
116 |
if __name__ == "__main__":
|
117 |
logger.info("Starting the Face Emotion Recognition API")
|