File size: 1,629 Bytes
833cfe7
 
 
 
 
 
ab74fcc
833cfe7
 
 
 
 
 
 
 
 
 
 
2c57d33
 
e975cee
 
833cfe7
db2f8b5
 
 
 
833cfe7
e975cee
833cfe7
 
 
 
 
 
 
 
2c57d33
833cfe7
 
 
 
 
 
 
 
 
 
 
 
 
d305e8c
7539d90
833cfe7
5717cc5
833cfe7
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
## libraries for data preprocessing
import numpy as np 
import pandas as pd 

## libraries for training dl models
import tensorflow as tf
from tensorflow import keras

## libraries for reading audio files 
import librosa as lib 


import gradio as gr 

  
## lets load the model 
model = keras.models.load_model('heartbeatsound_classification.h5')

def loading_sound_file(sound_file, sr=22050, duration=10):
    input_length = sr * duration
    X, sr = lib.load(sound_file, sr=sr, duration=duration) 
    dur = lib.get_duration(y=X, sr=sr)
    
    # # pad audio file same duration
    # if (round(dur) < duration):
    #     print ("fixing audio lenght :", file_name)
    #     y = lib.util.fix_length(X, input_length) 
    # extract normalized mfcc feature from data
    mfccs = np.mean(lib.feature.mfcc(y=X, sr=sr, n_mfcc=25).T,axis=0)

    data = np.array(mfccs).reshape([-1,1])

    return data



def heart_signal_classification(data):
    X = loading_sound_file(data)
    pred = model.predict(X)
    result = pred[0].argmax()
    ## lets create our labels
    labels = {
        0: 'Artifact',
        1: 'Murmur',
        2: 'Normal' 
    }

    label = labels[pred[0].argmax()]
    return label
################### Gradio Web APP ################################ 
title = "Heart Signal Classification App"   
Input = gr.Audio(sources=["upload"], type="filepath")
Output1 = gr.Textbox(label="Type Of Heart Signal")
description = "Type Of Signal: Artifact, Murmur, Normal"
iface = gr.Interface(fn=heart_signal_classification, inputs=Input, outputs=Output1, title=title, description=description)

iface.launch(inline=False)