Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,52 +1,55 @@
|
|
1 |
-
# Necessary imports
|
2 |
-
import
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
1 |
+
# Necessary imports
|
2 |
+
import warnings
|
3 |
+
warnings.filterwarnings("ignore")
|
4 |
+
|
5 |
+
import gradio as gr
|
6 |
+
from src.modernbert.classifier import ZeroShotTextClassification
|
7 |
+
|
8 |
+
|
9 |
+
# Examples to display in the interface
|
10 |
+
examples = [
|
11 |
+
[
|
12 |
+
"I have a problem with my iPhone that needs to be resolved asap!",
|
13 |
+
"urgent, not urgent, phone, tablet, computer",
|
14 |
+
False,
|
15 |
+
],
|
16 |
+
[
|
17 |
+
"Angela Merkel is a politician in Germany and leader of the CDU",
|
18 |
+
"politics, economy, entertainment, environment",
|
19 |
+
False,
|
20 |
+
],
|
21 |
+
[
|
22 |
+
"Hi, I recently bought a device from your company but it is not working as advertised and I would like to get reimbursed!",
|
23 |
+
"refund, legal, faq",
|
24 |
+
True,
|
25 |
+
],
|
26 |
+
]
|
27 |
+
|
28 |
+
# Title and description and article for the interface
|
29 |
+
title = "Zero Shot Text Classification"
|
30 |
+
description = "Classify text using zero-shot classification with ModernBERT-large zeroshot model! Provide a text input and a list of candidate labels separated by commas. Read more at the links below."
|
31 |
+
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2412.13663' target='_blank'>Smarter, Better, Faster, Longer: A Modern Bidirectional Encoder for Fast, Memory Efficient, and Long Context Finetuning and Inference</a> | <a href='https://huggingface.co/MoritzLaurer/ModernBERT-large-zeroshot-v2.0' target='_blank'>Model Page</a></p>"
|
32 |
+
|
33 |
+
|
34 |
+
# Launch the interface
|
35 |
+
demo = gr.Interface(
|
36 |
+
fn=ZeroShotTextClassification,
|
37 |
+
inputs=[
|
38 |
+
gr.Textbox(label="Input", placeholder="Enter text to classify"),
|
39 |
+
gr.Textbox(
|
40 |
+
label="Candidate Labels",
|
41 |
+
placeholder="Enter candidate labels separated by commas",
|
42 |
+
),
|
43 |
+
gr.Checkbox(label="Multi-Label", value=False),
|
44 |
+
],
|
45 |
+
outputs=gr.Label(label="Classification"),
|
46 |
+
title=title,
|
47 |
+
description=description,
|
48 |
+
article=article,
|
49 |
+
examples=examples,
|
50 |
+
cache_examples=True,
|
51 |
+
cache_mode="lazy",
|
52 |
+
theme="Soft",
|
53 |
+
flagging_mode="never",
|
54 |
+
)
|
55 |
+
demo.launch(debug=False)
|