|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
def zero_shot_classification(text, labels): |
|
classifier = pipeline("zero-shot-classification", model="models/tasksource/ModernBERT-nli") |
|
result = classifier(text, labels) |
|
return {label: score for label, score in zip(result['labels'], result['scores'])} |
|
|
|
default_text = "all cats are blue" |
|
default_labels = ['true', 'false'] |
|
|
|
demo = gr.Interface( |
|
fn=zero_shot_classification, |
|
inputs=[ |
|
gr.Textbox(label="Input Text", value=default_text), |
|
gr.Textbox(label="Possible Labels (comma-separated)", value=','.join(default_labels)) |
|
], |
|
outputs=gr.Label(label="Classification Scores"), |
|
title="Zero-Shot Classification", |
|
description="Classify a text into labels without prior training for the specific labels." |
|
) |
|
|
|
demo.launch() |
|
|