SCANSKY commited on
Commit
e55b6a5
·
verified ·
1 Parent(s): 8373f68

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +8 -13
handler.py CHANGED
@@ -4,18 +4,13 @@ import joblib
4
  import torch
5
  import os
6
 
7
- # Load the label encoder
8
-
9
- from transformers import pipeline
10
- from sklearn.preprocessing import LabelEncoder
11
- import joblib
12
- import torch
13
- import os
14
 
15
- try:
16
- label_encoder = joblib.load('/repository/label_encoder.pkl')
17
- except Exception as e:
18
- raise FileNotFoundError("Label encoder file not found: /repository/label_encoder.pkl in cwd "+os.getcwd()) #Raise a file not found error.
19
 
20
  # Load the model and tokenizer from Hugging Face
21
  model_name = "SCANSKY/distilbertTourism-multilingual-sentiment"
@@ -44,7 +39,7 @@ def get_average_sentiment(positive_count, negative_count, neutral_count):
44
  else:
45
  return "neutral"
46
 
47
- class Handler:
48
  def __init__(self):
49
  # Model and tokenizer are loaded globally, so no need to reinitialize here
50
  pass
@@ -126,7 +121,7 @@ class Handler:
126
  "results": output
127
  }
128
 
129
- def handle(self, data):
130
  # Main method to handle the request
131
  text = self.preprocess(data)
132
  output = self.inference(text)
 
4
  import torch
5
  import os
6
 
7
+ # Debugging: Print current directory and contents
8
+ print("Current working directory:", os.getcwd())
9
+ print("Contents of the directory:", os.listdir())
 
 
 
 
10
 
11
+ # Load the label encoder
12
+ label_encoder = joblib.load('/repository/label_encoder.pkl') # Use absolute path
13
+ print("Label encoder loaded successfully.")
 
14
 
15
  # Load the model and tokenizer from Hugging Face
16
  model_name = "SCANSKY/distilbertTourism-multilingual-sentiment"
 
39
  else:
40
  return "neutral"
41
 
42
+ class EndpointHandler:
43
  def __init__(self):
44
  # Model and tokenizer are loaded globally, so no need to reinitialize here
45
  pass
 
121
  "results": output
122
  }
123
 
124
+ def __call__(self, data):
125
  # Main method to handle the request
126
  text = self.preprocess(data)
127
  output = self.inference(text)