gopiashokan
commited on
Upload 5 files
Browse files- .streamlit/config.toml +7 -0
- app.py +89 -0
- model.h5 +3 -0
- prediction.json +1 -0
- requirements.txt +7 -0
.streamlit/config.toml
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[theme]
|
2 |
+
base="dark"
|
3 |
+
primaryColor="#FF4B4B"
|
4 |
+
backgroundColor="#0E1117"
|
5 |
+
secondaryBackgroundColor="#262730"
|
6 |
+
textColor="#FAFAFA"
|
7 |
+
font="sans serif"
|
app.py
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import librosa
|
3 |
+
import numpy as np
|
4 |
+
import PIL.Image as Image
|
5 |
+
import tensorflow as tf
|
6 |
+
import streamlit as st
|
7 |
+
from streamlit_extras.add_vertical_space import add_vertical_space
|
8 |
+
from warnings import filterwarnings
|
9 |
+
filterwarnings('ignore')
|
10 |
+
|
11 |
+
|
12 |
+
def streamlit_config():
|
13 |
+
|
14 |
+
# page configuration
|
15 |
+
st.set_page_config(page_title='Classification', layout='centered')
|
16 |
+
|
17 |
+
# page header transparent color
|
18 |
+
page_background_color = """
|
19 |
+
<style>
|
20 |
+
|
21 |
+
[data-testid="stHeader"]
|
22 |
+
{
|
23 |
+
background: rgba(0,0,0,0);
|
24 |
+
}
|
25 |
+
|
26 |
+
</style>
|
27 |
+
"""
|
28 |
+
st.markdown(page_background_color, unsafe_allow_html=True)
|
29 |
+
|
30 |
+
# title and position
|
31 |
+
st.markdown(f'<h1 style="text-align: center;">Bird Sound Classification</h1>',
|
32 |
+
unsafe_allow_html=True)
|
33 |
+
add_vertical_space(4)
|
34 |
+
|
35 |
+
|
36 |
+
# Streamlit Configuration Setup
|
37 |
+
streamlit_config()
|
38 |
+
|
39 |
+
|
40 |
+
def prediction(audio_file):
|
41 |
+
|
42 |
+
# Load the Prediction JSON File to Predict Target_Label
|
43 |
+
with open('prediction.json', mode='r') as f:
|
44 |
+
prediction_dict = json.load(f)
|
45 |
+
|
46 |
+
# Extract the Audio_Signal and Sample_Rate from Input Audio
|
47 |
+
audio, sample_rate =librosa.load(audio_file)
|
48 |
+
|
49 |
+
# Extract the MFCC Features and Aggrigate
|
50 |
+
mfccs_features = librosa.feature.mfcc(y=audio, sr=sample_rate, n_mfcc=40)
|
51 |
+
mfccs_features = np.mean(mfccs_features, axis=1)
|
52 |
+
|
53 |
+
# Reshape MFCC features to match the expected input shape for Conv1D both batch & feature dimension
|
54 |
+
mfccs_features = np.expand_dims(mfccs_features, axis=0)
|
55 |
+
mfccs_features = np.expand_dims(mfccs_features, axis=2)
|
56 |
+
|
57 |
+
# Convert into Tensors
|
58 |
+
mfccs_tensors = tf.convert_to_tensor(mfccs_features, dtype=tf.float32)
|
59 |
+
|
60 |
+
# Load the Model and Prediction
|
61 |
+
model = tf.keras.models.load_model('model.h5')
|
62 |
+
prediction = model.predict(mfccs_tensors)
|
63 |
+
|
64 |
+
# Find the Maximum Probability Value
|
65 |
+
target_label = np.argmax(prediction)
|
66 |
+
|
67 |
+
# Find the Target_Label Name using Prediction_dict
|
68 |
+
predicted_class = prediction_dict[str(target_label)]
|
69 |
+
confidence = round(np.max(prediction)*100, 2)
|
70 |
+
|
71 |
+
add_vertical_space(1)
|
72 |
+
st.markdown(f'<h2 style="text-align: center; color: orange;">{confidence}% Match Found</h2>',
|
73 |
+
unsafe_allow_html=True)
|
74 |
+
|
75 |
+
st.markdown(f'<h2 style="text-align: center; color: green;">{predicted_class}</h2>',
|
76 |
+
unsafe_allow_html=True)
|
77 |
+
|
78 |
+
|
79 |
+
|
80 |
+
|
81 |
+
_, col2, _ = st.columns([0.1,0.9,0.1])
|
82 |
+
with col2:
|
83 |
+
input_audio = st.file_uploader(label='Upload the Audio', type=['mp3', 'wav'])
|
84 |
+
|
85 |
+
if input_audio is not None:
|
86 |
+
|
87 |
+
_, col2, _ = st.columns([0.2,0.8,0.2])
|
88 |
+
with col2:
|
89 |
+
prediction(input_audio)
|
model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3eab543ebee814e9287100d8000e29ebb86a4eb3653df2730c18f21b3952329c
|
3 |
+
size 13807872
|
prediction.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"4": "Barred Tinamou_sound", "34": "Dusky-legged Guan_sound", "66": "Ornate Tinamou_sound", "64": "Okarito Kiwi_sound", "11": "Black-billed Brushturkey_sound", "26": "Cinereous Tinamou_sound", "42": "Greater Rhea_sound", "100": "Tongan Megapode_sound", "17": "Brushland Tinamou_sound", "32": "Darwins Nothura_sound", "9": "Biak Scrubfowl_sound", "28": "Colombian Chachalaca_sound", "1": "Andean Tinamou_sound", "107": "White-bellied Chachalaca_sound", "63": "Northern Cassowary_sound", "46": "Highland Tinamou_sound", "77": "Red-winged Tinamou_sound", "37": "East Brazilian Chachalaca_sound", "10": "Black Tinamou_sound", "88": "Southern Brown Kiwi_sound", "19": "Cauca Guan_sound", "97": "Tawny-breasted Tinamou_sound", "38": "Elegant Crested Tinamou_sound", "109": "White-browed Guan_sound", "83": "Scaled Chachalaca_sound", "53": "Little Tinamou_sound", "70": "Plain Chachalaca_sound", "2": "Australian Brushturkey_sound", "0": "Andean Guan_sound", "33": "Dusky Megapode_sound", "62": "North Island Brown Kiwi_sound", "65": "Orange-footed Scrubfowl_sound", "7": "Bearded Guan_sound", "111": "White-throated Tinamou_sound", "106": "West Mexican Chachalaca_sound", "18": "Buff-browed Chachalaca_sound", "36": "Dwarf Tinamou_sound", "15": "Brazilian Tinamou_sound", "24": "Chilean Tinamou_sound", "31": "Curve-billed Tinamou_sound", "29": "Common Ostrich_sound", "13": "Black-fronted Piping Guan_sound", "113": "Yellow-legged Tinamou_sound", "110": "White-crested Guan_sound", "48": "Huayco Tinamou_sound", "20": "Chaco Chachalaca_sound", "56": "Marail Guan_sound", "90": "Speckled Chachalaca_sound", "30": "Crested Guan_sound", "6": "Baudo Guan_sound", "99": "Thicket Tinamou_sound", "71": "Puna Tinamou_sound", "41": "Great Tinamou_sound", "51": "Little Chachalaca_sound", "79": "Rufous-headed Chachalaca_sound", "49": "Lesser Nothura_sound", "14": "Blue-throated Piping Guan_sound", "81": "Rusty Tinamou_sound", "103": "Vanuatu Megapode_sound", "87": "Somali Ostrich_sound", "73": "Red-billed Brushturkey_sound", "68": "Patagonian Tinamou_sound", "23": "Chestnut-winged Chachalaca_sound", "105": "Wattled Brushturkey_sound", "60": "New Guinea Scrubfowl_sound", "94": "Taczanowskis Tinamou_sound", "35": "Dwarf Cassowary_sound", "54": "Maleo_sound", "72": "Quebracho Crested Tinamou_sound", "45": "Grey-legged Tinamou_sound", "59": "Moluccan Megapode_sound", "43": "Grey Tinamou_sound", "93": "Sula Megapode_sound", "84": "Slaty-breasted Tinamou_sound", "69": "Philippine Megapode_sound", "101": "Trinidad Piping Guan_sound", "89": "Southern Cassowary_sound", "39": "Emu_sound", "44": "Grey-headed Chachalaca_sound", "22": "Chestnut-headed Chachalaca_sound", "85": "Small-billed Tinamou_sound", "104": "Variegated Tinamou_sound", "21": "Chestnut-bellied Guan_sound", "76": "Red-throated Piping Guan_sound", "74": "Red-faced Guan_sound", "5": "Bartletts Tinamou_sound", "40": "Great Spotted Kiwi_sound", "108": "White-bellied Nothura_sound", "95": "Tanimbar Megapode_sound", "61": "Nicobar Megapode_sound", "102": "Undulated Tinamou_sound", "75": "Red-legged Tinamou_sound", "92": "Spotted Nothura_sound", "12": "Black-capped Tinamou_sound", "96": "Tataupa Tinamou_sound", "57": "Melanesian Megapode_sound", "78": "Rufous-bellied Chachalaca_sound", "86": "Solitary Tinamou_sound", "67": "Pale-browed Tinamou_sound", "80": "Rufous-vented Chachalaca_sound", "25": "Choco Tinamou_sound", "58": "Micronesian Megapode_sound", "16": "Brown Tinamou_sound", "3": "Band-tailed Guan_sound", "52": "Little Spotted Kiwi_sound", "47": "Hooded Tinamou_sound", "82": "Rusty-margined Guan_sound", "27": "Collared Brushturkey_sound", "50": "Lesser Rhea_sound", "112": "White-winged Guan_sound", "91": "Spixs Guan_sound", "98": "Tepui Tinamou_sound", "8": "Berlepschs Tinamou_sound", "55": "Malleefowl_sound"}
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow
|
2 |
+
opencv-python
|
3 |
+
pillow
|
4 |
+
numpy
|
5 |
+
librosa
|
6 |
+
streamlit
|
7 |
+
streamlit_extras
|