Spaces:
Runtime error
Runtime error
kaushikbar
commited on
Commit
·
97a23a7
1
Parent(s):
71775e2
Multiple language support added.
Browse files
app.py
CHANGED
|
@@ -40,11 +40,11 @@ def detect_lang(sequence, labels):
|
|
| 40 |
lbl_lang))
|
| 41 |
|
| 42 |
if seq_lang in models:
|
| 43 |
-
print("Sequence Language detected
|
| 44 |
"Date:{}, Sequence:{}, Sequence Language:{}".format(
|
| 45 |
str(datetime.datetime.now()),
|
| 46 |
sequence,
|
| 47 |
-
|
| 48 |
else:
|
| 49 |
print("Language not supported. Defaulting to English!",
|
| 50 |
"Date:{}, Sequence:{}, Sequence Language:{}".format(
|
|
@@ -61,9 +61,9 @@ def sequence_to_classify(sequence, labels):
|
|
| 61 |
|
| 62 |
lang = detect_lang(sequence, labels)
|
| 63 |
classifier = pipeline("zero-shot-classification",
|
| 64 |
-
|
| 65 |
model=models[lang])
|
| 66 |
-
response = classifier(sequence, label_clean,
|
| 67 |
|
| 68 |
predicted_labels = response['labels']
|
| 69 |
predicted_scores = response['scores']
|
|
@@ -75,10 +75,17 @@ def sequence_to_classify(sequence, labels):
|
|
| 75 |
|
| 76 |
return clean_output
|
| 77 |
|
| 78 |
-
example_text1="
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
iface = gr.Interface(
|
| 84 |
title="Multilingual Multi-label Zero-shot Classification",
|
|
@@ -89,7 +96,7 @@ iface = gr.Interface(
|
|
| 89 |
placeholder="Text here..."),
|
| 90 |
gr.inputs.Textbox(lines=5,
|
| 91 |
label="Possible candidate labels (separated by comma)...",
|
| 92 |
-
placeholder="
|
| 93 |
outputs=gr.outputs.Label(num_top_classes=5),
|
| 94 |
capture_session=True,
|
| 95 |
#interpretation="default",
|
|
|
|
| 40 |
lbl_lang))
|
| 41 |
|
| 42 |
if seq_lang in models:
|
| 43 |
+
print("Sequence Language detected.",
|
| 44 |
"Date:{}, Sequence:{}, Sequence Language:{}".format(
|
| 45 |
str(datetime.datetime.now()),
|
| 46 |
sequence,
|
| 47 |
+
seq_lang))
|
| 48 |
else:
|
| 49 |
print("Language not supported. Defaulting to English!",
|
| 50 |
"Date:{}, Sequence:{}, Sequence Language:{}".format(
|
|
|
|
| 61 |
|
| 62 |
lang = detect_lang(sequence, labels)
|
| 63 |
classifier = pipeline("zero-shot-classification",
|
| 64 |
+
hypothesis_template=hypothesis_templates[lang],
|
| 65 |
model=models[lang])
|
| 66 |
+
response = classifier(sequence, label_clean, multi_label=True)
|
| 67 |
|
| 68 |
predicted_labels = response['labels']
|
| 69 |
predicted_scores = response['scores']
|
|
|
|
| 75 |
|
| 76 |
return clean_output
|
| 77 |
|
| 78 |
+
example_text1 = "Climate change refers to long-term shifts in temperatures and weather patterns. \
|
| 79 |
+
These shifts may be natural, but since the 1800s, human activities have been the main driver of climate change, \
|
| 80 |
+
primarily due to the burning of fossil fuels (like coal, oil, and gas), which produces heat-trapping gases."
|
| 81 |
+
example_labels1="business,nature,religion"
|
| 82 |
+
example_text2="Ja, vi elsker dette landet,\
|
| 83 |
+
som det stiger frem,\
|
| 84 |
+
furet, værbitt over vannet,\
|
| 85 |
+
med de tusen hjem.\
|
| 86 |
+
Og som fedres kamp har hevet\
|
| 87 |
+
det av nød til seir"\
|
| 88 |
+
example_labels2="helse,sport,religion,mat,patriotisme og nasjonalisme"
|
| 89 |
|
| 90 |
iface = gr.Interface(
|
| 91 |
title="Multilingual Multi-label Zero-shot Classification",
|
|
|
|
| 96 |
placeholder="Text here..."),
|
| 97 |
gr.inputs.Textbox(lines=5,
|
| 98 |
label="Possible candidate labels (separated by comma)...",
|
| 99 |
+
placeholder="Labels here separated by comma...")],
|
| 100 |
outputs=gr.outputs.Label(num_top_classes=5),
|
| 101 |
capture_session=True,
|
| 102 |
#interpretation="default",
|