Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,22 @@ import fasttext
|
|
5 |
|
6 |
model = fasttext.load_model(hf_hub_download("NbAiLab/nb-nordic-lid", "model.bin"))
|
7 |
model_labels = set(label[-3:] for label in model.get_labels())
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
def detect_lang(
|
11 |
text: str,
|
@@ -54,7 +69,12 @@ def detect_lang(
|
|
54 |
|
55 |
|
56 |
def identify(text):
|
57 |
-
return
|
58 |
|
59 |
-
iface = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
60 |
iface.launch()
|
|
|
5 |
|
6 |
model = fasttext.load_model(hf_hub_download("NbAiLab/nb-nordic-lid", "model.bin"))
|
7 |
model_labels = set(label[-3:] for label in model.get_labels())
|
8 |
+
language_dict = {
|
9 |
+
'dan': 'Danish',
|
10 |
+
'eng': 'English',
|
11 |
+
'fao': 'Faroese',
|
12 |
+
'fin': 'Finnish',
|
13 |
+
'isl': 'Icelandic',
|
14 |
+
'nno': 'Norwegian Nynorsk',
|
15 |
+
'nob': 'Norwegian Bokmål',
|
16 |
+
'sma': 'Southern Sami',
|
17 |
+
'sme': 'Northern Sami',
|
18 |
+
'smj': 'Lule Sami',
|
19 |
+
'smn': 'Inari Sami',
|
20 |
+
'sms': 'Skolt Sami',
|
21 |
+
'swe': 'Swedish',
|
22 |
+
'und': 'Undetermined',
|
23 |
+
}
|
24 |
|
25 |
def detect_lang(
|
26 |
text: str,
|
|
|
69 |
|
70 |
|
71 |
def identify(text):
|
72 |
+
return {language_dict[lang]: proba for lang, proba in detect_lang(text.replace("\n", " "), return_proba=True)}
|
73 |
|
74 |
+
iface = gr.Interface(
|
75 |
+
title="NB Nordic Language Identification",
|
76 |
+
description="""This demo uses the [NB-Nordic-LID](https://huggingface.co/NbAiLab/nb-nordic-lid) model to classify a given text into one of the 12 Nordic languages supported.""",
|
77 |
+
fn=identify,
|
78 |
+
inputs="text",
|
79 |
+
outputs="label")
|
80 |
iface.launch()
|