Spaces:
Build error
Build error
File size: 482 Bytes
5bd179e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
from modules.text_generation import decode, encode
def token_count(prompt):
tokens = encode(prompt)[0]
return {
'length': len(tokens)
}
def token_encode(input):
tokens = encode(input)[0]
if tokens.__class__.__name__ in ['Tensor', 'ndarray']:
tokens = tokens.tolist()
return {
'tokens': tokens,
'length': len(tokens),
}
def token_decode(tokens):
output = decode(tokens)
return {
'text': output
}
|