Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,23 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
def zero_shot_classification(text, labels):
|
5 |
+
classifier = pipeline("zero-shot-classification", model="models/tasksource/ModernBERT-nli")
|
6 |
+
result = classifier(text, labels)
|
7 |
+
return {label: score for label, score in zip(result['labels'], result['scores'])}
|
8 |
+
|
9 |
+
default_text = "all cats are blue"
|
10 |
+
default_labels = ['true', 'false']
|
11 |
+
|
12 |
+
demo = gr.Interface(
|
13 |
+
fn=zero_shot_classification,
|
14 |
+
inputs=[
|
15 |
+
gr.Textbox(label="Input Text", value=default_text),
|
16 |
+
gr.Textbox(label="Possible Labels (comma-separated)", value=','.join(default_labels))
|
17 |
+
],
|
18 |
+
outputs=gr.Label(label="Classification Scores"),
|
19 |
+
title="Zero-Shot Classification",
|
20 |
+
description="Classify a text into labels without prior training for the specific labels."
|
21 |
+
)
|
22 |
+
|
23 |
+
demo.launch()
|