dordonezc commited on
Commit
168dfbc
1 Parent(s): 55fd9e6

Added handler

Browse files
Files changed (1) hide show
  1. handler.py +16 -0
handler.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
3
+ from typing import Dict, List, Any
4
+
5
+ class EndpointHandler():
6
+ def __init__(self, path=""):
7
+ self.model = AutoModelForCausalLM.from_pretrained(path, device_map="cuda", torch_dtype="auto", trust_remote_code=True)
8
+ self.tokenizer = AutoTokenizer.from_pretrained(path)
9
+ self.pipeline = pipeline("text-generation", model=self.model, tokenizer=self.tokenizer)
10
+
11
+ def __call__(self, data: Dict[str, Dict[str, Any]]) -> Any:
12
+ inputs = data["inputs"]["msg"]
13
+ parameters = data["args"]
14
+ prediction = self.pipeline(inputs, **parameters)
15
+ output = prediction[0]['generated_text']
16
+ return output