Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,9 +8,6 @@ model = tf.keras.models.load_model('capuchin_bird_audio.h5')
|
|
8 |
class_names = ['This Is Not A Capuchin bird','It is a capuchin Bird']
|
9 |
# Function to preprocess input for the model
|
10 |
def test_preprocess_1(file_path):
|
11 |
-
_, file_extension = os.path.splitext(file_path)
|
12 |
-
|
13 |
-
if file_extension.lower() == '.wav':
|
14 |
file_contents = tf.io.read_file(file_path)
|
15 |
wav, sample_rate = tf.audio.decode_wav(file_contents, desired_channels=1)
|
16 |
wav = tf.squeeze(wav, axis=-1)
|
@@ -24,24 +21,19 @@ def test_preprocess_1(file_path):
|
|
24 |
spectrogram = tf.expand_dims(spectrogram, axis=2)
|
25 |
spectrogram = tf.expand_dims(spectrogram, axis=0)
|
26 |
return spectrogram
|
27 |
-
else:
|
28 |
-
return False
|
29 |
|
30 |
# Function to make predictions
|
31 |
def predict_audio(wav):
|
32 |
input_data = test_preprocess_1(wav)
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
result = class_names[1]
|
39 |
-
else:
|
40 |
-
result = class_names[0]
|
41 |
-
|
42 |
-
return result
|
43 |
else:
|
44 |
-
|
|
|
|
|
45 |
|
46 |
|
47 |
# Gradio Interface
|
@@ -54,5 +46,4 @@ iface = gr.Interface(
|
|
54 |
)
|
55 |
|
56 |
# Launch the interface on localhost
|
57 |
-
iface.launch(share=True)
|
58 |
-
|
|
|
8 |
class_names = ['This Is Not A Capuchin bird','It is a capuchin Bird']
|
9 |
# Function to preprocess input for the model
|
10 |
def test_preprocess_1(file_path):
|
|
|
|
|
|
|
11 |
file_contents = tf.io.read_file(file_path)
|
12 |
wav, sample_rate = tf.audio.decode_wav(file_contents, desired_channels=1)
|
13 |
wav = tf.squeeze(wav, axis=-1)
|
|
|
21 |
spectrogram = tf.expand_dims(spectrogram, axis=2)
|
22 |
spectrogram = tf.expand_dims(spectrogram, axis=0)
|
23 |
return spectrogram
|
|
|
|
|
24 |
|
25 |
# Function to make predictions
|
26 |
def predict_audio(wav):
|
27 |
input_data = test_preprocess_1(wav)
|
28 |
+
prediction = model.predict(input_data)
|
29 |
+
|
30 |
+
# Threshold logic
|
31 |
+
if prediction > 0.5:
|
32 |
+
result = class_names[1]
|
|
|
|
|
|
|
|
|
|
|
33 |
else:
|
34 |
+
result = class_names[0]
|
35 |
+
|
36 |
+
return result
|
37 |
|
38 |
|
39 |
# Gradio Interface
|
|
|
46 |
)
|
47 |
|
48 |
# Launch the interface on localhost
|
49 |
+
iface.launch(share=True)
|
|