|
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() |