cifkao commited on
Commit
fdbcf74
1 Parent(s): 068dd93

Include EOS token

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -86,18 +86,21 @@ dependencies.
86
 
87
  text = st.text_area("Input text", DEFAULT_TEXT)
88
 
 
 
89
  inputs = tokenizer([text])
90
  [input_ids] = inputs["input_ids"]
 
91
 
92
- if len(input_ids) < 2 or len(input_ids) > max_tokens:
93
- st.caption(f":red[{len(input_ids)}]/{max_tokens} tokens")
94
  else:
95
- st.caption(f"{len(input_ids)}/{max_tokens} tokens")
96
 
97
- if len(input_ids) < 2:
98
- st.error("Please enter at least 2 tokens.", icon="🚨")
99
  st.stop()
100
- if len(input_ids) > max_tokens:
101
  st.error(
102
  f"Please enter at most {max_tokens} tokens or try reducing the window size.",
103
  icon="🚨"
 
86
 
87
  text = st.text_area("Input text", DEFAULT_TEXT)
88
 
89
+ if tokenizer.eos_token:
90
+ text += tokenizer.eos_token
91
  inputs = tokenizer([text])
92
  [input_ids] = inputs["input_ids"]
93
+ num_user_tokens = len(input_ids) - (1 if tokenizer.eos_token else 0)
94
 
95
+ if num_user_tokens < 1 or num_user_tokens > max_tokens:
96
+ st.caption(f":red[{num_user_tokens}]/{max_tokens} tokens")
97
  else:
98
+ st.caption(f"{num_user_tokens}/{max_tokens} tokens")
99
 
100
+ if num_user_tokens < 1:
101
+ st.error("Please enter at least one token.", icon="🚨")
102
  st.stop()
103
+ if num_user_tokens > max_tokens:
104
  st.error(
105
  f"Please enter at most {max_tokens} tokens or try reducing the window size.",
106
  icon="🚨"