BrendaTellez commited on
Commit
3ce9398
·
1 Parent(s): 69dceb4

delete app2.py

Browse files
Files changed (1) hide show
  1. app2.py +0 -35
app2.py DELETED
@@ -1,35 +0,0 @@
1
- import os
2
- import torch
3
- import torchaudio
4
- from transformers import Wav2Vec2ForCTC, Wav2Vec2Tokenizer
5
-
6
- # Set the Hugging Face API token
7
- os.environ["HUGGINGFACE_TOKEN"] = "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"
8
-
9
- # Load the pre-trained model and tokenizer
10
- model_name = "BrendaTellez/sounds2"
11
- model = Wav2Vec2ForCTC.from_pretrained(model_name, use_auth_token=True)
12
- tokenizer = Wav2Vec2Tokenizer.from_pretrained(model_name, use_auth_token=True)
13
-
14
- # Get the audio file from the user
15
- file_path = input("Enter the path to the audio file: ")
16
-
17
- # Load the audio file using torchaudio
18
- waveform, sample_rate = torchaudio.load(file_path)
19
-
20
- # Resample the audio to match the sample rate expected by the model
21
- if waveform.shape[0] != model.config.sample_rate:
22
- resampler = torchaudio.transforms.Resample(waveform.shape[1], model.config.sample_rate)
23
- waveform = resampler(waveform)
24
-
25
- # Tokenize the audio using the model's tokenizer
26
- inputs = tokenizer(waveform.numpy(), return_tensors="pt", padding=True)
27
-
28
- # Use the model to classify the audio
29
- with torch.no_grad():
30
- logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
31
-
32
- predicted_class_id = torch.argmax(logits, dim=-1)
33
- predicted_class_label = tokenizer.decode(predicted_class_id[0])
34
-
35
- print(f"The audio file is classified as: {predicted_class_label}")