Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,52 +1,53 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import json
|
| 3 |
-
from collections import defaultdict
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
with open(file_path, "r") as f:
|
| 9 |
for line in f:
|
| 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 |
-
with gr.
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
import json
|
|
|
|
| 4 |
|
| 5 |
+
def load_data(path: str):
|
| 6 |
+
records = []
|
| 7 |
+
with open(path, "r", encoding="utf-8") as f:
|
|
|
|
| 8 |
for line in f:
|
| 9 |
+
obj = json.loads(line)
|
| 10 |
+
records.append({
|
| 11 |
+
"prompt": obj.get("Prompt", "").strip(),
|
| 12 |
+
"model": obj.get("model", "").strip(),
|
| 13 |
+
"response": obj.get("model response", "").strip()
|
| 14 |
+
})
|
| 15 |
+
return pd.DataFrame(records)
|
| 16 |
+
|
| 17 |
+
# Load once
|
| 18 |
+
df = load_data("all_10_responses.jsonl")
|
| 19 |
+
all_prompts = sorted(df["prompt"].unique().tolist())
|
| 20 |
+
all_models = sorted(df["model"].unique().tolist())
|
| 21 |
+
|
| 22 |
+
def get_model_responses(chosen_prompt, chosen_models):
|
| 23 |
+
subset = df[
|
| 24 |
+
(df["prompt"] == chosen_prompt) &
|
| 25 |
+
(df["model"].isin(chosen_models))
|
| 26 |
+
].sort_values("model")
|
| 27 |
+
# Return a list of tuples: [(model_name, response), …]
|
| 28 |
+
return [(row["model"], row["response"]) for _, row in subset.iterrows()]
|
| 29 |
+
|
| 30 |
+
with gr.Blocks() as demo:
|
| 31 |
+
gr.Markdown("# Model Responses Explorer")
|
| 32 |
+
|
| 33 |
+
with gr.Row():
|
| 34 |
+
prompt_dd = gr.Dropdown(all_prompts, label="Select a Prompt")
|
| 35 |
+
models_dd = gr.CheckboxGroup(all_models, value=all_models, label="Select Models")
|
| 36 |
+
|
| 37 |
+
with gr.Column():
|
| 38 |
+
output_acc = gr.Accordion(label="Responses", open=False)
|
| 39 |
+
|
| 40 |
+
def update_accordion(prompt, models):
|
| 41 |
+
items = get_model_responses(prompt, models)
|
| 42 |
+
# Gradio accordion expects a single gr.Column or gr.Text
|
| 43 |
+
# We’ll return a single Markdown string combining all models
|
| 44 |
+
md = ""
|
| 45 |
+
for m, r in items:
|
| 46 |
+
md += f"### {m}\n\n{r}\n---\n"
|
| 47 |
+
return md
|
| 48 |
+
|
| 49 |
+
accordion_text = gr.Markdown()
|
| 50 |
+
prompt_dd.change(fn=update_accordion, inputs=[prompt_dd, models_dd], outputs=accordion_text)
|
| 51 |
+
models_dd.change(fn=update_accordion, inputs=[prompt_dd, models_dd], outputs=accordion_text)
|
| 52 |
+
|
| 53 |
+
demo.launch()
|