File size: 1,276 Bytes
0610fc9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Score a simple baseline on a few PlotTwin-Bench tasks.

Every task gives a reference figure and a target CSV. A method writes one plotting
script per task, `<id>.py`, that reads the target data from `data.csv` and saves one
PNG. This example writes a default-style pandas plot for the first three tasks and
scores it:

    cd scorer
    export OPENAI_API_KEY=...              # plus OPENAI_BASE_URL for a compatible endpoint
    uv run python examples/quickstart.py
"""

from pathlib import Path

from datasets import load_dataset

from plottwin_scorer.cli import main as plottwin_score

BASELINE = '''\
import matplotlib.pyplot as plt
import pandas as pd

df = pd.read_csv("data.csv")
df.select_dtypes("number").iloc[:, :3].plot(figsize=(6, 4))
plt.tight_layout()
plt.savefig("figure.png", dpi=150)
'''

bench = load_dataset("figmirror/PlotTwin-Bench", split="test")
pred_dir = Path("quickstart_preds")
pred_dir.mkdir(exist_ok=True)
for row in bench.select(range(3)):
    # A real method reads row["reference_image"] and row["target_data"] here.
    (pred_dir / f"{row['id']}.py").write_text(BASELINE)

# Same as: uv run plottwin-score --pred-dir quickstart_preds --out-dir quickstart_scores
plottwin_score(["--pred-dir", str(pred_dir), "--out-dir", "quickstart_scores"])