Download handler.py from classla/multilingual-IPTC-news-topic-classifier: direct link, hf CLI and curl.
- Browser
- Download file 377 Bytes
-
https://huggingface.co/classla/multilingual-IPTC-news-topic-classifier/resolve/refs%2Fpr%2F1/handler.py
- Command line
-
hf download hf://classla/multilingual-IPTC-news-topic-classifier@refs/pr/1/handler.py
-
curl -L -o handler.py https://huggingface.co/classla/multilingual-IPTC-news-topic-classifier/resolve/refs%2Fpr%2F1/handler.py
377 Bytes
| from transformers import pipeline | |
| import json | |
| # Load the model | |
| def model_fn(model_dir): | |
| classifier = pipeline("text-classification", model=model_dir) | |
| return classifier | |
| # Handle requests | |
| def predict_fn(input_data, model): | |
| # Parse input data | |
| data = json.loads(input_data) | |
| texts = data.get("inputs", []) | |
| predictions = model(texts) | |
| return predictions | |