Spaces:
Runtime error
Runtime error
Matt
commited on
Commit
·
c6e51bd
1
Parent(s):
21346d9
Move to Blocks
Browse files
app.py
CHANGED
|
@@ -18,7 +18,9 @@ default_template = """{% for message in messages %}
|
|
| 18 |
{{ "<|im_start|>assistant\\n" }}
|
| 19 |
{% endif %}"""
|
| 20 |
|
| 21 |
-
description_text = """
|
|
|
|
|
|
|
| 22 |
|
| 23 |
### When you're happy with the outputs from your template, you can use the code block at the end to add it to a PR!"""
|
| 24 |
|
|
@@ -38,18 +40,39 @@ def apply_chat_template(template, test_conversation, add_generation_prompt, clea
|
|
| 38 |
formatted = tokenizer.apply_chat_template(conversation, tokenize=False, add_generation_prompt=add_generation_prompt)
|
| 39 |
return formatted, pr_snippet
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
gr.
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
gr.
|
| 53 |
-
|
| 54 |
-
)
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
{{ "<|im_start|>assistant\\n" }}
|
| 19 |
{% endif %}"""
|
| 20 |
|
| 21 |
+
description_text = """# Chat Template Creator
|
| 22 |
+
|
| 23 |
+
### This space is a helper app for writing [Chat Templates](https://huggingface.co/docs/transformers/main/en/chat_templating).
|
| 24 |
|
| 25 |
### When you're happy with the outputs from your template, you can use the code block at the end to add it to a PR!"""
|
| 26 |
|
|
|
|
| 40 |
formatted = tokenizer.apply_chat_template(conversation, tokenize=False, add_generation_prompt=add_generation_prompt)
|
| 41 |
return formatted, pr_snippet
|
| 42 |
|
| 43 |
+
with gr.Blocks():
|
| 44 |
+
|
| 45 |
+
gr.MarkDown(description_text)
|
| 46 |
+
|
| 47 |
+
with gr.Row():
|
| 48 |
+
with gr.Column():
|
| 49 |
+
template_in = gr.TextArea(value=default_template, lines=10, max_lines=30, label="Chat Template")
|
| 50 |
+
conversation_in = gr.TextArea(value=demo_conversation, lines=6, label="Conversation")
|
| 51 |
+
generation_prompt_check = gr.Checkbox(value=False, label="Add generation prompt")
|
| 52 |
+
cleanup_whitespace_check = gr.Checkbox(value=True, label="Cleanup template whitespace")
|
| 53 |
+
submit = gr.Button("Apply template")
|
| 54 |
+
with gr.Column():
|
| 55 |
+
formatted_out = gr.TextArea(label="Formatted conversation")
|
| 56 |
+
code_snippet_out = gr.TextArea(label="Code snippet to create PR", lines=3, show_label=True, show_copy_button=True)
|
| 57 |
+
btn.click(fn=apply_chat_template,
|
| 58 |
+
inputs=(template_in, conversation_in, generation_prompt_check, cleanup_whitespace_check),
|
| 59 |
+
outputs=(formatted_out, code_snippet_out
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
demo.launch()
|
| 63 |
+
|
| 64 |
+
#iface = gr.Interface(
|
| 65 |
+
# description=description_text,
|
| 66 |
+
# fn=apply_chat_template,
|
| 67 |
+
# inputs=[
|
| 68 |
+
# gr.TextArea(value=default_template, lines=10, max_lines=30, label="Chat Template"),
|
| 69 |
+
# gr.TextArea(value=demo_conversation, lines=6, label="Conversation"),
|
| 70 |
+
# gr.Checkbox(value=False, label="Add generation prompt"),
|
| 71 |
+
# gr.Checkbox(value=True, label="Cleanup template whitespace"),
|
| 72 |
+
# ],
|
| 73 |
+
# outputs=[
|
| 74 |
+
# gr.TextArea(label="Formatted conversation"),
|
| 75 |
+
# gr.TextArea(label="Code snippet to create PR", lines=3, show_label=True, show_copy_button=True)
|
| 76 |
+
# ]
|
| 77 |
+
#)
|
| 78 |
+
#iface.launch()
|