Spaces:
Sleeping
Sleeping
first commit
Browse files- app.py +28 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tiktoken
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
def tokens_len(prompt, model):
|
| 5 |
+
encoder = tiktoken.encoding_for_model(model)
|
| 6 |
+
tokens = encoder.encode(prompt)
|
| 7 |
+
return len(tokens)
|
| 8 |
+
|
| 9 |
+
web_tokenizer = gr.Interface(
|
| 10 |
+
fn = tokens_len,
|
| 11 |
+
inputs = [
|
| 12 |
+
gr.Textbox(label='輸入提示文字'),
|
| 13 |
+
gr.Dropdown(
|
| 14 |
+
label='模型名稱',
|
| 15 |
+
choices = [
|
| 16 |
+
'gpt-4o-mini',
|
| 17 |
+
'gpt-4o',
|
| 18 |
+
'gpt-4',
|
| 19 |
+
'gpt-3.5-turbo'
|
| 20 |
+
],
|
| 21 |
+
value='gpt-4o-mini')
|
| 22 |
+
],
|
| 23 |
+
outputs = [
|
| 24 |
+
gr.Number(label='Token 數量:')
|
| 25 |
+
]
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
web_tokenizer.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
tiktoken
|