lucyknada commited on
Commit
aeabc48
·
verified ·
1 Parent(s): 0429e33

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -1,13 +1,25 @@
1
  import gradio as gr
 
2
 
3
  with gr.Blocks() as demo:
4
- huggingface = gr.Textbox(placeholder="mistralai/Mistral-Small-24B-Instruct-2501", show_label=True, label="huggingface ID")
5
  button = gr.Button(value="get chat template")
6
- textbox = gr.Textbox(lines=10.0)
7
 
8
- @button.click(inputs=[button], outputs=[])
9
- def fn_1(button):
10
- ...
11
- return
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  demo.launch()
 
1
  import gradio as gr
2
+ from transformers import AutoTokenizer
3
 
4
  with gr.Blocks() as demo:
5
+ huggingface = gr.Textbox(value="mistralai/Mistral-Small-24B-Instruct-2501", show_label=True, label="huggingface ID")
6
  button = gr.Button(value="get chat template")
7
+ output = gr.Textbox(lines=10.0, show_copy_button=True, visible=False)
8
 
9
+ @button.click(inputs=[huggingface], outputs=[output])
10
+ def submit(huggingface_id):
11
+ try:
12
+ template = AutoTokenizer.from_pretrained(huggingface_id).apply_chat_template(
13
+ [
14
+ {"role": "system", "content": "system-prompt"},
15
+ {"role": "user", "content": "user-prompt"},
16
+ {"role": "assistant", "content": "assistant-prompt"}
17
+ ],
18
+ tokenize=False
19
+ )
20
+ return gr.update(value=template, visible=True)
21
+ except:
22
+ raise gr.Error("Could not get chat template")
23
+ return gr.update(visible=False)
24
 
25
  demo.launch()