Spaces:
Runtime error
Runtime error
Commit ·
9ae315d
1
Parent(s): f17f0ae
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,17 @@
|
|
| 1 |
import torch
|
| 2 |
from transformers import Wav2Vec2ForCTC, Wav2Vec2Tokenizer
|
| 3 |
|
| 4 |
-
#
|
|
|
|
|
|
|
|
|
|
| 5 |
model_name = "BrendaTellez/SoundClassification"
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# Load the audio file
|
| 10 |
audio_file = "../input/environmental-sound-classification-50/audio/audio/44100/"
|
|
@@ -19,4 +26,5 @@ with torch.no_grad():
|
|
| 19 |
predicted_class_id = torch.argmax(logits, dim=-1)
|
| 20 |
predicted_class_label = tokenizer.decode(predicted_class_id[0])
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
from transformers import Wav2Vec2ForCTC, Wav2Vec2Tokenizer
|
| 3 |
|
| 4 |
+
# Get user input for the text
|
| 5 |
+
text = input("Enter a sentence to classify the sound: ")
|
| 6 |
+
|
| 7 |
+
# Get the name of the sound classification model
|
| 8 |
model_name = "BrendaTellez/SoundClassification"
|
| 9 |
+
print("Using sound classification model:", model_name)
|
| 10 |
+
|
| 11 |
+
# Load the model and tokenizer from the Hugging Face Model Hub
|
| 12 |
+
api_token = "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"
|
| 13 |
+
model = Wav2Vec2ForCTC.from_pretrained(model_name, use_auth_token=True, token=api_token)
|
| 14 |
+
tokenizer = Wav2Vec2Tokenizer.from_pretrained(model_name, use_auth_token=True, token=api_token)
|
| 15 |
|
| 16 |
# Load the audio file
|
| 17 |
audio_file = "../input/environmental-sound-classification-50/audio/audio/44100/"
|
|
|
|
| 26 |
predicted_class_id = torch.argmax(logits, dim=-1)
|
| 27 |
predicted_class_label = tokenizer.decode(predicted_class_id[0])
|
| 28 |
|
| 29 |
+
# Print the predicted class label for the user to see
|
| 30 |
+
print("The predicted sound class for the sentence", text, "is:", predicted_class_label)
|