File size: 2,471 Bytes
448d6a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Finalize: upload reproduction bundle as an HF Dataset, register the trackio
artifact (so publish rewrites the Conclusion cell to a bucket URL), and add both
the dataset and the logbook Space to the collection."""
import os, sys, glob
from huggingface_hub import HfApi, upload_folder, create_repo, whoami, add_collection_item

BASE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(BASE, "src"))
ME = whoami()["name"]
DATASET = f"{ME}/mindflow-repro-bundle"
COLLECTION = os.environ.get("MINDFLOW_COLLECTION", "")  # slug
SPACE = f"{ME}/repro-mindflow-mind-supernet-powered-thinking-flows-for-research-idea-innovation"

IGNORE = ["llm_cache/*", "**/__pycache__/*", ".trackio/*", "tools/posterly/*", "or_*.json",
          "chal_*.json", "*.pyc", "paper.pdf", "outputs/poster/_poster_full.html", "or_notes.json"]

def upload_dataset():
    create_repo(DATASET, repo_type="dataset", exist_ok=True)
    upload_folder(folder_path=BASE, repo_id=DATASET, repo_type="dataset",
                  ignore_patterns=IGNORE, commit_message="MindFlow reproduction bundle")
    print("dataset:", f"https://huggingface.co/datasets/{DATASET}", flush=True)

def register_artifact():
    import trackio
    # register from within the logbook workspace so publish uploads it to the bucket
    os.chdir(BASE)
    try:
        trackio.init(project="repro-mindflow-mind-supernet-powered-thinking-flows-for-research-idea-innovation")
    except Exception as e:
        print("trackio.init note:", str(e)[:120], flush=True)
    art = trackio.log_artifact(BASE, name="repro-bundle", type="dataset")
    print("registered artifact:", getattr(art, "name", art), flush=True)
    try:
        trackio.finish()
    except Exception:
        pass

def add_to_collection():
    if not COLLECTION:
        print("no collection slug set", flush=True); return
    for item_id, item_type in [(DATASET, "dataset"), (SPACE, "space")]:
        try:
            add_collection_item(COLLECTION, item_id=item_id, item_type=item_type, exists_ok=True)
            print("added to collection:", item_id, flush=True)
        except Exception as e:
            print("collection add note:", item_id, str(e)[:120], flush=True)

if __name__ == "__main__":
    what = sys.argv[1:] or ["dataset", "collection"]
    if "dataset" in what: upload_dataset()
    if "artifact" in what: register_artifact()
    if "collection" in what: add_to_collection()
    print("finalize done.")