Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline, WhisperProcessor, WhisperForConditionalGeneration
|
3 |
import torch
|
4 |
-
|
5 |
|
6 |
# Load Whisper model and processor
|
7 |
processor = WhisperProcessor.from_pretrained("openai/whisper-large")
|
@@ -12,12 +12,11 @@ emotion_classifier = pipeline("text-classification", model="SamLowe/roberta-base
|
|
12 |
|
13 |
# Define a function to process audio and analyze emotions
|
14 |
def transcribe_and_analyze(audio_path):
|
15 |
-
# Load audio
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
# Process audio with Whisper
|
20 |
-
input_features = processor(audio, return_tensors="pt").input_features
|
21 |
predicted_ids = model.generate(input_features)
|
22 |
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
|
23 |
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline, WhisperProcessor, WhisperForConditionalGeneration
|
3 |
import torch
|
4 |
+
import soundfile as sf
|
5 |
|
6 |
# Load Whisper model and processor
|
7 |
processor = WhisperProcessor.from_pretrained("openai/whisper-large")
|
|
|
12 |
|
13 |
# Define a function to process audio and analyze emotions
|
14 |
def transcribe_and_analyze(audio_path):
|
15 |
+
# Load audio from the provided file
|
16 |
+
audio, sample_rate = sf.read(audio_path)
|
17 |
+
|
|
|
18 |
# Process audio with Whisper
|
19 |
+
input_features = processor(audio, sampling_rate=sample_rate, return_tensors="pt").input_features
|
20 |
predicted_ids = model.generate(input_features)
|
21 |
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
|
22 |
|