Spaces:
Running
Running
Commit
·
bbc075a
1
Parent(s):
ede8cb5
add beautify text support
Browse files
app.py
CHANGED
|
@@ -18,14 +18,17 @@ def count_tokens(text):
|
|
| 18 |
# Encode the input text to get the list of token IDs
|
| 19 |
tokens = encoding.encode(text)
|
| 20 |
|
| 21 |
-
# Return the number of tokens
|
| 22 |
-
return len(tokens)
|
| 23 |
|
| 24 |
# Define the Gradio interface
|
| 25 |
iface = gr.Interface(
|
| 26 |
fn=count_tokens, # The function to call
|
| 27 |
-
inputs=gr.Textbox(lines=
|
| 28 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
| 29 |
title="Token Counter with tiktoken",
|
| 30 |
description="Enter text below to calculate the number of tokens using the tiktoken library.",
|
| 31 |
examples=[
|
|
|
|
| 18 |
# Encode the input text to get the list of token IDs
|
| 19 |
tokens = encoding.encode(text)
|
| 20 |
|
| 21 |
+
# Return the number of tokens and the beautified text
|
| 22 |
+
return len(tokens), text.replace("\\n", "\n")
|
| 23 |
|
| 24 |
# Define the Gradio interface
|
| 25 |
iface = gr.Interface(
|
| 26 |
fn=count_tokens, # The function to call
|
| 27 |
+
inputs=gr.Textbox(lines=1, max_lines=1000000, placeholder="Enter your text here..."), # Input component
|
| 28 |
+
outputs=[
|
| 29 |
+
"number",
|
| 30 |
+
gr.Textbox(label="Beautified Text", lines=30)
|
| 31 |
+
],
|
| 32 |
title="Token Counter with tiktoken",
|
| 33 |
description="Enter text below to calculate the number of tokens using the tiktoken library.",
|
| 34 |
examples=[
|