Commit
•
07b4bca
1
Parent(s):
394ddf5
add custom pipeline
Browse files- __pycache__/pipeline.cpython-37.pyc +0 -0
- pipeline.py +29 -0
- requirements.txt +1 -0
__pycache__/pipeline.cpython-37.pyc
ADDED
Binary file (1.14 kB). View file
|
|
pipeline.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Dict, List, Any
|
2 |
+
from transformers import pipeline
|
3 |
+
import holidays
|
4 |
+
|
5 |
+
class PreTrainedPipeline():
|
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 |
+
"""
|
12 |
+
data args:
|
13 |
+
inputs (:obj: `str`)
|
14 |
+
date (:obj: `str`)
|
15 |
+
Return:
|
16 |
+
A :obj:`list` | `dict`: will be serialized and returned
|
17 |
+
"""
|
18 |
+
# get inputs
|
19 |
+
inputs = data.pop("inputs",data)
|
20 |
+
date = data.pop("date", None)
|
21 |
+
|
22 |
+
# check if date exists and if it is holiday
|
23 |
+
if date is not None and date in self.holidays:
|
24 |
+
return [{"label": "happy", "score": 1}]
|
25 |
+
|
26 |
+
|
27 |
+
# run normal prediction
|
28 |
+
prediction = self.pipeline(inputs)
|
29 |
+
return prediction
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
holidays
|