Download sample.py from jeonseonjin/demo1: direct link, hf CLI and curl.
- Browser
- Download file 741 Bytes
-
https://huggingface.co/jeonseonjin/demo1/resolve/main/sample.py
- Command line
-
hf download hf://jeonseonjin/demo1/sample.py
-
curl -L -o sample.py https://huggingface.co/jeonseonjin/demo1/resolve/main/sample.py
741 Bytes
| from transformers import pipeline | |
| def classify_text(email): | |
| """ | |
| Use Facebook BART model to classify an email into "spam" or "not spam" | |
| Args: | |
| email (str): The email to classify | |
| Returns: | |
| str: The classification of the email ("spam" or "not spam") | |
| """ | |
| # Load the BART model for text classification | |
| classifier = pipeline(task="zero-shot-classification", model="facebook/bart-large-mnli") | |
| # Classify the email | |
| labels = ['spam','not spam'] | |
| template = 'This email is {}.' | |
| result = classifier(email, labels) | |
| # Get the label with the highest score | |
| label = result['labels'][0] | |
| return label | |
| classify_text('hi I am marketer, we have good product for your good life') |