Download app.py from umer70112254/Umer-Text-Classification: direct link, hf CLI and curl.
- Browser
- Download file 774 Bytes
-
https://huggingface.co/spaces/umer70112254/Umer-Text-Classification/resolve/main/app.py
- Command line
-
hf download hf://spaces/umer70112254/Umer-Text-Classification/app.py
-
curl -L -o app.py https://huggingface.co/spaces/umer70112254/Umer-Text-Classification/resolve/main/app.py
774 Bytes
| import gradio as gr | |
| from transformers import pipeline | |
| classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli") | |
| def zeroShotClassification(text_input, candidate_labels): | |
| labels = [label.strip(' ') for label in candidate_labels.split(',')] | |
| output = {} | |
| prediction = classifier(text_input, labels) | |
| for i in range(len(prediction['labels'])): | |
| output[prediction['labels'][i]] = prediction['scores'][i] | |
| return output | |
| examples = [["I made education free for students", "education, cost, needs, future"]] | |
| demo = gr.Interface(fn=zeroShotClassification, inputs=[gr.Textbox(label="Input"), gr.Textbox(label="Candidate Labels")], outputs=gr.Label(label="Classification"), title="Umer Text Classification", examples=examples,) | |
| demo.launch(True) |