Uan Sholanbayev
commited on
Commit
•
9ef518f
1
Parent(s):
a22dbf1
fix path to model
Browse files- handler.py +4 -2
handler.py
CHANGED
@@ -3,6 +3,8 @@ import numpy as np
|
|
3 |
from transformers import BertTokenizer, BertModel
|
4 |
import torch
|
5 |
import pickle
|
|
|
|
|
6 |
|
7 |
|
8 |
def unpickle_obj(filepath):
|
@@ -15,9 +17,9 @@ def unpickle_obj(filepath):
|
|
15 |
class EndpointHandler():
|
16 |
def __init__(self, path=""):
|
17 |
self.model = unpickle_obj(path)
|
18 |
-
self.tokenizer = BertTokenizer.from_pretrained(
|
19 |
self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
20 |
-
self.bert = BertModel.from_pretrained(
|
21 |
|
22 |
def get_embeddings(self, texts: List[str]):
|
23 |
inputs = self.tokenizer(texts, return_tensors='pt', truncation=True,
|
|
|
3 |
from transformers import BertTokenizer, BertModel
|
4 |
import torch
|
5 |
import pickle
|
6 |
+
import os
|
7 |
+
|
8 |
|
9 |
|
10 |
def unpickle_obj(filepath):
|
|
|
17 |
class EndpointHandler():
|
18 |
def __init__(self, path=""):
|
19 |
self.model = unpickle_obj(path)
|
20 |
+
self.tokenizer = BertTokenizer.from_pretrained(os.getcwd(), local_files_only=True)
|
21 |
self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
22 |
+
self.bert = BertModel.from_pretrained(os.getcwd()).to(self.device)
|
23 |
|
24 |
def get_embeddings(self, texts: List[str]):
|
25 |
inputs = self.tokenizer(texts, return_tensors='pt', truncation=True,
|