Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import json
|
3 |
+
from collections import defaultdict
|
4 |
+
|
5 |
+
# Load and group data by prompt
|
6 |
+
def load_data(file_path):
|
7 |
+
prompt_dict = defaultdict(list)
|
8 |
+
with open(file_path, "r") as f:
|
9 |
+
for line in f:
|
10 |
+
row = json.loads(line)
|
11 |
+
prompt = row["prompt"]
|
12 |
+
model = row["model"]
|
13 |
+
response = row["model_response"]
|
14 |
+
prompt_dict[prompt].append((model, response))
|
15 |
+
return prompt_dict
|
16 |
+
|
17 |
+
DATA_PATH = "all_10_responses.jsonl"
|
18 |
+
prompt_to_responses = load_data(DATA_PATH)
|
19 |
+
prompt_list = sorted(prompt_to_responses.keys())
|
20 |
+
|
21 |
+
# Gradio interface
|
22 |
+
def display_responses(selected_prompt):
|
23 |
+
entries = prompt_to_responses[selected_prompt]
|
24 |
+
accordions = []
|
25 |
+
for model, response in sorted(entries):
|
26 |
+
with gr.Accordion(label=model, open=False):
|
27 |
+
gr.Markdown(f"""```text\n{response}\n```""")
|
28 |
+
return
|
29 |
+
|
30 |
+
with gr.Blocks(css=".gr-accordion .label {font-weight: bold}") as demo:
|
31 |
+
gr.Markdown("## 🔍 Prompt Viewer: Compare Model Responses")
|
32 |
+
selected_prompt = gr.Dropdown(choices=prompt_list, label="Select a Prompt", interactive=True)
|
33 |
+
|
34 |
+
with gr.Column() as output_column:
|
35 |
+
prompt_output = gr.Markdown()
|
36 |
+
response_group = gr.Group()
|
37 |
+
|
38 |
+
def update_output(prompt):
|
39 |
+
prompt_output.update(f"### Prompt\n```\n{prompt}\n```")
|
40 |
+
response_group.children.clear()
|
41 |
+
entries = prompt_to_responses[prompt]
|
42 |
+
for model, response in sorted(entries):
|
43 |
+
response_group.children.append(
|
44 |
+
gr.Accordion(label=model, open=False, children=[
|
45 |
+
gr.Markdown(f"""```text\n{response}\n```""")
|
46 |
+
])
|
47 |
+
)
|
48 |
+
|
49 |
+
selected_prompt.change(fn=update_output, inputs=[selected_prompt])
|
50 |
+
|
51 |
+
if __name__ == "__main__":
|
52 |
+
demo.launch()
|