Rename custom_handler.py to handler.py
Browse files
custom_handler.py → handler.py
RENAMED
@@ -1,18 +1,17 @@
|
|
|
|
1 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
2 |
import torch
|
3 |
|
4 |
-
|
5 |
-
class CustomHandler:
|
6 |
def __init__(self, model_name_or_path):
|
7 |
self.tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
|
8 |
self.model = AutoModelForSequenceClassification.from_pretrained(model_name_or_path)
|
9 |
self.model.eval() # Set the model to evaluation mode
|
10 |
|
11 |
-
def __call__(self,
|
12 |
-
|
13 |
tokens = self.tokenizer(inputs, return_tensors='pt')
|
14 |
-
# Perform inference
|
15 |
with torch.no_grad():
|
16 |
outputs = self.model(**tokens)
|
17 |
-
# Postprocess the outputs
|
18 |
return outputs
|
|
|
|
1 |
+
model_name_or_path="alfaxadeyembe/gemma2-27b-swahili-it"
|
2 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
3 |
import torch
|
4 |
|
5 |
+
class EndpointHandler:
|
|
|
6 |
def __init__(self, model_name_or_path):
|
7 |
self.tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
|
8 |
self.model = AutoModelForSequenceClassification.from_pretrained(model_name_or_path)
|
9 |
self.model.eval() # Set the model to evaluation mode
|
10 |
|
11 |
+
def __call__(self, data):
|
12 |
+
inputs = data.get("inputs", "")
|
13 |
tokens = self.tokenizer(inputs, return_tensors='pt')
|
|
|
14 |
with torch.no_grad():
|
15 |
outputs = self.model(**tokens)
|
|
|
16 |
return outputs
|
17 |
+
|