Spaces:
Running
Running
File size: 11,108 Bytes
5bf5905 | 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | """Bring Image-to-Scene back as a second tab (user, 2026-10-04: "每一栏分两个小tab,默认是text2scene,然后另一个是image2scene").
Task Format, Leaderboard, the case cards and the takeaways each get a Text-to-Scene / Image-to-Scene tab pair, Text-to-Scene
selected. The Image-to-Scene content is the page's own from before scripts/t2s_only.py (commit c77f6d97b3): the task
example, bars, Pareto view, ranking, the two repair cases with their models, and the three editing takeaways. The
Text-to-Scene content, the Research Track naming and the kit-style charts stay as they are. There is no Overall tab.
Each step asserts it found what it edits, so a re-run on an already-edited page stops instead of half-applying.
python3 scripts/i2s_tabs.py
"""
from __future__ import annotations
import json, re, subprocess
from pathlib import Path
from bs4 import BeautifulSoup
ROOT = Path(__file__).resolve().parent.parent
BEFORE = "c77f6d97b3" # the last commit with Image-to-Scene on the page
V = "20261004i2s"
I2S_CASES = ("comp-31-old-industrial-pallet-bay-repair-v2", "comp-61-new-york-mailbox-pair-repair-v2")
HIDE = "display:none"
def one(found, what):
assert found, f"not found: {what}"
return found
def old(path):
return subprocess.run(["git", "show", f"{BEFORE}:{path}"], cwd=ROOT, check=True, capture_output=True, text=True).stdout
def frag(html):
return BeautifulSoup(html, "html.parser")
def tabs(section_id):
"""The leaderboard's tab pair; paper.js shows the [data-view] elements of the section that match the pressed button."""
return frag(f'<div class="lb-tabs"><div class="seg seg-lg" data-for="{section_id}">'
'<button class="on" data-view="t2s">Text-to-Scene</button>'
'<button data-view="i2s">Image-to-Scene</button></div></div>')
def view(el, v):
el["data-view"] = v
if v == "i2s":
el["style"] = HIDE
return el
def restore_files():
"""The media and packed models t2s_only.py deleted (the v30 teaser stays retired)."""
gone = subprocess.run(["git", "diff", "--name-only", "--diff-filter=D", BEFORE, "HEAD"], cwd=ROOT, check=True,
capture_output=True, text=True).stdout.split()
gone = [p for p in gone if p != "media/teaser.mp4"]
assert gone and all(p.startswith(("media/i2s/", "models/")) for p in gone), gone
missing = [p for p in gone if not (ROOT / p).exists()]
assert missing, "already restored"
subprocess.run(["git", "checkout", BEFORE, "--", *missing], cwd=ROOT, check=True)
print("restored", len(missing), "files")
def index():
p = ROOT / "index.html"
soup = BeautifulSoup(p.read_text(), "html.parser")
was = BeautifulSoup(old("index.html"), "html.parser")
assert not soup.find(id="task-i2s"), "already has Image-to-Scene"
# task format: the old tab bar and editing example; each tab carries its own case-count strip
tf = one(soup.find(id="task-format"), "task format")
t2s = one(tf.find(id="task-t2s"), "task-t2s")
bar = one(was.find(id="task-format").find(class_="task-tabs"), "old task tabs")
one(bar.find(id="task-tab-t2s"), "t2s tab").string = "Text-to-Scene"
one(bar.find(id="task-tab-i2s"), "i2s tab").string = "Image-to-Scene"
t2s.insert_before(bar)
i2s = one(was.find(id="task-i2s"), "old task-i2s")
i2s["hidden"] = ""
t2s.insert_after(i2s)
av = one(tf.find(class_="availability"), "availability strip")
t2s.append(av.extract())
i2s.append(frag('<div class="availability"><span><b>160</b> editing cases in the full benchmark target, including '
'private cases</span><span><b>72</b> public editing cases (22 indoor, 50 outdoor)</span></div>'))
# leaderboard: the header, bar title, Pareto subtitle and ranking each get an Image-to-Scene twin
lb = one(soup.find(id="leaderboard"), "leaderboard")
olb = one(was.find(id="leaderboard"), "old leaderboard")
desc = view(one(lb.find(class_="section-desc"), "leaderboard desc"), "t2s")
view(one(lb.find(class_="tracks-why"), "tracks why"), "t2s")
desc.insert_after(view(frag('<p class="section-desc">Image-to-Scene · 75 public cases (25 indoor, 50 outdoor) · '
'14 coding-agent configurations.</p>').p, "i2s"))
wrap = one(lb.find(id="lbwrap"), "lbwrap")
wrap.insert(0, tabs("leaderboard"))
q = one(lb.select_one(".bar-heading h3 span.q"), "bar qualifier")
view(q, "t2s"); q.insert_after(view(frag('<span class="q">Image-to-Scene</span>').span, "i2s"))
side = lb.select(".bar-heading > span"); assert len(side) == 1, side
s = side[0].get_text(strip=True); assert s == "20 scenes · score out of 100", s
side[0].clear()
side[0].append(view(frag(f"<span>{s}</span>").span, "t2s"))
side[0].append(view(frag("<span>75 scenes · score out of 100</span>").span, "i2s"))
for kind, find in (("bars", lambda r: r.find(class_="bar-scroll").find("div", attrs={"data-view": "i2s"}, recursive=False)),
("pareto", lambda r: r.find(class_="pareto-view", attrs={"data-view": "i2s"})),
("ranking", lambda r: r.find(class_="ranking-card").find("div", attrs={"data-view": "i2s"}, recursive=False))):
new_ = one(find(olb), f"old i2s {kind}")
t2s_ = one({"bars": lambda r: r.find(class_="bar-scroll").find("div", attrs={"data-view": "t2s"}, recursive=False),
"pareto": lambda r: r.find(class_="pareto-view", attrs={"data-view": "t2s"}),
"ranking": lambda r: r.find(class_="ranking-card").find("div", attrs={"data-view": "t2s"}, recursive=False)}[kind](lb),
f"t2s {kind}")
t2s_.insert_after(view(new_, "i2s"))
sub = one(lb.find(class_="figure-subtitle"), "pareto subtitle")
view(sub, "t2s")
sub.insert_after(view(frag('<p class="figure-subtitle">Quality against the cost of one case · Image-to-Scene, '
'75 public cases</p>').p, "i2s"))
# cases: the four construction cards, or the two repairs with their input/ground-truth switch
cs = one(soup.find(id="cases"), "cases")
grid = view(one(cs.find(class_="case-grid"), "case grid"), "t2s")
cards = []
for c in I2S_CASES:
scene = one(was.find(id="cases").find(attrs={"data-case": c}), c)
cards.append(one(scene.find_parent("article", class_="case-card"), f"{c} card"))
i2s_grid = view(frag('<div class="case-grid"></div>').div, "i2s")
for c in cards:
i2s_grid.append(c)
grid.insert_after(i2s_grid)
cdesc = one(cs.find(class_="section-desc"), "cases desc")
view(cdesc, "t2s")
cdesc.insert_after(view(frag('<p class="section-desc">Drag any scene to inspect the saved 3D output. Switch each repair '
'between the saved scene, its corrupted input and the ground truth, or open a case to '
'explore every agent.</p>').p, "i2s"))
grid.insert_before(tabs("cases"))
# takeaways: Spatial Composition, or the three editing takeaways (the construction-vs-editing one first)
tk = one(soup.find(id="takeaways"), "takeaways")
t2s_card = view(one(tk.find(class_="tk"), "t2s takeaway"), "t2s")
old_cards = [c for c in was.find(id="takeaways").find_all(class_="tk")
if not " ".join(c.find("h3").get_text(" ").split()).startswith("Spatial Composition remains")]
assert len(old_cards) == 3, len(old_cards)
at = t2s_card
for k, c in enumerate(old_cards, 1):
for n in c.find_all(class_="n"):
n.string = f"Takeaway {k}"
at.insert_after(view(c, "i2s")); at = c
t2s_card.insert_before(tabs("takeaways"))
for h in tk.find_all("h2"):
if h.get_text(strip=True) == "Takeaway":
h.string = "Takeaways"
for a in soup.find_all("a"):
if a.get_text(strip=True) == "Takeaway":
a.string = "Takeaways"
# cache keys for what this edit changes
for t in soup.find_all(["script", "link"]):
a = "src" if t.name == "script" else "href"
u = t.get(a) or ""
if re.match(r"(assets/(buildingbench\.css|leaderboard-bars\.js|pareto\.js)|data/site\.js)", u):
t[a] = re.sub(r"\?v=.*$", "", u) + f"?v={V}"
p.write_text(str(soup))
print("index.html: Text-to-Scene / Image-to-Scene tabs in task format, leaderboard, cases and takeaways")
def bars():
p = ROOT / "assets/leaderboard-bars.js"; s = p.read_text()
m = one(re.search(r"const ALL = (\{.*?\});\n", s, re.S), "const ALL")
data = json.loads(m.group(1)); assert list(data) == ["t2s"], list(data)
data["i2s"] = json.loads(re.search(r"const ALL = (\{.*?\});\n", old("assets/leaderboard-bars.js"), re.S).group(1))["i2s"]
p.write_text(s[:m.start(1)] + json.dumps(data) + s[m.end(1):])
print("leaderboard-bars.js: views", list(data))
def pareto():
p = ROOT / "assets/pareto.js"; s = p.read_text()
a = "'Text-to-Scene Score');"; assert s.count(a) == 1, "pareto axis title"
s = s.replace(a, "{t2s:'Text-to-Scene Score',i2s:'Image-to-Scene Score'}[svg.dataset.mode]);")
p.write_text(s); print("pareto.js: axis title per view")
def site_data():
p = ROOT / "data/site.js"
S = json.loads(p.read_text().split("=", 1)[1].rstrip().rstrip(";"))
assert all(c["track"] == "t2s" for c in S["cases"]), "already has Image-to-Scene cases"
was = json.loads(old("data/site.js").split("=", 1)[1].rstrip().rstrip(";"))
add = [c for c in was["cases"] if c["track"] == "i2s"]
assert [c["id"] for c in add] == list(I2S_CASES), [c["id"] for c in add]
S["cases"] += add
p.write_text("window.SITE = " + json.dumps(S) + ";\n")
n3d = sum(1 for c in S["cases"] for a in c["agents"] if a.get("glb")) + sum(1 for c in S["cases"] for k in ("gt_glb", "input_glb") if c.get(k))
cp = ROOT / "cases.html"; cs = cp.read_text()
cs, n = re.subn(r"\d+ cases, \d+ scenes in 3D", f'{len(S["cases"])} cases, {n3d} scenes in 3D', cs); assert n == 1
cs, n = re.subn(r"(data/site\.js|assets/buildingbench\.css)\?v=\w+", lambda m: f"{m.group(1)}?v={V}", cs); assert n == 2, n
cp.write_text(cs)
print("data/site.js: cases", len(S["cases"]), "· cases.html:", n3d, "scenes in 3D")
def progressive():
p = ROOT / "data/progressive-scenes.json"
d = json.loads(p.read_text()); n0 = len(d)
was = json.loads(old("data/progressive-scenes.json"))
add = {k: v for k, v in was.items() if k not in d}
i2s_models = {f.rsplit("/", 1)[1] for f in subprocess.run(["git", "diff", "--name-only", "--diff-filter=D", BEFORE, "HEAD", "--", "models/*.bin"],
cwd=ROOT, check=True, capture_output=True, text=True).stdout.split()}
assert add and set(add) <= i2s_models, sorted(add) # 6 of the 12 Image-to-Scene models are progressive
d.update(add)
p.write_text(json.dumps(d, indent=2) + "\n")
print("data/progressive-scenes.json:", n0, "->", len(d))
if __name__ == "__main__":
restore_files(); index(); bars(); pareto(); site_data(); progressive()
|