Instructions to use LA1512/led-epoch-1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use LA1512/led-epoch-1 with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("LA1512/led-epoch-1") model = AutoModelForSeq2SeqLM.from_pretrained("LA1512/led-epoch-1", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download handler.py from LA1512/led-epoch-1: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/LA1512/led-epoch-1/resolve/main/handler.py
- Command line
-
hf download hf://LA1512/led-epoch-1/handler.py
-
curl -L -o handler.py https://huggingface.co/LA1512/led-epoch-1/resolve/main/handler.py
1.4 kB
| from typing import Dict, List, Any | |
| from transformers import pipeline, AutoTokenizer, BartForConditionalGeneration | |
| class EndpointHandler(): | |
| def __init__(self, path=""): | |
| self.device = 'cuda' if torch.cuda.is_available() else 'cpu' | |
| try: | |
| self.model = BartForConditionalGeneration.from_pretrained(path).to(self.device) | |
| self.tokenizer = AutoTokenizer.from_pretrained(path) | |
| except Exception as e: | |
| print(f"Error loading model or tokenizer from path {path}: {e}") | |
| def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]: | |
| """ | |
| data args: | |
| inputs (:obj: `str`) | |
| date (:obj: `str`) | |
| Return: | |
| A :obj:`list` | `dict`: will be serialized and returned | |
| """ | |
| # get inputs | |
| inputs = data.get("inputs", "") | |
| if not inputs: | |
| return [{"error": "No inputs provided"}] | |
| tokenized_input = self.tokenizer(inputs, return_tensors="pt", truncation=True, max_length=1024, padding="max_length") | |
| tokenized_input = tokenized_input.to(self.device) # Move input tensors to the same device as model | |
| summary_ids = self.model.generate(**tokenized_input, max_length=256, do_sample=True, top_p=0.8) | |
| summary_text = self.tokenizer.decode(summary_ids[0], skip_special_tokens=True) | |
| return [{"summary": summary_text}] |