Alfaxad commited on
Commit
6fda4a2
·
verified ·
1 Parent(s): 039c1c1

Create handler.py

Browse files
Files changed (1) hide show
  1. handler.py +16 -0
handler.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ model_name_or_path="alfaxadeyembe/gemma2-2b-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