adorkin commited on
Commit
aca3de7
·
1 Parent(s): f6f9509

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -7
app.py CHANGED
@@ -14,19 +14,15 @@ def preprocess(text):
14
  return " ".join(new_text)
15
 
16
 
17
- def get_top_emojis(text, top_n=TOP_N):
18
  preprocessed = preprocess(text)
19
  inputs = tokenizer(preprocessed, return_tensors="pt")
20
  preds = model(**inputs).logits
21
  scores = torch.nn.functional.softmax(preds, dim=-1).detach().numpy()
22
  ranking = np.argsort(scores)
23
- print(ranking)
24
  ranking = ranking.squeeze()[::-1][:top_n]
25
- print(scores)
26
- print(ranking)
27
- print(model.config.id2label)
28
  emojis = [model.config.id2label[i] for i in ranking]
29
- return '/t'.join(map(str, emojis))
30
 
31
  def main():
32
 
@@ -62,7 +58,7 @@ def main():
62
  # Define function to run when submit is clicked
63
  def submit(message):
64
  if len(message) > 0:
65
- st.header(get_top_emojis(message))
66
  else:
67
  st.error("The text can't be empty")
68
 
 
14
  return " ".join(new_text)
15
 
16
 
17
+ def get_top_emojis(text, tokenizer, top_n=TOP_N):
18
  preprocessed = preprocess(text)
19
  inputs = tokenizer(preprocessed, return_tensors="pt")
20
  preds = model(**inputs).logits
21
  scores = torch.nn.functional.softmax(preds, dim=-1).detach().numpy()
22
  ranking = np.argsort(scores)
 
23
  ranking = ranking.squeeze()[::-1][:top_n]
 
 
 
24
  emojis = [model.config.id2label[i] for i in ranking]
25
+ return '\t'.join(map(str, emojis))
26
 
27
  def main():
28
 
 
58
  # Define function to run when submit is clicked
59
  def submit(message):
60
  if len(message) > 0:
61
+ st.header(get_top_emojis(message, tokenizer=tokenizer))
62
  else:
63
  st.error("The text can't be empty")
64