14B_lora_ze / handler.py
zemuwen's picture
6
f30715f verified
raw
history blame
609 Bytes
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