File size: 901 Bytes
3d8b295
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
import gradio as gr
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("HuggingFaceH4/zephyr-7b-beta")

demo_conversation1 = [
    {"role": "user", "content": "Hi there!"},
    {"role": "assistant", "content": "Hello, human!"}
]

demo_conversation2 = [
    {"role": "system", "content": "You are a helpful chatbot."},
    {"role": "user", "content": "Hi there!"}
]

conversations = [demo_conversation1, demo_conversation2]

def apply_chat_template(template):
    tokenizer.chat_template = template
    without_gen = tokenizer.apply_chat_template(conversation, tokenize=False)
    with_gen = tokenizer.apply_chat_template(conversation, tokenize=False, add_generation_prompt=True)
    return f"Without generation prompt:\n\n{without_gen}\n\nWith generation prompt:\n\n{with_gen}"

iface = gr.Interface(fn=apply_chat_template, inputs="text", outputs="text")
iface.launch()