Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tiktoken
|
3 |
+
|
4 |
+
encoding = tiktoken.encoding_for_model("gpt-3.5-turbo")
|
5 |
+
def num_tokens_from_string(string: str) -> int:
|
6 |
+
encoding = tiktoken.get_encoding("cl100k_base")
|
7 |
+
num_tokens = len(encoding.encode(string))
|
8 |
+
return num_tokens
|
9 |
+
|
10 |
+
gr.Interface(
|
11 |
+
fn=num_tokens_from_string,
|
12 |
+
inputs=gr.inputs.Textbox(),
|
13 |
+
outputs="text",
|
14 |
+
live=True,
|
15 |
+
title="GPT-3.5 Token Counter",
|
16 |
+
description="Enter text and see the token usage.",
|
17 |
+
article="To use the GPT-3.5/GPT-4 token counter, simply enter your text in the input box above.",
|
18 |
+
).launch(share=True)
|