chidojawbreaker commited on
Commit
e1f22dd
1 Parent(s): d4d5ba9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -1,13 +1,26 @@
1
  import gradio as gr
2
  import numpy as np
 
3
  import joblib
4
  import librosa
5
  from sklearn.preprocessing import StandardScaler
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  model = joblib.load('UTI.pkl')
8
 
9
  def predictor(audio_filename):
10
- y,sr = librosa.load(audio_filename,mono=True,duration=5)
11
 
12
  chroma_stft = np.mean(librosa.feature.chroma_stft(y=y, sr=sr))
13
  rmse = np.mean(librosa.feature.rms(y=y))
@@ -41,17 +54,16 @@ def predictor(audio_filename):
41
  mfcc20 = v[19]
42
 
43
  features = np.array([[chroma_stft,rmse,spec_cent,spec_bw,rolloff,zcr,mfcc1,mfcc2,mfcc3,mfcc4,mfcc5,mfcc6,mfcc7,mfcc8,mfcc9,mfcc10,mfcc11,mfcc12,mfcc13,mfcc14,mfcc15,mfcc16,mfcc17,mfcc18,mfcc19,mfcc20]])
44
-
45
- prediction = model.predict(StandardScaler().fit_transform(features))
46
 
47
- if prediction[0] == 0:
 
 
48
  result = 'Normal'
49
  else:
50
  result = 'Infected'
51
  return result
52
 
53
-
54
  app = gr.Interface(fn=predictor,
55
  inputs=gr.Audio(source="upload",type="filepath",label="Please Upload Audio file here:"),
56
- outputs=gr.Textbox(label="Result"),title="SMART UTI DETECTOR",description="UTI Prediction Model",examples=[["normal 1_rn.wav"]])
57
- app.launch()
 
1
  import gradio as gr
2
  import numpy as np
3
+ import pandas as pd
4
  import joblib
5
  import librosa
6
  from sklearn.preprocessing import StandardScaler
7
+ from sklearn import preprocessing
8
+ from sklearn.model_selection import train_test_split
9
+
10
+ dataset = pd.read_csv('UTIv2.csv')
11
+ dataset = dataset.drop('filename',axis=1)
12
+ x = dataset.iloc[:, :-1].values
13
+ y = dataset.iloc[:, -1].values
14
+ encoder = preprocessing.LabelEncoder()
15
+ y = encoder.fit_transform(y)
16
+ x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.2, random_state = 0)
17
+ sc = StandardScaler()
18
+ sc = sc.fit(x_train)
19
 
20
  model = joblib.load('UTI.pkl')
21
 
22
  def predictor(audio_filename):
23
+ y, sr = librosa.load(audio_filename, mono=True, duration=5)
24
 
25
  chroma_stft = np.mean(librosa.feature.chroma_stft(y=y, sr=sr))
26
  rmse = np.mean(librosa.feature.rms(y=y))
 
54
  mfcc20 = v[19]
55
 
56
  features = np.array([[chroma_stft,rmse,spec_cent,spec_bw,rolloff,zcr,mfcc1,mfcc2,mfcc3,mfcc4,mfcc5,mfcc6,mfcc7,mfcc8,mfcc9,mfcc10,mfcc11,mfcc12,mfcc13,mfcc14,mfcc15,mfcc16,mfcc17,mfcc18,mfcc19,mfcc20]])
 
 
57
 
58
+ prediction = model.predict(sc.transform(features))
59
+
60
+ if prediction[0] == 1:
61
  result = 'Normal'
62
  else:
63
  result = 'Infected'
64
  return result
65
 
 
66
  app = gr.Interface(fn=predictor,
67
  inputs=gr.Audio(source="upload",type="filepath",label="Please Upload Audio file here:"),
68
+ outputs=gr.Textbox(label="Result"),title="SMART LUTS DETECTOR",description="UTI Prediction Model",examples=[["normal 1_rn.wav"]])
69
+ app.launch()