ttt-tkmr commited on
Commit
c9d400e
1 Parent(s): 7a02f6a

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +60 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ !pip install opensmile
2
+ !pip install scikit-learn==1.3.2
3
+ !pip install gradio
4
+
5
+ import opensmile
6
+ import joblib
7
+ import wave
8
+ import datetime
9
+ import os
10
+ import pandas as pd
11
+ from sklearn.preprocessing import StandardScaler
12
+
13
+
14
+ from IPython.display import Javascript, Audio
15
+
16
+ from base64 import b64decode
17
+
18
+ import gradio as gr
19
+
20
+
21
+ model_path = "RF_emobase_20_model_top1_score0.6863_20231207_1537.joblib"
22
+ model = joblib.load(model_path)
23
+
24
+ def extract_features(audio_path):
25
+ smile = opensmile.Smile(
26
+ #feature_set=opensmile.FeatureSet.GeMAPSv01b,
27
+ feature_set=opensmile.FeatureSet.emobase,
28
+ feature_level=opensmile.FeatureLevel.Functionals,
29
+ )
30
+ feature_df = smile.process_files(audio_path)
31
+ output_features = ['F0env_sma_de_amean', 'lspFreq_sma_de[5]_linregc1', 'mfcc_sma[3]_linregc1', 'lspFreq_sma[6]_quartile1', 'lspFreq_sma_de[6]_linregerrQ', 'lspFreq_sma_de[6]_maxPos', 'lspFreq_sma_de[6]_iqr2-3', 'lspFreq_sma_de[7]_minPos', 'lspFreq_sma_de[4]_linregc1', 'lspFreq_sma_de[6]_linregerrA', 'lspFreq_sma_de[6]_linregc2', 'lspFreq_sma[5]_amean', 'lspFreq_sma_de[6]_iqr1-2', 'mfcc_sma[1]_minPos', 'mfcc_sma[4]_linregc1', 'mfcc_sma[9]_iqr2-3', 'lspFreq_sma[5]_kurtosis', 'lspFreq_sma_de[3]_skewness', 'mfcc_sma[3]_minPos', 'mfcc_sma[12]_linregc1']
32
+ df = pd.DataFrame(feature_df.values[0], index=feature_df.columns)
33
+ df = df[df.index.isin(output_features)]
34
+ df = df.T
35
+ scaler = StandardScaler()
36
+ feature = scaler.fit_transform(df)
37
+ print(df.shape)
38
+
39
+ return feature
40
+
41
+ def main(input):
42
+ # openSMILEで特徴量抽出
43
+ feature_vector = extract_features([input])
44
+
45
+ # ロードしたモデルで推論
46
+ prediction = model.predict(feature_vector)
47
+ #print(f"Prediction: {prediction}")
48
+ return prediction
49
+
50
+ gr.Interface(
51
+ title = 'Question Classifier Model',
52
+ fn = main,
53
+ inputs=[
54
+ gr.Audio(sources=["microphone","upload"], type="filepath")
55
+ ],
56
+ outputs=[
57
+ "textbox"
58
+ ],
59
+ live=True
60
+ ).launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ opensmile
2
+ scikit-learn==1.3.2
3
+ gradio