moro23 commited on
Commit
833cfe7
·
verified ·
1 Parent(s): c40566d

created the app

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## libraries for data preprocessing
2
+ import numpy as np
3
+ import pandas as pd
4
+
5
+ ## libraries for training dl models
6
+ import tensorflow as tf
7
+ from tensorflow import keras
8
+
9
+ ## libraries for reading audio files
10
+ import librosa as lib
11
+
12
+
13
+ import gradio as gr
14
+
15
+
16
+ ## lets load the model
17
+ model = keras.models.load_model('heartbeatsound_classification.h5')
18
+
19
+ def loading_sound_file(sound_file):
20
+ X, sr = librosa.load(sound_file, sr=sr, duration=duration)
21
+ dur = librosa.get_duration(y=X, sr=sr)
22
+
23
+ # pad audio file same duration
24
+ if (round(dur) < duration):
25
+ print ("fixing audio lenght :", file_name)
26
+ y = librosa.util.fix_length(X, input_length)
27
+ # extract normalized mfcc feature from data
28
+ mfccs = np.mean(librosa.feature.mfcc(y=X, sr=sr, n_mfcc=25).T,axis=0)
29
+
30
+ data = np.array(mfccs).reshape([-1,1])
31
+
32
+ return data
33
+
34
+
35
+
36
+ def heart_signal_classification(data):
37
+ x = np.array(image)
38
+ X = np.array([x])
39
+ X = preprocess_input(X)
40
+ pred = model.predict(X)
41
+ result = pred[0].argmax()
42
+ ## lets create our labels
43
+ labels = {
44
+ 0: 'Artifact',
45
+ 1: 'Murmur',
46
+ 2: 'Normal'
47
+ }
48
+
49
+ label = labels[pred[0].argmax()]
50
+ return label
51
+ ################### Gradio Web APP ################################
52
+ title = "Heart Signal Classification App"
53
+ Input = gr.Audio(shape=(299, 299), label="Please Upload An Image")
54
+ Output1 = gr.Textbox(label="Type Of Heart Signal)
55
+ description = "Type Of Signal: Artifact, Murmur, Normal"
56
+ iface = gr.Interface(fn=maize_disease_classifier, inputs=Input, outputs=Output1, title=title, description=description)
57
+
58
+ iface.launch(inline=False)