File size: 1,024 Bytes
0429e33
aeabc48
0429e33
 
aeabc48
0429e33
aeabc48
0429e33
aeabc48
 
 
 
 
 
 
 
 
 
 
 
6c117ab
 
aeabc48
0429e33
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import gradio as gr
from transformers import AutoTokenizer

with gr.Blocks() as demo:
    huggingface = gr.Textbox(value="mistralai/Mistral-Small-24B-Instruct-2501", show_label=True, label="huggingface ID")
    button = gr.Button(value="get chat template")
    output = gr.Textbox(lines=10.0, show_copy_button=True, visible=False)

    @button.click(inputs=[huggingface], outputs=[output])
    def submit(huggingface_id):
        try:
            template = AutoTokenizer.from_pretrained(huggingface_id).apply_chat_template(
                [
                    {"role": "system", "content": "system-prompt"},
                    {"role": "user", "content": "user-prompt"},
                    {"role": "assistant", "content": "assistant-prompt"}
                ],
                tokenize=False
            )
            return gr.update(value=template, visible=True)
        except Exception as err:
            raise gr.Error(f"Could not get chat template: {err}")
        return gr.update(visible=False)

demo.launch()