Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import librosa
|
3 |
+
import numpy as np
|
4 |
+
import torch
|
5 |
+
from transformers import pipeline
|
6 |
+
|
7 |
+
|
8 |
+
language_classes = {
|
9 |
+
0: "Arabic",
|
10 |
+
1: "Basque",
|
11 |
+
2: "Breton",
|
12 |
+
3: "Catalan",
|
13 |
+
4: "Chinese_China",
|
14 |
+
5: "Chinese_Hongkong",
|
15 |
+
6: "Chinese_Taiwan",
|
16 |
+
7: "Chuvash",
|
17 |
+
8: "Czech",
|
18 |
+
9: "Dhivehi",
|
19 |
+
10: "Dutch",
|
20 |
+
11: "English",
|
21 |
+
12: "Esperanto",
|
22 |
+
13: "Estonian",
|
23 |
+
14: "French",
|
24 |
+
15: "Frisian",
|
25 |
+
16: "Georgian",
|
26 |
+
17: "German",
|
27 |
+
18: "Greek",
|
28 |
+
19: "Hakha_Chin",
|
29 |
+
20: "Indonesian",
|
30 |
+
21: "Interlingua",
|
31 |
+
22: "Italian",
|
32 |
+
23: "Japanese",
|
33 |
+
24: "Kabyle",
|
34 |
+
25: "Kinyarwanda",
|
35 |
+
26: "Kyrgyz",
|
36 |
+
27: "Latvian",
|
37 |
+
28: "Maltese",
|
38 |
+
29: "Mongolian",
|
39 |
+
30: "Persian",
|
40 |
+
31: "Polish",
|
41 |
+
32: "Portuguese",
|
42 |
+
33: "Romanian",
|
43 |
+
34: "Romansh_Sursilvan",
|
44 |
+
35: "Russian",
|
45 |
+
36: "Sakha",
|
46 |
+
37: "Slovenian",
|
47 |
+
38: "Spanish",
|
48 |
+
39: "Swedish",
|
49 |
+
40: "Tamil",
|
50 |
+
41: "Tatar",
|
51 |
+
42: "Turkish",
|
52 |
+
43: "Ukranian",
|
53 |
+
44: "Welsh"
|
54 |
+
}
|
55 |
+
|
56 |
+
|
57 |
+
|
58 |
+
|
59 |
+
username = "jpbello" ## Complete your username
|
60 |
+
model_id = "jpbello/Hubert_emotion-finetuned-common_language"
|
61 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
62 |
+
pipe = pipeline("audio-classification", model=model_id, device=device)
|
63 |
+
|
64 |
+
# def predict_trunc(filepath):
|
65 |
+
# preprocessed = pipe.preprocess(filepath)
|
66 |
+
# truncated = pipe.feature_extractor.pad(preprocessed,truncation=True, max_length = 16_000*30)
|
67 |
+
# model_outputs = pipe.forward(truncated)
|
68 |
+
# outputs = pipe.postprocess(model_outputs)
|
69 |
+
|
70 |
+
# return outputs
|
71 |
+
|
72 |
+
|
73 |
+
def classify_audio(filepath):
|
74 |
+
|
75 |
+
|
76 |
+
preds = pipe(filepath)
|
77 |
+
# preds = predict_trunc(filepath)
|
78 |
+
outputs = {}
|
79 |
+
for p in preds:
|
80 |
+
outputs[p["label"]] = p["score"]
|
81 |
+
return outputs
|
82 |
+
|
83 |
+
|
84 |
+
title = "Language Classification Model"
|
85 |
+
description = (
|
86 |
+
"This model has been fine-tuned on a dataset containing various languages\n"
|
87 |
+
"including Arabic, Basque, Catalan, Chinese, English, French, German, Japanese, Russian, and more.\n"
|
88 |
+
"It is designed for audio classification, allowing it to predict the language spoken in a given audio clip.\n"
|
89 |
+
"Try it out by uploading an audio sample and see how accurately it can identify the language being spoken!\n"
|
90 |
+
"For more info, check out [GITHUB](https://github.com/AEscF)"
|
91 |
+
)
|
92 |
+
filenames = ['EN_0049.wav', "FR_0098.wav", "JP_0222.wav",]
|
93 |
+
filenames = [[f"./{f}"] for f in filenames]
|
94 |
+
demo = gr.Interface(
|
95 |
+
fn=classify_audio,
|
96 |
+
inputs=gr.Audio(type="filepath"),
|
97 |
+
outputs=[gr.Label(label="Predictions")],
|
98 |
+
title=title,
|
99 |
+
description=description,
|
100 |
+
examples=filenames,
|
101 |
+
)
|
102 |
+
demo.launch()
|