|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
languages = [ |
|
"Arabic", "Basque", "Breton", "Catalan", "Chinese_China", "Chinese_Hongkong", |
|
"Chinese_Taiwan", "Chuvash", "Czech", "Dhivehi", "Dutch", "English", |
|
"Esperanto", "Estonian", "French", "Frisian", "Georgian", "German", "Greek", |
|
"Hakha_Chin", "Indonesian", "Interlingua", "Italian", "Japanese", "Kabyle", |
|
"Kinyarwanda", "Kyrgyz", "Latvian", "Maltese", "Mongolian", "Persian", "Polish", |
|
"Portuguese", "Romanian", "Romansh_Sursilvan", "Russian", "Sakha", "Slovenian", |
|
"Spanish", "Swedish", "Tamil", "Tatar", "Turkish", "Ukranian", "Welsh" |
|
] |
|
|
|
pipe = pipeline("text-classification", model="Mike0307/multilingual-e5-language-detection") |
|
|
|
def func(inp): |
|
result = '' |
|
out = pipe(inp) |
|
for lang in out: |
|
result += languages[int(lang['label'][6:])] + ' ' + str(lang['score']) + '\n' |
|
return result |
|
|
|
demo = gr.Interface(fn=func, inputs="text", outputs="text") |
|
demo.launch() |