update
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from datasets import load_dataset
|
3 |
+
from typing import List,Dict
|
4 |
+
from gradio import ChatMessage
|
5 |
+
|
6 |
+
DATASETS_LIST = [("Self-GRIT/tuluv2-expanded-150k-part_v0-chat-format-syn-knowledge","part_v0")]
|
7 |
+
DATASETS = {f"{name}: {split}":load_dataset(name,split = split) for name,split in DATASETS_LIST}
|
8 |
+
KEY_MESSAGES_ORIGINAL = "messages_original"
|
9 |
+
KEY_MESSAGES_AUGMENTED = "messages_augmented"
|
10 |
+
|
11 |
+
def return_conversation_chat_message(history: List[Dict]):
|
12 |
+
conversation = []
|
13 |
+
for message in history:
|
14 |
+
conversation.append(ChatMessage(role = message["role"],content = message["content"]))
|
15 |
+
return conversation
|
16 |
+
|
17 |
+
def update_chatbot(value,dataset_name):
|
18 |
+
example = DATASETS[dataset_name][int(value)]
|
19 |
+
oring_chat_history = return_conversation_chat_message(example[KEY_MESSAGES_ORIGINAL])
|
20 |
+
augmented_chat_history = return_conversation_chat_message(example[KEY_MESSAGES_AUGMENTED])
|
21 |
+
return oring_chat_history,augmented_chat_history
|
22 |
+
|
23 |
+
with gr.Blocks() as demo:
|
24 |
+
with gr.Group():
|
25 |
+
with gr.Row():
|
26 |
+
with gr.Column():
|
27 |
+
dropdown = gr.Dropdown(DATASETS.keys(), label="Select the dataset")
|
28 |
+
with gr.Column():
|
29 |
+
slider = gr.Slider(minimum=0, maximum=100, step=1, label="Select the example")
|
30 |
+
with gr.Group():
|
31 |
+
with gr.Row():
|
32 |
+
gr.Markdown("Original Chat")
|
33 |
+
with gr.Row():
|
34 |
+
chatbot_original = gr.Chatbot(type = "messages")
|
35 |
+
with gr.Group():
|
36 |
+
with gr.Row():
|
37 |
+
gr.Markdown("Augmented Chat")
|
38 |
+
with gr.Row():
|
39 |
+
chatbot_augmented = gr.Chatbot(type = "messages")
|
40 |
+
slider.change(fn=update_chatbot, inputs=[slider,dropdown], outputs=[chatbot_original,chatbot_augmented])
|
41 |
+
demo.launch()
|