Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,25 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
with gr.Blocks() as demo:
|
4 |
-
huggingface = gr.Textbox(
|
5 |
button = gr.Button(value="get chat template")
|
6 |
-
|
7 |
|
8 |
-
@button.click(inputs=[
|
9 |
-
def
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer
|
3 |
|
4 |
with gr.Blocks() as demo:
|
5 |
+
huggingface = gr.Textbox(value="mistralai/Mistral-Small-24B-Instruct-2501", show_label=True, label="huggingface ID")
|
6 |
button = gr.Button(value="get chat template")
|
7 |
+
output = gr.Textbox(lines=10.0, show_copy_button=True, visible=False)
|
8 |
|
9 |
+
@button.click(inputs=[huggingface], outputs=[output])
|
10 |
+
def submit(huggingface_id):
|
11 |
+
try:
|
12 |
+
template = AutoTokenizer.from_pretrained(huggingface_id).apply_chat_template(
|
13 |
+
[
|
14 |
+
{"role": "system", "content": "system-prompt"},
|
15 |
+
{"role": "user", "content": "user-prompt"},
|
16 |
+
{"role": "assistant", "content": "assistant-prompt"}
|
17 |
+
],
|
18 |
+
tokenize=False
|
19 |
+
)
|
20 |
+
return gr.update(value=template, visible=True)
|
21 |
+
except:
|
22 |
+
raise gr.Error("Could not get chat template")
|
23 |
+
return gr.update(visible=False)
|
24 |
|
25 |
demo.launch()
|