Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import BartForSequenceClassification, BartTokenizer
|
2 |
+
import gradio as grad
|
3 |
+
|
4 |
+
model_name = "facebook/bart-large-mnli"
|
5 |
+
bart_tokenizer = BartTokenizer.from_pretrained(model_name)
|
6 |
+
model = BartForSequenceClassification.from_pretrained(model_name)
|
7 |
+
|
8 |
+
def classify(text, label):
|
9 |
+
token_ids = bart_tokenizer.encode(text, label, return_tensors="pt")
|
10 |
+
token_logits = model(token_ids)[0]
|
11 |
+
entail_contra_token_logits = token_logits[:, [0, 2]]
|
12 |
+
probabilities = entail_contra_token_logits.softmax(dim=1)
|
13 |
+
response = probabilities[:, 1].item() * 100
|
14 |
+
return response
|
15 |
+
|
16 |
+
in_text = grad.Textbox(lines=1, label="English", placeholder="Text to be classified")
|
17 |
+
in_labels = grad.Textbox(lines=1, label="Label", placeholder="Input a label")
|
18 |
+
out = grad.Textbox(lines=1, label="Probability of label being true is ")
|
19 |
+
|
20 |
+
grad.Interface(classify, inputs=[in_text, in_labels], outputs=[out]).launch()
|