connersdavis
commited on
Commit
·
be39b45
1
Parent(s):
a26d44a
handler.py
Browse files- handler.py +28 -0
- requirements.txt +3 -0
handler.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Dict, List, Any
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
class PreTrainedPipeline():
|
5 |
+
def __init__(self, path=""):
|
6 |
+
self.pipeline = pipeline("text-classification",model=path)
|
7 |
+
self.holidays = holidays.US()
|
8 |
+
|
9 |
+
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
10 |
+
"""
|
11 |
+
data args:
|
12 |
+
inputs (:obj: `str`)
|
13 |
+
date (:obj: `str`)
|
14 |
+
Return:
|
15 |
+
A :obj:`list` | `dict`: will be serialized and returned
|
16 |
+
"""
|
17 |
+
# get inputs
|
18 |
+
inputs = data.pop("inputs",data)
|
19 |
+
date = data.pop("date", None)
|
20 |
+
|
21 |
+
# check if date exists and if it is holiday
|
22 |
+
if date is not None and date in self.holidays:
|
23 |
+
return [{"label": "happy", "score": 1}]
|
24 |
+
|
25 |
+
|
26 |
+
# run normal prediction
|
27 |
+
prediction = self.pipeline(inputs)
|
28 |
+
return prediction
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
diffusers
|
3 |
+
typing
|