| from transformers import pipeline |
| import gradio as gr |
| classifier = pipeline("zero-shot-classification", model="facebook/bart-large-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.inputs.Textbox( |
| lines=3, |
| label="Text to classify", |
| default="Furry fandom" |
| ), |
| gr.inputs.Textbox( |
| lines=1, |
| label="Candidate labels separated with commas (no spaces)", |
| default="good,bad", |
| placeholder="good,bad", |
| ), |
| gr.inputs.Textbox(lines=1, label="Template", default="Asexuality is {}.", placeholder="Asexuality is {}.") |
| ], |
| outputs=[ |
| gr.outputs.Textbox(label="Predicted label") |
| ], |
| enable_queue=True, |
| allow_screenshot=False, |
| allow_flagging=False, |
| |
| |
| |
| ).launch(debug=True) |