Update handler.py
Browse files- handler.py +8 -5
handler.py
CHANGED
|
@@ -1,13 +1,14 @@
|
|
| 1 |
from typing import Dict, List, Any
|
| 2 |
-
from transformers import
|
| 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(
|
| 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 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
| 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}
|