thak123 commited on
Commit
55b119f
·
1 Parent(s): 058e542

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -12,9 +12,14 @@ import engine
12
  from model import BERTBaseUncased
13
 
14
  MODEL = None
15
- DEVICE = config.device
16
  T = tokenizer.TweetTokenizer(preserve_handles=True, preserve_hashes=True, preserve_case=False, preserve_url=False)
17
 
 
 
 
 
 
18
 
19
  def preprocess(text):
20
  tokens = T.tokenize(text)
@@ -39,7 +44,7 @@ def preprocess(text):
39
 
40
  def sentence_prediction(sentence):
41
  sentence = preprocess(sentence)
42
- model_path = config.MODEL_PATH
43
 
44
  test_dataset = dataset.BERTDataset(
45
  review=[sentence],
@@ -52,23 +57,16 @@ def sentence_prediction(sentence):
52
  num_workers=3
53
  )
54
 
55
- device = config.device
56
-
57
- model = BERTBaseUncased()
58
- model.load_state_dict(torch.load(
59
- model_path, map_location=torch.device(device)))
60
- model.to(device)
61
-
62
  outputs, [] = engine.predict_fn(test_data_loader, model, device)
63
  print(outputs)
64
- return outputs[0]
65
 
66
  interface = gr.Interface(
67
  fn=sentence_prediction,
68
  inputs='text',
69
  outputs=['text'],
70
  title='Sentiment Analysis',
71
- description='Get the positive/negative sentiment for the given input.'
72
  )
73
 
74
 
 
12
  from model import BERTBaseUncased
13
 
14
  MODEL = None
15
+
16
  T = tokenizer.TweetTokenizer(preserve_handles=True, preserve_hashes=True, preserve_case=False, preserve_url=False)
17
 
18
+ device = config.device
19
+
20
+ model = BERTBaseUncased()
21
+ model.load_state_dict(torch.load(model_path, map_location=torch.device(device)))
22
+ model.to(device)
23
 
24
  def preprocess(text):
25
  tokens = T.tokenize(text)
 
44
 
45
  def sentence_prediction(sentence):
46
  sentence = preprocess(sentence)
47
+
48
 
49
  test_dataset = dataset.BERTDataset(
50
  review=[sentence],
 
57
  num_workers=3
58
  )
59
 
 
 
 
 
 
 
 
60
  outputs, [] = engine.predict_fn(test_data_loader, model, device)
61
  print(outputs)
62
+ return label_full_decoder(outputs[0])
63
 
64
  interface = gr.Interface(
65
  fn=sentence_prediction,
66
  inputs='text',
67
  outputs=['text'],
68
  title='Sentiment Analysis',
69
+ description='Get the positive/neutral/negative sentiment for the given input.'
70
  )
71
 
72