Matt commited on
Commit
3d8b295
1 Parent(s): 4b56865
Files changed (2) hide show
  1. app.py +25 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer
3
+
4
+ tokenizer = AutoTokenizer.from_pretrained("HuggingFaceH4/zephyr-7b-beta")
5
+
6
+ demo_conversation1 = [
7
+ {"role": "user", "content": "Hi there!"},
8
+ {"role": "assistant", "content": "Hello, human!"}
9
+ ]
10
+
11
+ demo_conversation2 = [
12
+ {"role": "system", "content": "You are a helpful chatbot."},
13
+ {"role": "user", "content": "Hi there!"}
14
+ ]
15
+
16
+ conversations = [demo_conversation1, demo_conversation2]
17
+
18
+ def apply_chat_template(template):
19
+ tokenizer.chat_template = template
20
+ without_gen = tokenizer.apply_chat_template(conversation, tokenize=False)
21
+ with_gen = tokenizer.apply_chat_template(conversation, tokenize=False, add_generation_prompt=True)
22
+ return f"Without generation prompt:\n\n{without_gen}\n\nWith generation prompt:\n\n{with_gen}"
23
+
24
+ iface = gr.Interface(fn=apply_chat_template, inputs="text", outputs="text")
25
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ transformers