Boubou78000 commited on
Commit
3e8ed31
1 Parent(s): 89002be
Files changed (1) hide show
  1. app.py +30 -13
app.py CHANGED
@@ -1,18 +1,35 @@
 
 
1
  import gradio as gr
2
- from transformers import pipeline
 
3
 
4
- pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
5
 
6
- def predict(input_img):
7
- predictions = pipeline(input_img)
8
- return input_img, {p["label"]: p["score"] for p in predictions}
 
 
 
 
 
 
 
 
9
 
10
- gradio_app = gr.Interface(
11
- predict,
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
- if __name__ == "__main__":
18
- gradio_app.launch()
 
 
 
 
 
 
 
 
 
 
 
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()