File size: 772 Bytes
383927e
3b3ed68
383927e
93019e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
383927e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import gradio as gr
from transformers import pipeline

classifier = pipeline(task="zero-shot-classification", model = "MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli")    

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()