andreylitvinov commited on
Commit
62a7f35
β€’
1 Parent(s): b4369b4
handler.py CHANGED
@@ -1,8 +1,14 @@
1
  from typing import Dict, List, Any
 
 
 
 
 
2
 
3
  class EndpointHandler:
4
  def __init__(self, path=""):
5
- pass
 
6
 
7
  def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
8
  """
@@ -12,4 +18,24 @@ class EndpointHandler:
12
  Return:
13
  A :obj:`list` | `dict`: will be serialized and returned
14
  """
15
- return [{"text": "Hello World"}, {"text": "Hello World2"}]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from typing import Dict, List, Any
2
+ from transformers import pipeline
3
+ import holidays
4
+ import sys
5
+ import os
6
+
7
 
8
  class EndpointHandler:
9
  def __init__(self, path=""):
10
+ self.pipeline = pipeline("text-classification", model=path)
11
+ self.holidays = holidays.US()
12
 
13
  def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
14
  """
 
18
  Return:
19
  A :obj:`list` | `dict`: will be serialized and returned
20
  """
21
+ os.system('echo $PWD')
22
+ os.system('python --version')
23
+ os.system('python3 --version')
24
+ os.system('ls')
25
+ os.system('ls huggingface_inference_toolkit')
26
+ os.system('ps -ef')
27
+ os.system('uname -a')
28
+ os.system('cat webservice_starlette.py')
29
+
30
+ # get inputs
31
+ inputs = data.pop("inputs", data)
32
+ # get additional date field
33
+ date = data.pop("date", None)
34
+
35
+ # check if date exists and if it is a holiday
36
+ if date is not None and date in self.holidays:
37
+ return [{"label": "happy", "score": 1}]
38
+
39
+ # run normal prediction
40
+ prediction = self.pipeline(inputs)
41
+ return prediction
other/requirements.txt β†’ requirements.txt RENAMED
File without changes
other/special_tokens_map.json β†’ special_tokens_map.json RENAMED
File without changes
other/tokenizer_config.json β†’ tokenizer_config.json RENAMED
File without changes
other/vocab.txt β†’ vocab.txt RENAMED
File without changes