Seidazymov Adil
commited on
Commit
·
4f92cf0
1
Parent(s):
de86ddb
Detect language
Browse files
app.py
CHANGED
|
@@ -1,18 +1,56 @@
|
|
| 1 |
-
|
| 2 |
-
|
|
|
|
| 3 |
|
| 4 |
-
# pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
#
|
| 12 |
-
#
|
| 13 |
-
#
|
| 14 |
-
#
|
| 15 |
-
# )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from gradio_client import Client, file
|
| 4 |
|
|
|
|
| 5 |
|
| 6 |
+
def detect_language(file_path):
|
| 7 |
+
client = Client("adrien-alloreview/speechbrain-lang-id-voxlingua107-ecapa")
|
| 8 |
+
result = client.predict(param_0=file(file_path), api_name="/predict")
|
| 9 |
+
language_result = result["label"].split(": ")[1]
|
| 10 |
+
if language_result.lower() in ["russian", "belarussian", "ukrainian"]:
|
| 11 |
+
selected_language = "russian"
|
| 12 |
+
else:
|
| 13 |
+
selected_language = "kazakh"
|
| 14 |
+
return selected_language
|
| 15 |
|
| 16 |
+
# def detect_emotion(audio):
|
| 17 |
+
# pipe = pipeline(
|
| 18 |
+
# "audio-classification",
|
| 19 |
+
# model="HowMannyMore/wav2vec2-lg-xlsr-ur-speech-emotion-recognition",
|
| 20 |
+
# )
|
| 21 |
+
# res = pipe(audio)
|
| 22 |
+
# emotion_with_max_score = res[0]["label"]
|
| 23 |
+
#
|
| 24 |
+
# return emotion_with_max_score
|
| 25 |
+
#
|
| 26 |
+
#
|
| 27 |
+
# def detect_toxic_local(text_whisper):
|
| 28 |
+
# model_name_rus = "IlyaGusev/rubertconv_toxic_clf"
|
| 29 |
+
# pipe = pipeline(
|
| 30 |
+
# "text-classification",
|
| 31 |
+
# model=model_name_rus,
|
| 32 |
+
# tokenizer=model_name_rus,
|
| 33 |
+
# framework="pt",
|
| 34 |
+
# max_length=512,
|
| 35 |
+
# truncation=True,
|
| 36 |
+
# device=0,
|
| 37 |
+
# )
|
| 38 |
+
# res = pipe([text_whisper])[0]["label"]
|
| 39 |
+
# if res == "toxic":
|
| 40 |
+
# return True
|
| 41 |
+
# if res == "neutral":
|
| 42 |
+
# return False
|
| 43 |
+
# else:
|
| 44 |
+
# return None
|
| 45 |
|
| 46 |
+
|
| 47 |
+
gradio_app = gr.Interface(
|
| 48 |
+
fn=detect_language,
|
| 49 |
+
inputs=gr.Audio(source="upload", type="filepath"),
|
| 50 |
+
outputs="text",
|
| 51 |
+
title="File Upload Transcription",
|
| 52 |
+
description="Upload an audio file to determine language."
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
if __name__ == "__main__":
|
| 56 |
+
gradio_app.launch()
|