wang-sy commited on
Commit
2d23981
·
1 Parent(s): 44ec3c3

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +8 -5
handler.py CHANGED
@@ -1,13 +1,14 @@
1
  from typing import Dict, List, Any
2
- from transformers import pipeline, GPT2Tokenizer
3
  from model import GPT
 
4
 
5
  class EndpointHandler():
6
  def __init__(self, path=""):
7
  # Preload all the elements you are going to need at inference.
8
- model = GPT.from_pretrained('wang-sy/stinfo-gpt2')
9
  tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
10
- self.pipeline = pipeline("text-generation", model=model, tokenizer=tokenizer)
11
 
12
  def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
13
  """
@@ -18,5 +19,7 @@ class EndpointHandler():
18
  A :obj:`list` | `dict`: will be serialized and returned
19
  """
20
  inputs = data.pop("inputs", data)
21
- output = self.pipeline(inputs)
22
- return {"Answer": output}
 
 
 
1
  from typing import Dict, List, Any
2
+ from transformers import GPT2Tokenizer
3
  from model import GPT
4
+ import pipeline
5
 
6
  class EndpointHandler():
7
  def __init__(self, path=""):
8
  # Preload all the elements you are going to need at inference.
9
+ model = GPT.from_pretrained(path)
10
  tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
11
+ # self.pipeline = pipeline("text-generation", model=model, tokenizer=tokenizer)
12
 
13
  def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
14
  """
 
19
  A :obj:`list` | `dict`: will be serialized and returned
20
  """
21
  inputs = data.pop("inputs", data)
22
+ pipeline.start = inputs
23
+ output = pipeline.infer()
24
+ # isinstance(output,str)
25
+ return {"Ans": output}