Spaces:
Runtime error
Runtime error
Testing
Browse files
app.py
CHANGED
@@ -4,22 +4,20 @@ import torch
|
|
4 |
import torchaudio
|
5 |
from transformers import Wav2Vec2FeatureExtractor, Wav2Vec2ForSequenceClassification
|
6 |
|
7 |
-
device =
|
8 |
|
9 |
model_name = "Hemg/human-emotion-detection"
|
10 |
feature_extractor = Wav2Vec2FeatureExtractor.from_pretrained(model_name)
|
11 |
-
model = Wav2Vec2ForSequenceClassification.from_pretrained(model_name)
|
|
|
12 |
|
13 |
def preprocess_audio(audio):
|
14 |
-
print('hallo')
|
15 |
waveform, sampling_rate = torchaudio.load(audio)
|
16 |
resampled_waveform = torchaudio.transforms.Resample(orig_freq=sampling_rate, new_freq=16000)(waveform)
|
17 |
return {'speech': resampled_waveform.numpy().flatten(), 'sampling_rate': 16000}
|
18 |
|
19 |
@spaces.GPU
|
20 |
def inference(audio):
|
21 |
-
print('hello')
|
22 |
-
|
23 |
example = preprocess_audio(audio)
|
24 |
inputs = feature_extractor(example['speech'], sampling_rate=16000, return_tensors="pt", padding=True)
|
25 |
inputs = inputs.to(device) # Move inputs to GPU
|
|
|
4 |
import torchaudio
|
5 |
from transformers import Wav2Vec2FeatureExtractor, Wav2Vec2ForSequenceClassification
|
6 |
|
7 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
8 |
|
9 |
model_name = "Hemg/human-emotion-detection"
|
10 |
feature_extractor = Wav2Vec2FeatureExtractor.from_pretrained(model_name)
|
11 |
+
model = Wav2Vec2ForSequenceClassification.from_pretrained(model_name)
|
12 |
+
model.to(device)
|
13 |
|
14 |
def preprocess_audio(audio):
|
|
|
15 |
waveform, sampling_rate = torchaudio.load(audio)
|
16 |
resampled_waveform = torchaudio.transforms.Resample(orig_freq=sampling_rate, new_freq=16000)(waveform)
|
17 |
return {'speech': resampled_waveform.numpy().flatten(), 'sampling_rate': 16000}
|
18 |
|
19 |
@spaces.GPU
|
20 |
def inference(audio):
|
|
|
|
|
21 |
example = preprocess_audio(audio)
|
22 |
inputs = feature_extractor(example['speech'], sampling_rate=16000, return_tensors="pt", padding=True)
|
23 |
inputs = inputs.to(device) # Move inputs to GPU
|