File size: 708 Bytes
89c4aad 50582e8 89c4aad 50582e8 89c4aad 50582e8 89c4aad 50582e8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import gradio as gr
from transformers import pipeline
classifier = pipeline("zero-shot-classification")
def classify(text):
candidate_labels = ["positive", "negative", "neutral"]
output = classifier(text, candidate_labels)
# Process the output to match Gradio's expected input format for gr.Label
labels = output['labels']
scores = output['scores']
# Construct a simple string representation of top classifications
top_classes = ', '.join([f"{labels[i]}: {scores[i]:.2f}" for i in range(len(labels))])
return top_classes
demo = gr.Interface(fn=classify,
inputs=gr.Textbox(label="Enter something"),
outputs=gr.Label())
demo.launch()
|