Upload handler.py
Browse files- handler.py +1 -12
handler.py
CHANGED
|
@@ -2,10 +2,6 @@ import torch
|
|
| 2 |
from typing import Dict, List, Any
|
| 3 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 4 |
|
| 5 |
-
# check for GPU
|
| 6 |
-
device = 0 if torch.cuda.is_available() else -1
|
| 7 |
-
|
| 8 |
-
|
| 9 |
class EndpointHandler:
|
| 10 |
def __init__(self, path=""):
|
| 11 |
# load the model
|
|
@@ -16,12 +12,5 @@ class EndpointHandler:
|
|
| 16 |
|
| 17 |
def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
|
| 18 |
inputs = data.pop("inputs", data)
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
# pass inputs with all kwargs in data
|
| 22 |
-
if parameters is not None:
|
| 23 |
-
prediction = self.pipeline(inputs, **parameters)
|
| 24 |
-
else:
|
| 25 |
-
prediction = self.pipeline(inputs)
|
| 26 |
-
# postprocess the prediction
|
| 27 |
return prediction
|
|
|
|
| 2 |
from typing import Dict, List, Any
|
| 3 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
class EndpointHandler:
|
| 6 |
def __init__(self, path=""):
|
| 7 |
# load the model
|
|
|
|
| 12 |
|
| 13 |
def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
|
| 14 |
inputs = data.pop("inputs", data)
|
| 15 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
return prediction
|