handler for running inference endpoints
Browse files- handler.py +14 -0
handler.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
2 |
+
|
3 |
+
|
4 |
+
class EndpointHandler:
|
5 |
+
def __init__(self, path="Chituyi7/EBO-AlpacaLlama3-8B-InstructionTuned"):
|
6 |
+
# Initialize your model here
|
7 |
+
self.model = AutoModelForSequenceClassification.from_pretrained(path)
|
8 |
+
self.tokenizer = AutoTokenizer.from_pretrained(path)
|
9 |
+
|
10 |
+
def __call__(self, data):
|
11 |
+
# Use your model to make predictions here
|
12 |
+
inputs = self.tokenizer(data["inputs"], return_tensors="pt")
|
13 |
+
outputs = self.model(**inputs)
|
14 |
+
return outputs.logits.argmax(-1).item()
|