File size: 781 Bytes
e3c3046 ee4ad00 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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.inputs.Textbox(lines=5, label="Text to classify"),
gr.inputs.Textbox(lines=1, label="Candidate labels separated with commas"),
gr.inputs.Textbox(lines=1, label="Template", default="This sentence is about {}.", placeholder="This sentence is about {}.")
],
outputs=[
gr.outputs.Textbox(label="Label")
],
).launch() |