ayameRushia's picture
Update app.py
cbc4091
raw
history blame
586 Bytes
import gradio as gr
import tiktoken
encoding = tiktoken.encoding_for_model("gpt-3.5-turbo")
def num_tokens_from_string(string: str) -> int:
encoding = tiktoken.get_encoding("cl100k_base")
num_tokens = len(encoding.encode(string))
return num_tokens
gr.Interface(
fn=num_tokens_from_string,
inputs=gr.inputs.Textbox(),
outputs="text",
live=True,
title="GPT-3.5 Token Counter",
description="Enter text and see the token usage.",
article="To use the GPT-3.5/GPT-4 token counter, simply enter your text in the input box above.",
).launch(share=True)