Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,26 @@
|
|
1 |
import torch
|
2 |
-
from utils import label_full_decoder
|
3 |
import sys
|
4 |
-
import dataset
|
5 |
-
import engine
|
6 |
-
from model import BERTBaseUncased
|
7 |
-
from tokenizer import tokenizer
|
8 |
-
import config
|
9 |
-
|
10 |
import gradio as gr
|
11 |
|
12 |
DEVICE = config.device
|
13 |
|
|
|
|
|
14 |
# MODEL = BERTBaseUncased()
|
15 |
# MODEL.load_state_dict(torch.load(config.MODEL_PATH, map_location=torch.device(DEVICE)))
|
16 |
# MODEL.eval()
|
17 |
|
18 |
|
19 |
|
20 |
-
T = tokenizer.TweetTokenizer(
|
21 |
-
|
22 |
|
23 |
def preprocess(text):
|
24 |
tokens = T.tokenize(text)
|
@@ -43,29 +45,32 @@ def preprocess(text):
|
|
43 |
|
44 |
def sentence_prediction(sentence):
|
45 |
sentence = preprocess(sentence)
|
46 |
-
model_path = config.MODEL_PATH
|
47 |
|
48 |
-
test_dataset = dataset.BERTDataset(
|
49 |
-
|
50 |
-
|
51 |
-
)
|
52 |
|
53 |
-
test_data_loader = torch.utils.data.DataLoader(
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
)
|
58 |
|
59 |
# device = config.device
|
60 |
|
61 |
-
model = BERTBaseUncased()
|
62 |
-
# model.load_state_dict(torch.load(
|
63 |
-
# model_path, map_location=torch.device(device)))
|
64 |
-
model.to(device)
|
65 |
|
66 |
-
outputs, [] = engine.predict_fn(test_data_loader, MODEL, device)
|
|
|
|
|
|
|
67 |
print(outputs)
|
68 |
-
return {"label":outputs[0]}
|
69 |
|
70 |
if __name__ == "__main__":
|
71 |
|
|
|
1 |
import torch
|
2 |
+
# from utils import label_full_decoder
|
3 |
import sys
|
4 |
+
# import dataset
|
5 |
+
# import engine
|
6 |
+
# from model import BERTBaseUncased
|
7 |
+
# from tokenizer import tokenizer
|
8 |
+
# import config
|
9 |
+
from transformers import pipeline, AutoTokenizer, AutoModel
|
10 |
import gradio as gr
|
11 |
|
12 |
DEVICE = config.device
|
13 |
|
14 |
+
classifier = pipeline("sentiment-analysis",model="thak123/bert-emoji-latvian-twitter-classifier", tokenizer = "FFZG-cleopatra/bert-emoji-latvian-twitter")
|
15 |
+
|
16 |
# MODEL = BERTBaseUncased()
|
17 |
# MODEL.load_state_dict(torch.load(config.MODEL_PATH, map_location=torch.device(DEVICE)))
|
18 |
# MODEL.eval()
|
19 |
|
20 |
|
21 |
|
22 |
+
# T = tokenizer.TweetTokenizer(
|
23 |
+
# preserve_handles=True, preserve_hashes=True, preserve_case=False, preserve_url=False)
|
24 |
|
25 |
def preprocess(text):
|
26 |
tokens = T.tokenize(text)
|
|
|
45 |
|
46 |
def sentence_prediction(sentence):
|
47 |
sentence = preprocess(sentence)
|
48 |
+
# model_path = config.MODEL_PATH
|
49 |
|
50 |
+
# test_dataset = dataset.BERTDataset(
|
51 |
+
# review=[sentence],
|
52 |
+
# target=[0]
|
53 |
+
# )
|
54 |
|
55 |
+
# test_data_loader = torch.utils.data.DataLoader(
|
56 |
+
# test_dataset,
|
57 |
+
# batch_size=config.VALID_BATCH_SIZE,
|
58 |
+
# num_workers=3
|
59 |
+
# )
|
60 |
|
61 |
# device = config.device
|
62 |
|
63 |
+
# model = BERTBaseUncased()
|
64 |
+
# # model.load_state_dict(torch.load(
|
65 |
+
# # model_path, map_location=torch.device(device)))
|
66 |
+
# model.to(device)
|
67 |
|
68 |
+
# outputs, [] = engine.predict_fn(test_data_loader, MODEL, device)
|
69 |
+
|
70 |
+
outputs = sentiment(input_text)
|
71 |
+
|
72 |
print(outputs)
|
73 |
+
return outputs #{"label":outputs[0]}
|
74 |
|
75 |
if __name__ == "__main__":
|
76 |
|