Spaces:
Running
Running
- .gitattributes +9 -0
- README.md +14 -14
- app.py +95 -0
- examples/102_1b1_Ar_sc_Meditron.wav +3 -0
- examples/104_1b1_Al_sc_Litt3200.wav +0 -0
- examples/110_1p1_Pr_sc_Meditron.wav +0 -0
- examples/116_1b2_Pl_sc_Meditron.wav +3 -0
- examples/121_1b1_Tc_sc_Meditron.wav +3 -0
- examples/126_1b1_Al_sc_Meditron.wav +3 -0
- examples/127_1b1_Ar_sc_Meditron.wav +3 -0
- examples/135_2b2_Al_mc_LittC2SE.wav +3 -0
- examples/136_1b1_Ar_sc_Meditron.wav +3 -0
- examples/149_1b1_Lr_sc_Meditron.wav +3 -0
- examples/152_1b1_Al_sc_Meditron.wav +3 -0
- models/lung_disease_predictor_cnn_logmel_without_data_augmentation.keras +0 -0
- models/lung_disease_predictor_cnn_mcff_with_data_augmentation.keras +0 -0
- models/lung_disease_predictor_cnn_mcff_without_data_augmentation.keras +0 -0
- models/models_info.txt +11 -0
- temp/lungs_audio.wav +0 -0
.gitattributes
CHANGED
@@ -33,3 +33,12 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
examples/102_1b1_Ar_sc_Meditron.wav filter=lfs diff=lfs merge=lfs -text
|
37 |
+
examples/116_1b2_Pl_sc_Meditron.wav filter=lfs diff=lfs merge=lfs -text
|
38 |
+
examples/121_1b1_Tc_sc_Meditron.wav filter=lfs diff=lfs merge=lfs -text
|
39 |
+
examples/126_1b1_Al_sc_Meditron.wav filter=lfs diff=lfs merge=lfs -text
|
40 |
+
examples/127_1b1_Ar_sc_Meditron.wav filter=lfs diff=lfs merge=lfs -text
|
41 |
+
examples/135_2b2_Al_mc_LittC2SE.wav filter=lfs diff=lfs merge=lfs -text
|
42 |
+
examples/136_1b1_Ar_sc_Meditron.wav filter=lfs diff=lfs merge=lfs -text
|
43 |
+
examples/149_1b1_Lr_sc_Meditron.wav filter=lfs diff=lfs merge=lfs -text
|
44 |
+
examples/152_1b1_Al_sc_Meditron.wav filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
-
---
|
2 |
-
title: LungDiseaseDetector
|
3 |
-
emoji: 🔥
|
4 |
-
colorFrom: green
|
5 |
-
colorTo: pink
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 5.7.1
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
license: mit
|
11 |
-
short_description: 'AI To Detect Lung Diseases from just Lung Sounds '
|
12 |
-
---
|
13 |
-
|
14 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
+
---
|
2 |
+
title: LungDiseaseDetector
|
3 |
+
emoji: 🔥
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: pink
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 5.7.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
short_description: 'AI To Detect Lung Diseases from just Lung Sounds '
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import librosa
|
2 |
+
import tensorflow as tf
|
3 |
+
import soundfile
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
import pandas as pd
|
7 |
+
import os
|
8 |
+
import random
|
9 |
+
import numpy as np
|
10 |
+
# Set the environment variable
|
11 |
+
os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"
|
12 |
+
|
13 |
+
audio_files_path = 'examples'
|
14 |
+
c_names = ['Bronchiectasis', 'COPD', 'Healthy', 'Pneumonia', 'URTI']
|
15 |
+
|
16 |
+
# Loading Audio Files
|
17 |
+
audio_files = []
|
18 |
+
for file in os.listdir(audio_files_path):
|
19 |
+
if file.endswith('.wav'):
|
20 |
+
audio_files.append(file)
|
21 |
+
# convert the list to a df
|
22 |
+
audio_files_df = pd.DataFrame(audio_files, columns=['audio_paths'])
|
23 |
+
# print(audio_files_df.iloc[0]['audio_file'])
|
24 |
+
audio_files_to_show = audio_files_df['audio_paths'].tolist()
|
25 |
+
# create a gradio interface
|
26 |
+
# 0. Load models
|
27 |
+
# 1. Audio File input
|
28 |
+
# 2. clear and Submit button
|
29 |
+
# 3. Upon submit , first preprocess the audio file using log mel and then run the outputs through the AI model
|
30 |
+
# # 4. Output the prediction
|
31 |
+
|
32 |
+
def load_model():
|
33 |
+
# Load the model
|
34 |
+
return tf.keras.models.load_model("models/lung_disease_predictor_cnn_logmel_without_data_augmentation.keras")
|
35 |
+
|
36 |
+
def preprocessing(audio_file, mode):
|
37 |
+
# we want to resample audio to 16 kHz
|
38 |
+
sr_new = 16000 # 16kHz sample rate
|
39 |
+
x, sr = librosa.load(audio_file, sr=sr_new)
|
40 |
+
# padding sound
|
41 |
+
# because duration of sound is dominantly 20 s and all of sample rate is 22050
|
42 |
+
# we want to pad or truncated sound which is below or above 20 s respectively
|
43 |
+
max_len = 5 * sr_new # length of sound array = time x sample rate
|
44 |
+
if x.shape[0] < max_len:
|
45 |
+
# padding with zero
|
46 |
+
pad_width = max_len - x.shape[0]
|
47 |
+
x = np.pad(x, (0, pad_width))
|
48 |
+
elif x.shape[0] > max_len:
|
49 |
+
# truncated
|
50 |
+
x = x[:max_len]
|
51 |
+
|
52 |
+
if mode == 'mfcc':
|
53 |
+
feature = librosa.feature.mfcc(y=x, sr=sr_new)
|
54 |
+
|
55 |
+
elif mode == 'log_mel':
|
56 |
+
feature = librosa.feature.melspectrogram(y=x, sr=sr_new, n_mels=128, fmax=8000)
|
57 |
+
feature = librosa.power_to_db(feature, ref=np.max)
|
58 |
+
|
59 |
+
return feature
|
60 |
+
|
61 |
+
|
62 |
+
def predict_lung_disease(audio_data):
|
63 |
+
# Create a temporary file
|
64 |
+
|
65 |
+
filename = "temp/lungs_audio.wav" # Set your desired filename
|
66 |
+
soundfile.write(filename, audio_data[1],samplerate=audio_data[0]) # Save audio to file
|
67 |
+
|
68 |
+
# Process the temporary audio file
|
69 |
+
processed_audio = preprocessing(filename, 'log_mel').reshape((-1, 128, 157, 1))
|
70 |
+
new_preds = model.predict(processed_audio)
|
71 |
+
new_classpreds = np.argmax(new_preds, axis=1)
|
72 |
+
print(str(c_names[new_classpreds[0]]))
|
73 |
+
return str(c_names[new_classpreds[0]])
|
74 |
+
|
75 |
+
# Gradio Interface
|
76 |
+
model = load_model()
|
77 |
+
|
78 |
+
# have example audio files to test
|
79 |
+
|
80 |
+
|
81 |
+
|
82 |
+
# Interface
|
83 |
+
iface = gr.Interface(
|
84 |
+
fn=predict_lung_disease,
|
85 |
+
inputs=["audio"],
|
86 |
+
outputs="text",
|
87 |
+
title="VitalSenseAI",
|
88 |
+
examples=
|
89 |
+
[
|
90 |
+
[os.path.join(audio_files_path,audio_file)] for audio_file in audio_files_to_show
|
91 |
+
]
|
92 |
+
)
|
93 |
+
|
94 |
+
|
95 |
+
iface.launch()
|
examples/102_1b1_Ar_sc_Meditron.wav
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:46f1864cee63d51cdf8d2278284614d7a9da7a4860bbd0c04d5cdc4283a24753
|
3 |
+
size 1764044
|
examples/104_1b1_Al_sc_Litt3200.wav
ADDED
Binary file (127 kB). View file
|
|
examples/110_1p1_Pr_sc_Meditron.wav
ADDED
Binary file (602 kB). View file
|
|
examples/116_1b2_Pl_sc_Meditron.wav
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:70a1064702bce56b8b93505ee4870b71208103c3b4e33dbac6ddee063558d767
|
3 |
+
size 1764046
|
examples/121_1b1_Tc_sc_Meditron.wav
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d65fd9b4aa09be36d9f731acd468621c39c3d20402930dbc79022f4d137a67b9
|
3 |
+
size 2646044
|
examples/126_1b1_Al_sc_Meditron.wav
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2019badde82bfd418fe5005bb6936d02dd7424178306c9bca648b70d5408db3a
|
3 |
+
size 2646044
|
examples/127_1b1_Ar_sc_Meditron.wav
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:846d0126105bb2a6782fde70ff35608cb86fa285e329cb38f8cc5637f9168f5b
|
3 |
+
size 2642076
|
examples/135_2b2_Al_mc_LittC2SE.wav
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8ba1dd01d916dd0d0ea5ce2326a9c80f22a91e1d88e9c9fefeeb86c02f6901a8
|
3 |
+
size 2646044
|
examples/136_1b1_Ar_sc_Meditron.wav
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d9e5f7cf08a3a53cdaed66d29d0db0f58c89bd73ab171dc1569ac82aa8248e6a
|
3 |
+
size 2646044
|
examples/149_1b1_Lr_sc_Meditron.wav
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a21ea35c63f1602da5b06ff18cca8381dbe3914c552967a85637e48e5d16844e
|
3 |
+
size 1764044
|
examples/152_1b1_Al_sc_Meditron.wav
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:07163c1e1aae3ee3aaf51e8b9a148781f00496c84acfd1065d4ba7407a149f94
|
3 |
+
size 2646044
|
models/lung_disease_predictor_cnn_logmel_without_data_augmentation.keras
ADDED
Binary file (389 kB). View file
|
|
models/lung_disease_predictor_cnn_mcff_with_data_augmentation.keras
ADDED
Binary file (389 kB). View file
|
|
models/lung_disease_predictor_cnn_mcff_without_data_augmentation.keras
ADDED
Binary file (389 kB). View file
|
|
models/models_info.txt
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# lung_disease_predictor_cnn_mcff_without_data_augmentation.keras
|
2 |
+
-> 95% Training Acc. , 85% Testing Acc.
|
3 |
+
|
4 |
+
# lung_disease_predictor_cnn_mcff_with_data_augmentation
|
5 |
+
-> Training Accuracy: 90%
|
6 |
+
-> Testing Accuracy: 55%
|
7 |
+
|
8 |
+
# lung_disease_predictor_cnn_logmel_without_data_augmentation
|
9 |
+
-> Training Accuracy: 93%
|
10 |
+
-> Testing Accuracy: 90%
|
11 |
+
|
temp/lungs_audio.wav
ADDED
Binary file (127 kB). View file
|
|