Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from speechbrain.pretrained.interfaces import foreign_class
|
2 |
+
import gradio as gr
|
3 |
+
import nltk
|
4 |
+
import librosa
|
5 |
+
|
6 |
+
import warnings
|
7 |
+
warnings.filterwarnings("ignore")
|
8 |
+
|
9 |
+
# Loading the speechbrain emotion detection model
|
10 |
+
learner = foreign_class(source="mtauro/wavlm_vrs_ck_iva_k492",
|
11 |
+
pymodule_file="custom_interface.py",
|
12 |
+
classname="CustomEncoderWav2vec2Classifier")
|
13 |
+
|
14 |
+
|
15 |
+
# Building prediction function for gradio
|
16 |
+
emotion_dict = {
|
17 |
+
'HC': 'No AD detected',
|
18 |
+
'AD': 'Signs of AD detected',
|
19 |
+
|
20 |
+
}
|
21 |
+
|
22 |
+
#def predict_emotion(audio):
|
23 |
+
# out_prob, score, index, text_lab = learner.classify_file(audio.name)
|
24 |
+
# return emotion_dict[text_lab[0]]
|
25 |
+
|
26 |
+
def detect_ad(audio):
|
27 |
+
out_prob, score, index, text_lab = learner.classify_file(audio.name)
|
28 |
+
return emotion_dict[text_lab[0]]
|
29 |
+
|
30 |
+
# Loading gradio interface
|
31 |
+
#inputs = gr.inputs.Audio(label="Input Audio", type="file")
|
32 |
+
#input_1 = gr.inputs.Audio(label="Input Audio", type="file")
|
33 |
+
##inputs = gr.inputs.Audio(source="microphone", type="filepath", optional=True, label="Please record your voice")
|
34 |
+
#outputs = "text"
|
35 |
+
#title = "AD Detection"
|
36 |
+
#description = "Testing"
|
37 |
+
#gr.Interface(detect_ad, inputs, outputs, title=title, description=description).launch()
|
38 |
+
#gr.Interface(detect_ad, input_1, outputs, title=title, description=description).launch()
|
39 |
+
|
40 |
+
gr.Interface(detect_ad,
|
41 |
+
inputs = gr.inputs.Audio(source="microphone", type="file", optional=True, label="Please speak for 13-30 seconds"),
|
42 |
+
outputs = gr.outputs.Textbox(label="Output Text"),
|
43 |
+
title="AD Detection",
|
44 |
+
description = "Testing",
|
45 |
+
#examples = [["Test_File1.wav"], ["Test_File2.wav"], ["Test_File3.wav"]],
|
46 |
+
theme="grass").launch()
|