Spaces:
Runtime error
Runtime error
HridayKharpude
commited on
Commit
โข
94c1c1f
1
Parent(s):
d3d38a1
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,62 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
#import flask
|
3 |
+
#from tkinter import filedialog
|
4 |
+
import numpy as np
|
5 |
+
import pandas as pd
|
6 |
+
import csv
|
7 |
+
import librosa
|
8 |
+
import tensorflow as tf
|
9 |
|
10 |
+
#!gdown https://drive.google.com/uc?id=1hKQdsTZ35KQmNV9Zrqg-ksTLSmPapR53
|
11 |
+
model = tf.keras.models.load_model('TTM_model.h5')
|
12 |
|
13 |
+
def config_audio(audio):
|
14 |
+
print('enter2')
|
15 |
+
header = 'ChromaSTFT RMS SpectralCentroid SpectralBandwidth Rolloff ZeroCrossingRate'
|
16 |
+
for i in range(1, 21):
|
17 |
+
header += f' mfcc{i}'
|
18 |
+
header += ' label'
|
19 |
+
header = header.split()
|
20 |
+
print(1)
|
21 |
+
file = open('predict_file.csv', 'w', newline='')
|
22 |
+
with file:
|
23 |
+
writer = csv.writer(file)
|
24 |
+
writer.writerow(header)
|
25 |
+
print(2)
|
26 |
+
#taalfile = audio
|
27 |
+
#print('stored in taalfile')
|
28 |
+
y, sr = librosa.load(audio, mono=True, duration=30)
|
29 |
+
print(3)
|
30 |
+
rms = librosa.feature.rms(y=y)
|
31 |
+
chroma = librosa.feature.chroma_stft(y=y, sr=sr)
|
32 |
+
spec_centroid = librosa.feature.spectral_centroid(y=y, sr=sr)
|
33 |
+
spec_bandwidth = librosa.feature.spectral_bandwidth(y=y, sr=sr)
|
34 |
+
rolloff = librosa.feature.spectral_rolloff(y=y, sr=sr)
|
35 |
+
zcr = librosa.feature.zero_crossing_rate(y)
|
36 |
+
mfcc = librosa.feature.mfcc(y=y, sr=sr)
|
37 |
+
to_append = f' {np.mean(chroma)} {np.mean(rms)} {np.mean(spec_centroid)} {np.mean(spec_bandwidth)} {np.mean(rolloff)} {np.mean(zcr)} '
|
38 |
+
for e in mfcc:
|
39 |
+
to_append += f' {np.mean(e)}'
|
40 |
+
#to_append += f' {t}'
|
41 |
+
file = open('predict_file.csv', 'a', newline='')
|
42 |
+
with file:
|
43 |
+
writer = csv.writer(file)
|
44 |
+
writer.writerow(to_append.split())
|
45 |
+
predict_file = pd.read_csv("predict_file.csv")
|
46 |
+
X_predict = predict_file.drop('label', axis=1)
|
47 |
+
print('exit2')
|
48 |
+
return X_predict
|
49 |
+
|
50 |
+
def predict_audio(audiox, temp):
|
51 |
+
audio=audiox.name
|
52 |
+
print('enter1')
|
53 |
+
X_predict = config_audio(audio)
|
54 |
+
taals = ['addhatrital','bhajani','dadra','deepchandi','ektal','jhaptal','rupak','trital']
|
55 |
+
pred = model.predict(X_predict).flatten()
|
56 |
+
print('exit1')
|
57 |
+
return {taals[i]: float(pred[i]) for i in range(7)}
|
58 |
+
|
59 |
+
audio = gr.inputs.Audio(source="upload", optional=False)
|
60 |
+
label = gr.outputs.Label()
|
61 |
+
|
62 |
+
gr.Interface(predict_audio, ["file","audio"],outputs=label).launch(debug=True)
|