File size: 1,782 Bytes
7824c63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import gradio as gr
import json
from collections import defaultdict

# Load and group data by prompt
def load_data(file_path):
    prompt_dict = defaultdict(list)
    with open(file_path, "r") as f:
        for line in f:
            row = json.loads(line)
            prompt = row["prompt"]
            model = row["model"]
            response = row["model_response"]
            prompt_dict[prompt].append((model, response))
    return prompt_dict

DATA_PATH = "all_10_responses.jsonl"
prompt_to_responses = load_data(DATA_PATH)
prompt_list = sorted(prompt_to_responses.keys())

# Gradio interface
def display_responses(selected_prompt):
    entries = prompt_to_responses[selected_prompt]
    accordions = []
    for model, response in sorted(entries):
        with gr.Accordion(label=model, open=False):
            gr.Markdown(f"""```text\n{response}\n```""")
    return

with gr.Blocks(css=".gr-accordion .label {font-weight: bold}") as demo:
    gr.Markdown("## 🔍 Prompt Viewer: Compare Model Responses")
    selected_prompt = gr.Dropdown(choices=prompt_list, label="Select a Prompt", interactive=True)

    with gr.Column() as output_column:
        prompt_output = gr.Markdown()
        response_group = gr.Group()

    def update_output(prompt):
        prompt_output.update(f"### Prompt\n```\n{prompt}\n```")
        response_group.children.clear()
        entries = prompt_to_responses[prompt]
        for model, response in sorted(entries):
            response_group.children.append(
                gr.Accordion(label=model, open=False, children=[
                    gr.Markdown(f"""```text\n{response}\n```""")
                ])
            )

    selected_prompt.change(fn=update_output, inputs=[selected_prompt])

if __name__ == "__main__":
    demo.launch()