thak123 commited on
Commit
6c86820
·
1 Parent(s): 8cd8309

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -33
app.py CHANGED
@@ -9,27 +9,6 @@ import config
9
  from transformers import pipeline, AutoTokenizer, AutoModel
10
  import gradio as gr
11
 
12
- # DEVICE = config.device
13
-
14
- # model = AutoModel.from_pretrained("thak123/bert-emoji-latvian-twitter-classifier")
15
- # 7 EPOCH Version
16
- # BERT_PATH = "FFZG-cleopatra/bert-emoji-latvian-twitter"
17
-
18
- # tokenizer = transformers.BertTokenizer.from_pretrained(
19
- # BERT_PATH,
20
- # do_lower_case=True
21
- # )
22
- #AutoTokenizer.from_pretrained("FFZG-cleopatra/bert-emoji-latvian-twitter")
23
-
24
- # classifier = pipeline("sentiment-analysis",
25
- # model= model,
26
- # tokenizer = tokenizer)
27
-
28
- # MODEL = BERTBaseUncased()
29
- # MODEL.load_state_dict(torch.load(config.MODEL_PATH, map_location=torch.device(DEVICE)))
30
- # MODEL.eval()
31
-
32
-
33
 
34
  # T = tokenizer.TweetTokenizer(
35
  # preserve_handles=True, preserve_hashes=True, preserve_case=False, preserve_url=False)
@@ -58,27 +37,27 @@ def preprocess(text):
58
  def sentence_prediction(sentence):
59
  # sentence = preprocess(sentence)
60
 
61
- # model_path = config.MODEL_PATH
62
 
63
- # test_dataset = dataset.BERTDataset(
64
- # review=[sentence],
65
- # target=[0]
66
- # )
67
 
68
- # test_data_loader = torch.utils.data.DataLoader(
69
- # test_dataset,
70
- # batch_size=config.VALID_BATCH_SIZE,
71
- # num_workers=3
72
- # )
73
 
74
- # device = config.device
75
 
76
  model = BERTBaseUncased()
77
  model.load_state_dict(torch.load(
78
  model_path, map_location=torch.device(device)))
79
  model.to(device)
80
 
81
- outputs, [] = engine.predict_fn(test_data_loader, MODEL, device)
82
 
83
  outputs = classifier(sentence)
84
 
 
9
  from transformers import pipeline, AutoTokenizer, AutoModel
10
  import gradio as gr
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  # T = tokenizer.TweetTokenizer(
14
  # preserve_handles=True, preserve_hashes=True, preserve_case=False, preserve_url=False)
 
37
  def sentence_prediction(sentence):
38
  # sentence = preprocess(sentence)
39
 
40
+ model_path = config.MODEL_PATH
41
 
42
+ test_dataset = dataset.BERTDataset(
43
+ review=[sentence],
44
+ target=[0]
45
+ )
46
 
47
+ test_data_loader = torch.utils.data.DataLoader(
48
+ test_dataset,
49
+ batch_size=config.VALID_BATCH_SIZE,
50
+ num_workers=3
51
+ )
52
 
53
+ device = config.device
54
 
55
  model = BERTBaseUncased()
56
  model.load_state_dict(torch.load(
57
  model_path, map_location=torch.device(device)))
58
  model.to(device)
59
 
60
+ outputs, [] = engine.predict_fn(test_data_loader, model, device)
61
 
62
  outputs = classifier(sentence)
63