Spaces:
Runtime error
Runtime error
from fer import Video | |
import pandas as pd | |
def analyze_video_emotions(video_file_path, face_detector): | |
""" | |
Analyzes the emotions in a given video file and returns a dataframe of scores. | |
""" | |
input_video = Video(video_file_path) | |
processing_data = input_video.analyze(face_detector, display=False) | |
if not processing_data: | |
print("No faces detected in the video.") | |
return pd.DataFrame() | |
vid_df = input_video.to_pandas(processing_data) | |
vid_df = input_video.get_first_face(vid_df) | |
vid_df = input_video.get_emotions(vid_df) | |
emotions = ['angry', 'disgust', 'fear', 'happy', 'sad', 'surprise', 'neutral'] | |
emotions_values = [sum(vid_df[emotion]) for emotion in emotions] | |
score_comparisons = pd.DataFrame({ | |
'Human Emotions': [emotion.capitalize() for emotion in emotions], | |
'Emotion Value from the Video': emotions_values | |
}) | |
return score_comparisons | |