Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -29,6 +29,29 @@ audio_model_name = "ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition"
|
|
29 |
audio_processor = AutoFeatureExtractor.from_pretrained(audio_model_name)
|
30 |
audio_model = AutoModelForAudioClassification.from_pretrained(audio_model_name).to(device)
|
31 |
audio_sampling_rate = 16000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
def calculate_angle(a, b, c):
|
34 |
"""Calculates the angle between three points."""
|
|
|
29 |
audio_processor = AutoFeatureExtractor.from_pretrained(audio_model_name)
|
30 |
audio_model = AutoModelForAudioClassification.from_pretrained(audio_model_name).to(device)
|
31 |
audio_sampling_rate = 16000
|
32 |
+
import os
|
33 |
+
|
34 |
+
def analyze_video(video_path):
|
35 |
+
if not video_path:
|
36 |
+
return "Error: No video input received!"
|
37 |
+
|
38 |
+
# Check file size (limit to ~50MB for Hugging Face Spaces)
|
39 |
+
max_size_mb = 50
|
40 |
+
file_size_mb = os.path.getsize(video_path) / (1024 * 1024)
|
41 |
+
|
42 |
+
if file_size_mb > max_size_mb:
|
43 |
+
return f"Error: File size ({file_size_mb:.2f}MB) exceeds the {max_size_mb}MB limit."
|
44 |
+
|
45 |
+
# Process the video normally
|
46 |
+
audio_path = extract_audio(video_path)
|
47 |
+
frames = extract_frames(video_path)
|
48 |
+
facial_emotions = analyze_facial_emotion(frames)
|
49 |
+
transcription = transcribe_audio(audio_path)
|
50 |
+
audio_emotion, _ = analyze_audio_emotion(transcription)
|
51 |
+
final_emotion = max(facial_emotions, key=facial_emotions.get) if facial_emotions else "Neutral"
|
52 |
+
|
53 |
+
return transcription, audio_emotion, final_emotion, facial_emotions, "emotion_pie_chart.png"
|
54 |
+
|
55 |
|
56 |
def calculate_angle(a, b, c):
|
57 |
"""Calculates the angle between three points."""
|