Alfaxad commited on
Commit
4414af8
·
verified ·
1 Parent(s): 3ab23cf

Rename custom_handler.py to handler.py

Browse files
Files changed (1) hide show
  1. custom_handler.py → handler.py +5 -6
custom_handler.py → handler.py RENAMED
@@ -1,18 +1,17 @@
 
1
  from transformers import AutoModelForSequenceClassification, AutoTokenizer
2
  import torch
3
 
4
- model_name_or_path="alfaxadeyembe/gemma2-27b-swahili-it"
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, inputs):
12
- # Preprocess the inputs
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
+