Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,9 @@ import skops.io as sio
|
|
5 |
import gradio as gr
|
6 |
import warnings
|
7 |
|
|
|
|
|
|
|
8 |
## Voice Data Feature Extraction
|
9 |
|
10 |
### extract the features from the audio files using mfcc
|
@@ -16,42 +19,43 @@ def feature_extracter(fileName):
|
|
16 |
return list(mfccs_scaled_features)
|
17 |
|
18 |
def prediction_age_gender(fileName):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
scaled_observation = scaler.transform(observation)
|
28 |
-
scaled_observation = pd.DataFrame(scaled_observation, columns = col_name)
|
29 |
-
|
30 |
-
### Gender classification model
|
31 |
-
gender_model = joblib.load('/content/KNN_gender_detection.pkl')
|
32 |
-
gender_predict = gender_model.predict_proba(scaled_observation)
|
33 |
-
## considering the labels 1 = male 0 = female
|
34 |
-
gender_dict = {}
|
35 |
-
gender_dict['Female'] = gender_predict[0][0]
|
36 |
-
gender_dict['Male'] = gender_predict[0][1]
|
37 |
-
|
38 |
-
### Age classification model
|
39 |
-
age_model = joblib.load('/content/KNN_age_model.pkl')
|
40 |
-
age_predict = age_model.predict_proba(scaled_observation)
|
41 |
-
age_dict = {}
|
42 |
-
age_dict['Eighties'] = age_predict[0][0]
|
43 |
-
age_dict['Fifties'] = age_predict[0][1]
|
44 |
-
age_dict['Fourties'] = age_predict[0][2]
|
45 |
-
age_dict['Seventies'] = age_predict[0][3]
|
46 |
-
age_dict['Sixties'] = age_predict[0][4]
|
47 |
-
age_dict['Teens'] = age_predict[0][5]
|
48 |
-
age_dict['Thirties'] = age_predict[0][6]
|
49 |
-
age_dict['Twenties'] = age_predict[0][7]
|
50 |
-
age_dict['Other'] = 1 - age_dict['Eighties'] - age_dict['Fifties'] - age_dict['Fourties'] - age_dict['Seventies'] - age_dict['Sixties'] - age_dict['Teens'] - age_dict['Thirties'] - age_dict['Twenties']
|
51 |
-
|
52 |
-
#final = "The person is a: " + gender + " of the age group: " + age
|
53 |
-
return gender_dict, age_dict
|
54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
demo = gr.Interface(
|
56 |
prediction_age_gender,
|
57 |
inputs = [gr.Audio(sources=["microphone","upload"], type = 'filepath')],
|
|
|
5 |
import gradio as gr
|
6 |
import warnings
|
7 |
|
8 |
+
def remove_warnings():
|
9 |
+
warnings.filterwarnings('ignore')
|
10 |
+
|
11 |
## Voice Data Feature Extraction
|
12 |
|
13 |
### extract the features from the audio files using mfcc
|
|
|
19 |
return list(mfccs_scaled_features)
|
20 |
|
21 |
def prediction_age_gender(fileName):
|
22 |
+
|
23 |
+
remove_warnings()
|
24 |
+
col_name = ['Feature_1', 'Feature_2', 'Feature_3', 'Feature_4', 'Feature_5','Feature_6', 'Feature_7', 'Feature_8', 'Feature_9', 'Feature_10','Feature_11', 'Feature_12', 'Feature_13', 'Feature_14', 'Feature_15','Feature_16', 'Feature_17', 'Feature_18', 'Feature_19', 'Feature_20','Feature_21', 'Feature_22', 'Feature_23', 'Feature_24', 'Feature_25','Feature_26', 'Feature_27', 'Feature_28', 'Feature_29', 'Feature_30']
|
25 |
+
|
26 |
+
observation = [feature_extracter(fileName)]
|
27 |
+
observation = pd.DataFrame(observation, columns = col_name)
|
28 |
+
|
29 |
+
## scaling the observation
|
30 |
+
scaler = sio.load('scaler')
|
31 |
+
scaled_observation = scaler.transform(observation)
|
32 |
+
scaled_observation = pd.DataFrame(scaled_observation, columns = col_name)
|
33 |
|
34 |
+
### Gender classification model
|
35 |
+
gender_model = sio.load('KNN_gender_detection')
|
36 |
+
gender_predict = gender_model.predict_proba(scaled_observation.values)
|
37 |
+
## considering the labels 1 = male 0 = female
|
38 |
+
gender_dict = {}
|
39 |
+
gender_dict['Female'] = gender_predict[0][0]
|
40 |
+
gender_dict['Male'] = gender_predict[0][1]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
+
### Age classification model
|
43 |
+
age_model = sio.load('KNN_age_model')
|
44 |
+
age_predict = age_model.predict_proba(scaled_observation.values)
|
45 |
+
age_dict = {}
|
46 |
+
age_dict['Eighties'] = age_predict[0][0]
|
47 |
+
age_dict['Fifties'] = age_predict[0][1]
|
48 |
+
age_dict['Fourties'] = age_predict[0][2]
|
49 |
+
age_dict['Seventies'] = age_predict[0][3]
|
50 |
+
age_dict['Sixties'] = age_predict[0][4]
|
51 |
+
age_dict['Teens'] = age_predict[0][5]
|
52 |
+
age_dict['Thirties'] = age_predict[0][6]
|
53 |
+
age_dict['Twenties'] = age_predict[0][7]
|
54 |
+
age_dict['Other'] = 1 - age_dict['Eighties'] - age_dict['Fifties'] - age_dict['Fourties'] - age_dict['Seventies'] - age_dict['Sixties'] - age_dict['Teens'] - age_dict['Thirties'] - age_dict['Twenties']
|
55 |
+
|
56 |
+
#final = "The person is a: " + gender + " of the age group: " + age
|
57 |
+
return gender_dict, age_dict
|
58 |
+
|
59 |
demo = gr.Interface(
|
60 |
prediction_age_gender,
|
61 |
inputs = [gr.Audio(sources=["microphone","upload"], type = 'filepath')],
|