thesven commited on
Commit
ac0ed37
1 Parent(s): 0e62613

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -4
app.py CHANGED
@@ -1,7 +1,45 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import AutoTokenizer
3
 
4
+ def load_tokenizer(repo_path):
5
+ try:
6
+ # Load the tokenizer from the provided repository path
7
+ tokenizer = AutoTokenizer.from_pretrained(repo_path, trust_remote_code=True)
8
 
9
+ messages = [
10
+ {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
11
+ {"role": "user", "content": "Who are you?"},
12
+ ]
13
+
14
+ input_ids = tokenizer.apply_chat_template(
15
+ messages,
16
+ add_generation_prompt=True,
17
+ tokenize=False,
18
+ )
19
+
20
+ # Extract relevant details about the tokenizer and chat template
21
+ details = {
22
+ "Tokenizer Name": tokenizer.name_or_path,
23
+ "Vocabulary Size": tokenizer.vocab_size,
24
+ "Model Max Length": tokenizer.model_max_length,
25
+ "Special Tokens": tokenizer.all_special_tokens,
26
+ "Chat Template": input_ids,
27
+ }
28
+
29
+ # Convert details to a formatted string for display
30
+ details_str = "\n".join([f"{key}: {value}" for key, value in details.items()])
31
+ return details_str
32
+ except Exception as e:
33
+ return str(e)
34
+
35
+ # Create the Gradio interface
36
+ iface = gr.Interface(
37
+ fn=load_tokenizer,
38
+ inputs=gr.Textbox(label="Hugging Face Repository Path (e.g., user/repo)"),
39
+ outputs=gr.Textbox(label="Tokenizer Details"),
40
+ title="Hugging Face Tokenizer Loader",
41
+ description="Enter the Hugging Face repository path to load the tokenizer and view its details."
42
+ )
43
+
44
+ # Launch the app
45
+ iface.launch()