Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,14 +5,25 @@ from langdetect import detect, DetectorFactory, detect_langs
|
|
5 |
import fasttext
|
6 |
from transformers import pipeline
|
7 |
|
8 |
-
models = {'en': 'Narsil/deberta-large-mnli-zero-cls'
|
|
|
|
|
|
|
9 |
|
10 |
|
11 |
-
hypothesis_templates = {'en': 'This example is {}.'
|
|
|
|
|
12 |
|
13 |
|
14 |
classifiers = {'en': pipeline("zero-shot-classification", hypothesis_template=hypothesis_templates['en'],
|
15 |
-
model=models['en'])
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
fasttext_model = fasttext.load_model(hf_hub_download("julien-c/fasttext-language-id", "lid.176.bin"))
|
18 |
|
@@ -23,8 +34,17 @@ def prep_examples():
|
|
23 |
example_labels1 = "business,health related,politics,climate change"
|
24 |
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
examples = [
|
27 |
-
[example_text1, example_labels1]
|
|
|
|
|
28 |
]
|
29 |
|
30 |
return examples
|
@@ -86,8 +106,8 @@ def sequence_to_classify(sequence, labels):
|
|
86 |
return clean_output
|
87 |
|
88 |
iface = gr.Interface(
|
89 |
-
title="En Multi-label Zero-shot Classification",
|
90 |
-
description="Supported languages are: English",
|
91 |
fn=sequence_to_classify,
|
92 |
inputs=[gr.inputs.Textbox(lines=10,
|
93 |
label="Please enter the text you would like to classify...",
|
|
|
5 |
import fasttext
|
6 |
from transformers import pipeline
|
7 |
|
8 |
+
models = {'en': 'Narsil/deberta-large-mnli-zero-cls', # English
|
9 |
+
'ru': 'DeepPavlov/xlm-roberta-large-en-ru-mnli', # Russian
|
10 |
+
'uz': 'coppercitylabs/uzbek-news-category-classifier'
|
11 |
+
} #Uzbek
|
12 |
|
13 |
|
14 |
+
hypothesis_templates = {'en': 'This example is {}.', # English
|
15 |
+
'ru': 'Этот пример {}.', # Russian
|
16 |
+
'uz': 'Бу мисол {}.'} # Uzbek
|
17 |
|
18 |
|
19 |
classifiers = {'en': pipeline("zero-shot-classification", hypothesis_template=hypothesis_templates['en'],
|
20 |
+
model=models['en']),
|
21 |
+
|
22 |
+
'ru': pipeline("zero-shot-classification", hypothesis_template=hypothesis_templates['ru'],
|
23 |
+
model=models['ru']),
|
24 |
+
'uz': pipeline("zero-shot-classification", hypothesis_template=hypothesis_templates['uz'],
|
25 |
+
model=models['uz'])
|
26 |
+
}
|
27 |
|
28 |
fasttext_model = fasttext.load_model(hf_hub_download("julien-c/fasttext-language-id", "lid.176.bin"))
|
29 |
|
|
|
34 |
example_labels1 = "business,health related,politics,climate change"
|
35 |
|
36 |
|
37 |
+
example_text2 = "Том был невероятно рад встрече со своим другом, ученным из Китая, который занимается искусственным интелектом."
|
38 |
+
example_labels2 = "наука,политика"
|
39 |
+
|
40 |
+
example_text3 = "Алишер Навоий ўзбек классик шоири, буюк ижодкор ва ватанпарвар инсон бўлган."
|
41 |
+
example_labels3 = "шеърият,спорт, санъат"
|
42 |
+
|
43 |
+
|
44 |
examples = [
|
45 |
+
[example_text1, example_labels1],
|
46 |
+
[example_text2, example_labels2],
|
47 |
+
[example_text3, example_labels3]
|
48 |
]
|
49 |
|
50 |
return examples
|
|
|
106 |
return clean_output
|
107 |
|
108 |
iface = gr.Interface(
|
109 |
+
title="En-Ru-Uz Multi-label Zero-shot Classification",
|
110 |
+
description="Supported languages are: English, Russian and Uzbek",
|
111 |
fn=sequence_to_classify,
|
112 |
inputs=[gr.inputs.Textbox(lines=10,
|
113 |
label="Please enter the text you would like to classify...",
|