Spaces:
Build error
Build error
Commit
·
4e3dfa8
1
Parent(s):
8e6236a
Upload 2 files
Browse files- app.py +17 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
| 5 |
+
|
| 6 |
+
def zeroShotClassification(text_input, candidate_labels):
|
| 7 |
+
labels = [label.strip(' ') for label in candidate_labels.split(',')]
|
| 8 |
+
output = {}
|
| 9 |
+
prediction = classifier(text_input, labels)
|
| 10 |
+
for i in range(len(prediction['labels'])):
|
| 11 |
+
output[prediction['labels'][i]] = prediction['scores'][i]
|
| 12 |
+
return output
|
| 13 |
+
|
| 14 |
+
examples = [["One day I will see the world", "travel, live, die, future"]]
|
| 15 |
+
|
| 16 |
+
demo = gr.Interface(fn=zeroShotClassification, inputs=[gr.Textbox(label="Input"), gr.Textbox(label="Candidate Labels")], outputs=gr.Label(label="Classification"), examples=examples)
|
| 17 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
torch
|
| 3 |
+
timm
|
| 4 |
+
sentencepiece
|
| 5 |
+
transformers
|