File size: 3,967 Bytes
cfde47c | 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 | """
eden_upload_fast.py β Uploads READMEs, CSVs, and .py scripts to Hugging Face.
No .pth weights (those are uploaded separately due to size).
"""
from huggingface_hub import HfApi, create_repo, upload_file
import os, glob
TOKEN = os.environ.get("HF_TOKEN", "")
USER = "Shanmuk4622"
BASE = os.path.dirname(os.path.abspath(__file__))
api = HfApi(token=TOKEN)
print(f"Logged in as: {api.whoami()['name']}\n")
# ββ helpers ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def safe_upload(local_path, repo_id, repo_filename):
try:
upload_file(
path_or_fileobj=local_path,
path_in_repo=repo_filename,
repo_id=repo_id,
token=TOKEN,
repo_type="model",
)
print(f" β {repo_filename} β {repo_id}")
except Exception as e:
print(f" β {repo_filename} β {repo_id} | {e}")
def parse_arch_ds(fn):
fn = fn.lower().replace("\\", "/")
ds = "unknown"
arch = "unknown"
if "cifar100" in fn: ds = "CIFAR-100"
elif "cifar10" in fn: ds = "CIFAR-10"
elif "imagenet" in fn: ds = "Custom-ImageNet300"
if "efficientnet" in fn: arch = "EfficientNetV2"
elif "convnext" in fn: arch = "ConvNeXtV2"
elif "mobilevit" in fn: arch = "MobileViTv3"
elif "resnet50" in fn: arch = "ResNet50"
elif "resnet18" in fn: arch = "ResNet18"
elif "vgg16" in fn: arch = "VGG16"
elif "alexnet" in fn: arch = "AlexNet"
elif "inception" in fn: arch = "InceptionV3"
elif "densenet" in fn: arch = "DenseNet121"
elif "unet" in fn: arch = "UNet"
return arch, ds
# ββ STEP 1 : Core-Scripts repo βββββββββββββββββββββββββββββββββββββββββββββββββ
print("="*60)
print("STEP 1 β EDEN-Core-Scripts (README + .py scripts)")
print("="*60)
core_repo = f"{USER}/EDEN-Core-Scripts"
create_repo(core_repo, token=TOKEN, repo_type="model", exist_ok=True, private=False)
# README
safe_upload(
os.path.join(BASE, "hf_readmes", "EDEN-Core-Scripts_README.md"),
core_repo, "README.md"
)
# All algorithm .py scripts
for py in sorted(glob.glob(os.path.join(BASE, "**", "*.py"), recursive=True)):
rel = os.path.relpath(py, BASE)
if any(k in rel for k in ["Algo_", "eden_", "mobilevit_model"]):
safe_upload(py, core_repo, rel.replace(os.sep, "/"))
# ββ STEP 2 : Per-model READMEs ββββββββββββββββββββββββββββββββββββββββββββββββ
print("\n" + "="*60)
print("STEP 2 β Per-model repo READMEs")
print("="*60)
for rf in sorted(glob.glob(os.path.join(BASE, "hf_readmes", "EDEN-*_README.md"))):
repo_name = os.path.basename(rf).replace("_README.md", "")
repo_id = f"{USER}/{repo_name}"
create_repo(repo_id, token=TOKEN, repo_type="model", exist_ok=True, private=False)
safe_upload(rf, repo_id, "README.md")
# ββ STEP 3 : CSV training logs ββββββββββββββββββββββββββββββββββββββββββββββββ
print("\n" + "="*60)
print("STEP 3 β CSV training logs")
print("="*60)
for csv in sorted(glob.glob(os.path.join(BASE, "**", "*.csv"), recursive=True)):
# skip the aggregated helper CSVs
if any(skip in csv for skip in ["green_ai_", "experiment_summary", "repository"]):
continue
arch, ds = parse_arch_ds(csv)
if arch == "unknown" or ds == "unknown":
continue
repo_id = f"{USER}/EDEN-{arch}-{ds.replace(' ', '-')}"
safe_upload(csv, repo_id, os.path.basename(csv))
print("\n" + "="*60)
print("ALL DONE β Check https://huggingface.co/Shanmuk4622")
print("="*60)
|