File size: 1,093 Bytes
e3c3046
 
 
 
 
ee4ad00
 
 
 
 
 
 
 
 
20183ab
903e92f
c4e0334
6cbf59a
c4e0334
20183ab
c4e0334
 
6cbf59a
c4e0334
 
6cbf59a
ee4ad00
 
20183ab
ee4ad00
20183ab
1
2
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
from transformers import pipeline
import gradio as gr

classifier = pipeline("zero-shot-classification", model="DeepPavlov/xlm-roberta-large-en-ru-mnli")

def wrap_classifier(text, labels, template):
    labels = labels.split(",")
    outputs = classifier(text, labels, hypothesis_template=template)
    return outputs["labels"][0]

gr.Interface(
    fn=wrap_classifier,
    title="Zero-shot Classification",
    inputs=[
        gr.Textbox(
            lines=3,
            label="Text to classify",
            value="Sneaky Credit Card Tactics Keep an eye on your credit card issuers -- they may be about to raise your rates."
            ),
        gr.Textbox(
            lines=1,
            label="Candidate labels separated with commas (no spaces)",
            value="World,Sports,Business,Sci/Tech",
            placeholder="World,Sports,Business,Sci/Tech",
            ),
        gr.Textbox(lines=1, label="Template", value="The topic of this text is {}.", placeholder="The topic of this text is {}.")
    ],
    outputs=[
        gr.Label(label="Predicted label")
    ],
).launch()