Spaces:
Runtime error
Runtime error
Commit ·
d8827ea
1
Parent(s): 02ff318
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers import Wav2Vec2ForCTC, Wav2Vec2Tokenizer
|
| 3 |
+
|
| 4 |
+
# Load the model and tokenizer from the Hugging Face Model Hub
|
| 5 |
+
model_name = "BrendaTellez/SoundClassificationCNNRNN"
|
| 6 |
+
model = Wav2Vec2ForCTC.from_pretrained(SoundClassificationCNNRNN)
|
| 7 |
+
tokenizer = Wav2Vec2Tokenizer.from_pretrained(SoundClassificationCNNRNN)
|
| 8 |
+
|
| 9 |
+
# Load the audio file
|
| 10 |
+
audio_file = ""../input/environmental-sound-classification-50/audio/audio/44100/""
|
| 11 |
+
|
| 12 |
+
# Tokenize the audio file
|
| 13 |
+
inputs = tokenizer(audio_file, return_tensors="pt", padding=True)
|
| 14 |
+
|
| 15 |
+
# Use the model to classify the audio
|
| 16 |
+
with torch.no_grad():
|
| 17 |
+
logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
|
| 18 |
+
|
| 19 |
+
predicted_class_id = torch.argmax(logits, dim=-1)
|
| 20 |
+
predicted_class_label = tokenizer.decode(predicted_class_id[0])
|
| 21 |
+
|
| 22 |
+
print(predicted_class_label)
|