torinriley
commited on
Commit
•
0229607
1
Parent(s):
30ad7c6
Update handler.py
Browse files- handler.py +11 -5
handler.py
CHANGED
@@ -1,9 +1,15 @@
|
|
1 |
import torch
|
2 |
from typing import Dict, List, Any
|
3 |
from tokenizers import Tokenizer
|
4 |
-
|
|
|
5 |
import warnings
|
6 |
|
|
|
|
|
|
|
|
|
|
|
7 |
warnings.simplefilter("ignore", category=FutureWarning)
|
8 |
|
9 |
class EndpointHandler:
|
@@ -14,10 +20,10 @@ class EndpointHandler:
|
|
14 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
15 |
self.device = device
|
16 |
|
17 |
-
#
|
18 |
-
self.model_weights_path = path
|
19 |
-
self.tokenizer_src_path = path
|
20 |
-
self.tokenizer_tgt_path = path
|
21 |
|
22 |
# Load tokenizers
|
23 |
self.tokenizer_src = Tokenizer.from_file(self.tokenizer_src_path)
|
|
|
1 |
import torch
|
2 |
from typing import Dict, List, Any
|
3 |
from tokenizers import Tokenizer
|
4 |
+
import sys
|
5 |
+
import os
|
6 |
import warnings
|
7 |
|
8 |
+
# Add the current directory to the system path to locate the model module
|
9 |
+
sys.path.append(os.path.dirname(__file__))
|
10 |
+
|
11 |
+
from model import build_transformer
|
12 |
+
|
13 |
warnings.simplefilter("ignore", category=FutureWarning)
|
14 |
|
15 |
class EndpointHandler:
|
|
|
20 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
21 |
self.device = device
|
22 |
|
23 |
+
# Paths for weights and tokenizers
|
24 |
+
self.model_weights_path = os.path.join(path, "SAVE.pt") # Ensure SAVE.pt is uploaded in the repository
|
25 |
+
self.tokenizer_src_path = os.path.join(path, "tokenizer_en.json")
|
26 |
+
self.tokenizer_tgt_path = os.path.join(path, "tokenizer_it.json")
|
27 |
|
28 |
# Load tokenizers
|
29 |
self.tokenizer_src = Tokenizer.from_file(self.tokenizer_src_path)
|