Noumida commited on
Commit
3dfae4b
·
verified ·
1 Parent(s): f00cc48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -8,10 +8,13 @@ sess = onnxruntime.InferenceSession('weightsgru.onnx')
8
 
9
 
10
  # Define a function to extract MFCC features from an audio file
 
 
 
 
11
 
12
- def extract_mfcc(audio_data, utterance_length):
13
- # Obtain MFCC Features from raw audio data
14
- mfcc_features = librosa.feature.mfcc(y=audio_data, sr=16000, n_mfcc=40, hop_length=512)
15
 
16
  # Adjust the utterance length
17
  if mfcc_features.shape[1] > utterance_length:
@@ -26,9 +29,9 @@ def extract_mfcc(audio_data, utterance_length):
26
 
27
 
28
  # Define a function to classify audio using the ONNX model
29
- def classify_audio(audio_data):
30
  utterance_length = 384
31
- mfcc_features = extract_mfcc(audio_data, utterance_length)
32
  features = np.split(mfcc_features, 6)
33
  inputs = [np.expand_dims(segment, axis=0) for segment in features]
34
  classes = np.zeros((1, 10))
@@ -46,10 +49,8 @@ def classify_audio(audio_data):
46
  highest_bird_label = bird_labels[pred_final1]
47
  second_highest_bird_label = bird_labels[pred_final2]
48
  return highest_bird_label, second_highest_bird_label
49
-
50
- # Create Gradio interface
51
- inputs = gr.Audio(type="filepath", label="Upload Audio")
52
- outputs = [gr.Textbox(label="Highest Bird Label"), gr.Textbox(label="Second Highest Bird Label")]
53
 
54
  # Create Gradio interface
55
  interface = gr.Interface(
@@ -57,8 +58,12 @@ interface = gr.Interface(
57
  inputs=inputs,
58
  outputs=outputs,
59
  title="Bird Classification",
60
- description="Upload an audio file or speak into the microphone to classify it into bird categories"
61
  )
62
 
63
  # Launch the interface
64
- interface.launch()
 
 
 
 
 
8
 
9
 
10
  # Define a function to extract MFCC features from an audio file
11
+ utterance_length = 384
12
+ def extract_mfcc(file_path, utterance_length):
13
+ # Get raw .wav data and sampling rate from librosa's load function
14
+ raw_w, sampling_rate = librosa.load(file_path, sr=None)
15
 
16
+ # Obtain MFCC Features from raw data
17
+ mfcc_features = librosa.feature.mfcc(y=raw_w, sr=sampling_rate, n_mfcc=40, hop_length=512)
 
18
 
19
  # Adjust the utterance length
20
  if mfcc_features.shape[1] > utterance_length:
 
29
 
30
 
31
  # Define a function to classify audio using the ONNX model
32
+ def classify_audio(audio_file):
33
  utterance_length = 384
34
+ mfcc_features = extract_mfcc(audio_file, utterance_length)
35
  features = np.split(mfcc_features, 6)
36
  inputs = [np.expand_dims(segment, axis=0) for segment in features]
37
  classes = np.zeros((1, 10))
 
49
  highest_bird_label = bird_labels[pred_final1]
50
  second_highest_bird_label = bird_labels[pred_final2]
51
  return highest_bird_label, second_highest_bird_label
52
+ inputs = gr.Audio(type="filepath")
53
+ outputs = [gr.Textbox(label="highest_bird_label"), gr.Textbox(label="second_highest_bird_label")]
 
 
54
 
55
  # Create Gradio interface
56
  interface = gr.Interface(
 
58
  inputs=inputs,
59
  outputs=outputs,
60
  title="Bird Classification",
61
+ description="Upload an audio file and classify it into bird categories"
62
  )
63
 
64
  # Launch the interface
65
+ interface.launch()
66
+ # highest_bird, second_highest_bird = classify_audio(audio_file)
67
+
68
+ # print("Highest Bird Label:", highest_bird)
69
+ # print("Second Highest Bird Label:", second_highest_bird)