zemuwen commited on
Commit
172c1a7
·
verified ·
1 Parent(s): f30715f

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +3 -10
handler.py CHANGED
@@ -1,19 +1,12 @@
1
  from typing import Dict, List, Any
2
  from transformers import pipeline
3
- import holidays
4
-
5
  class EndpointHandler():
6
  def __init__(self, path=""):
 
7
  self.pipeline = pipeline("text-classification", model=path)
8
- self.holidays = holidays.US()
9
 
10
  def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
11
- inputs = data.pop("inputs", "")
12
- date = data.pop("date", None)
13
-
14
- # 根据日期判断是否是假期
15
- if date and date in self.holidays:
16
- return [{"label": "happy", "score": 1}]
17
-
18
  prediction = self.pipeline(inputs)
19
  return prediction
 
1
  from typing import Dict, List, Any
2
  from transformers import pipeline
 
 
3
  class EndpointHandler():
4
  def __init__(self, path=""):
5
+ # 初始化方法,加载模型
6
  self.pipeline = pipeline("text-classification", model=path)
 
7
 
8
  def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
9
+ # 处理输入数据并返回预测结果
10
+ inputs = data.get("inputs", "")
 
 
 
 
 
11
  prediction = self.pipeline(inputs)
12
  return prediction