File size: 609 Bytes
f30715f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
from typing import Dict, List, Any
from transformers import pipeline
import holidays
class EndpointHandler():
def __init__(self, path=""):
self.pipeline = pipeline("text-classification", model=path)
self.holidays = holidays.US()
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
inputs = data.pop("inputs", "")
date = data.pop("date", None)
# 根据日期判断是否是假期
if date and date in self.holidays:
return [{"label": "happy", "score": 1}]
prediction = self.pipeline(inputs)
return prediction
|