HEL-892: add source-bound VOSR2 image reference documentation
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
"""Bounded exact source text; no installation or execution of upstream code."""
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from pathlib import Path
|
||||
|
||||
REF = Path(__file__).resolve().parent.parent / "vosr2-reference"
|
||||
SPECS = {
|
||||
"vosr": ("ylchen333/ComfyUI-VOSR2", "c9450b611e6b0e854212b81fecde2da5d088c1bc", None),
|
||||
"core": ("Comfy-Org/ComfyUI", None, "v0.35.1"),
|
||||
"frontend": ("Comfy-Org/ComfyUI_frontend", None, "v1.51.9"),
|
||||
"rgthree": ("rgthree/rgthree-comfy", "2c5342a8cb0eaecaabf61435a5f37dd594c510ba", None),
|
||||
"vhs": (
|
||||
"Kosinkadink/ComfyUI-VideoHelperSuite",
|
||||
"4d907bee61e92c2e65af3bd6383a4e4d356126d1",
|
||||
None,
|
||||
),
|
||||
"guhai": ("goohai/Goohaitools-comfyui", "4e11bd3b8471102eef1cadd809c79c94dc8001ee", None),
|
||||
}
|
||||
|
||||
|
||||
def get(url):
|
||||
with urllib.request.urlopen(url, timeout=45) as r:
|
||||
b = r.read(3000001)
|
||||
assert len(b) < 3000000
|
||||
return b
|
||||
|
||||
|
||||
def metadata(item):
|
||||
key, (repo, commit, tag) = item
|
||||
if tag:
|
||||
raw = get(f"https://api.github.com/repos/{repo}/git/ref/tags/{tag}")
|
||||
(REF / f"{key}-tag.json").write_bytes(raw)
|
||||
obj = json.loads(raw)["object"]
|
||||
if obj["type"] == "tag":
|
||||
raw = get(obj["url"])
|
||||
(REF / f"{key}-tag-object.json").write_bytes(raw)
|
||||
obj = json.loads(raw)["object"]
|
||||
assert obj["type"] == "commit"
|
||||
commit = obj["sha"]
|
||||
raw = get(f"https://api.github.com/repos/{repo}/git/trees/{commit}?recursive=1")
|
||||
(REF / f"{key}-tree.json").write_bytes(raw)
|
||||
tree = json.loads(raw)
|
||||
assert not tree["truncated"] and tree["sha"] == commit
|
||||
assert commit == PINS[key]
|
||||
return key, repo, commit, tree
|
||||
|
||||
|
||||
def main():
|
||||
with ThreadPoolExecutor(max_workers=4) as pool:
|
||||
rows = list(pool.map(metadata, SPECS.items()))
|
||||
(REF / "identities.json").write_text(
|
||||
json.dumps([{"id": k, "repo": r, "commit": c} for k, r, c, t in rows], indent=2) + "\n"
|
||||
)
|
||||
for key, repo, commit, tree in rows:
|
||||
print(key, commit, "exact tree entries", len(tree["tree"]), flush=True)
|
||||
|
||||
|
||||
FILES = {
|
||||
"vosr": [
|
||||
"__init__.py",
|
||||
"nodes_vosr.py",
|
||||
"loader.py",
|
||||
"inference.py",
|
||||
"color.py",
|
||||
"tiled_vae.py",
|
||||
"LICENSE",
|
||||
],
|
||||
"core": [
|
||||
"nodes.py",
|
||||
"comfy_extras/nodes_images.py",
|
||||
"comfy_api/latest/_io.py",
|
||||
"folder_paths.py",
|
||||
"LICENSE",
|
||||
],
|
||||
"frontend": [
|
||||
"src/scripts/widgets.ts",
|
||||
"src/scripts/valueControl.ts",
|
||||
"src/extensions/core/uploadImage.ts",
|
||||
"src/lib/litegraph/src/LGraphNode.ts",
|
||||
"LICENSE",
|
||||
],
|
||||
"rgthree": [
|
||||
"__init__.py",
|
||||
"py/image_comparer.py",
|
||||
"py/constants.py",
|
||||
"web/comfyui/image_comparer.js",
|
||||
"LICENSE",
|
||||
],
|
||||
"vhs": [
|
||||
"__init__.py",
|
||||
"videohelpersuite/nodes.py",
|
||||
"videohelpersuite/load_video_nodes.py",
|
||||
"videohelpersuite/utils.py",
|
||||
"video_formats/h264-mp4.json",
|
||||
"web/js/VHS.core.js",
|
||||
"LICENSE",
|
||||
],
|
||||
"guhai": ["__init__.py", "nodes/忽略多组.py", "web/js/nodes pass.js", "README.md"],
|
||||
}
|
||||
|
||||
|
||||
def fetch_texts():
|
||||
identities = json.loads((REF / "identities.json").read_bytes())
|
||||
entries = []
|
||||
|
||||
def fetch(job):
|
||||
row, p, blob = job
|
||||
key = row["id"]
|
||||
commit = row["commit"]
|
||||
url = f"https://raw.githubusercontent.com/{row['repo']}/{commit}/{p}"
|
||||
name = key + "__" + p.replace("/", "__")
|
||||
cached = REF / name
|
||||
b = cached.read_bytes() if cached.exists() else get(urllib.parse.quote(url, safe=":/"))
|
||||
actual = hashlib.sha1(b"blob " + str(len(b)).encode() + b"\0" + b).hexdigest()
|
||||
assert actual == blob
|
||||
name = key + "__" + p.replace("/", "__")
|
||||
(REF / name).write_bytes(b)
|
||||
return dict(
|
||||
id=key,
|
||||
file=p,
|
||||
local_file=name,
|
||||
url=url,
|
||||
commit=commit,
|
||||
sha256=hashlib.sha256(b).hexdigest(),
|
||||
git_blob_sha1=blob,
|
||||
)
|
||||
|
||||
jobs = []
|
||||
for row in identities:
|
||||
paths = {
|
||||
e["path"]: e["sha"]
|
||||
for e in json.loads((REF / (row["id"] + "-tree.json")).read_bytes())["tree"]
|
||||
if e["type"] == "blob"
|
||||
}
|
||||
for p in FILES[row["id"]]:
|
||||
if p in paths:
|
||||
jobs.append((row, p, paths[p]))
|
||||
else:
|
||||
print("MISSING", row["id"], p, flush=True)
|
||||
with ThreadPoolExecutor(max_workers=5) as pool:
|
||||
entries = list(pool.map(fetch, jobs))
|
||||
(REF / "sources.json").write_text(json.dumps(dict(sources=entries), indent=2) + "\n")
|
||||
print("Fetched", len(entries), "bounded texts")
|
||||
|
||||
|
||||
PINS = {
|
||||
"vosr": "c9450b611e6b0e854212b81fecde2da5d088c1bc",
|
||||
"core": "856a922befab9d94cb66f36a3dce17234d7a6e31",
|
||||
"frontend": "71d2f2f2b5c6da9dee281836b5b72f3af368966f",
|
||||
"rgthree": "2c5342a8cb0eaecaabf61435a5f37dd594c510ba",
|
||||
"vhs": "4d907bee61e92c2e65af3bd6383a4e4d356126d1",
|
||||
"guhai": "4e11bd3b8471102eef1cadd809c79c94dc8001ee",
|
||||
}
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
fetch_texts()
|
||||
Reference in New Issue
Block a user