Spaces:
Sleeping
Sleeping
Boubou78000
commited on
Commit
•
3e8ed31
1
Parent(s):
89002be
Idea
Browse files
app.py
CHANGED
@@ -1,18 +1,35 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
-
from
|
|
|
3 |
|
4 |
-
|
5 |
|
6 |
-
def
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
inputs=gr.Image(label="Select hot dog candidate", sources=['upload', 'webcam'], type="pil"),
|
13 |
-
outputs=[gr.Image(label="Processed Image"), gr.Label(label="Result", num_top_classes=2)],
|
14 |
-
title="Hot Dog? Or Not?",
|
15 |
-
)
|
16 |
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import token
|
2 |
+
import tokenize
|
3 |
import gradio as gr
|
4 |
+
from datasets import load_dataset
|
5 |
+
from tokenizers import Tokenizer
|
6 |
|
7 |
+
from StreetFlash.Farm import Get
|
8 |
|
9 |
+
def ReturnTokens(dataset, tokenizer="openai-community/gpt2", split="train"):
|
10 |
+
global tokens_
|
11 |
+
tokenizer=Tokenizer.from_pretrained(tokenizer)
|
12 |
+
dataset=load_dataset(dataset)
|
13 |
+
tokens_=0
|
14 |
+
def CountTokens(Example):
|
15 |
+
global tokens_
|
16 |
+
for i in Example.values():
|
17 |
+
tokens_+=len(Tokenizer.encode(i))
|
18 |
+
dataset.map(CountTokens)
|
19 |
+
return tokens_
|
20 |
|
21 |
+
with gr.Blocks(title="Dataset token counter") as app:
|
22 |
+
gr.Markdown("# Token Counter")
|
|
|
|
|
|
|
|
|
23 |
|
24 |
+
with gr.Row():
|
25 |
+
prompt = gr.Textbox(label="Dataset", elem_id="dataset", info="", placeholder="")
|
26 |
+
tokenizer = gr.Textbox(label="Tokenizer", elem_id="tokenizer", info="", placeholder="openai-community/gpt2", value="openai-community/gpt2")
|
27 |
+
split = gr.Textbox(label="Split (default: train)", elem_id="split", info="", placeholder="train", value="train")
|
28 |
+
tokens = gr.Label(label="Tokens", elem_id="tokens", info="")
|
29 |
+
prompt.submit().success(
|
30 |
+
ReturnTokens,
|
31 |
+
inputs=[prompt,tokenizer,split],
|
32 |
+
outputs=[tokens]
|
33 |
+
)
|
34 |
+
|
35 |
+
app.launch()
|