| | from typing import Dict, List, Any |
| | from transformers import pipeline, AutoTokenizer |
| |
|
| | class EndpointHandler: |
| | def __init__(self, path=""): |
| | |
| | tokenizer = AutoTokenizer.from_pretrained(path) |
| | |
| | self.pipeline = pipeline("text-classification", model=path, tokenizer=tokenizer) |
| |
|
| | def __call__(self, data: str) -> List[List[Dict[str, float]]]: |
| | """ |
| | Args: |
| | data (str): A raw string input for inference. |
| | Returns: |
| | A list containing the prediction results: |
| | A list of one list, e.g., [[{"label": "LABEL", "score": 0.99}]] |
| | """ |
| | |
| | inputs = data.pop("inputs", data) |
| | prediction = self.pipeline(inputs) |
| |
|
| | |
| | return prediction |