Upload eden_upload_fast.py with huggingface_hub
Browse files- eden_upload_fast.py +96 -0
eden_upload_fast.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
eden_upload_fast.py β Uploads READMEs, CSVs, and .py scripts to Hugging Face.
|
| 3 |
+
No .pth weights (those are uploaded separately due to size).
|
| 4 |
+
"""
|
| 5 |
+
from huggingface_hub import HfApi, create_repo, upload_file
|
| 6 |
+
import os, glob
|
| 7 |
+
|
| 8 |
+
TOKEN = os.environ.get("HF_TOKEN", "")
|
| 9 |
+
USER = "Shanmuk4622"
|
| 10 |
+
BASE = os.path.dirname(os.path.abspath(__file__))
|
| 11 |
+
|
| 12 |
+
api = HfApi(token=TOKEN)
|
| 13 |
+
print(f"Logged in as: {api.whoami()['name']}\n")
|
| 14 |
+
|
| 15 |
+
# ββ helpers ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 16 |
+
def safe_upload(local_path, repo_id, repo_filename):
|
| 17 |
+
try:
|
| 18 |
+
upload_file(
|
| 19 |
+
path_or_fileobj=local_path,
|
| 20 |
+
path_in_repo=repo_filename,
|
| 21 |
+
repo_id=repo_id,
|
| 22 |
+
token=TOKEN,
|
| 23 |
+
repo_type="model",
|
| 24 |
+
)
|
| 25 |
+
print(f" β {repo_filename} β {repo_id}")
|
| 26 |
+
except Exception as e:
|
| 27 |
+
print(f" β {repo_filename} β {repo_id} | {e}")
|
| 28 |
+
|
| 29 |
+
def parse_arch_ds(fn):
|
| 30 |
+
fn = fn.lower().replace("\\", "/")
|
| 31 |
+
ds = "unknown"
|
| 32 |
+
arch = "unknown"
|
| 33 |
+
if "cifar100" in fn: ds = "CIFAR-100"
|
| 34 |
+
elif "cifar10" in fn: ds = "CIFAR-10"
|
| 35 |
+
elif "imagenet" in fn: ds = "Custom-ImageNet300"
|
| 36 |
+
if "efficientnet" in fn: arch = "EfficientNetV2"
|
| 37 |
+
elif "convnext" in fn: arch = "ConvNeXtV2"
|
| 38 |
+
elif "mobilevit" in fn: arch = "MobileViTv3"
|
| 39 |
+
elif "resnet50" in fn: arch = "ResNet50"
|
| 40 |
+
elif "resnet18" in fn: arch = "ResNet18"
|
| 41 |
+
elif "vgg16" in fn: arch = "VGG16"
|
| 42 |
+
elif "alexnet" in fn: arch = "AlexNet"
|
| 43 |
+
elif "inception" in fn: arch = "InceptionV3"
|
| 44 |
+
elif "densenet" in fn: arch = "DenseNet121"
|
| 45 |
+
elif "unet" in fn: arch = "UNet"
|
| 46 |
+
return arch, ds
|
| 47 |
+
|
| 48 |
+
# ββ STEP 1 : Core-Scripts repo βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 49 |
+
print("="*60)
|
| 50 |
+
print("STEP 1 β EDEN-Core-Scripts (README + .py scripts)")
|
| 51 |
+
print("="*60)
|
| 52 |
+
|
| 53 |
+
core_repo = f"{USER}/EDEN-Core-Scripts"
|
| 54 |
+
create_repo(core_repo, token=TOKEN, repo_type="model", exist_ok=True, private=False)
|
| 55 |
+
|
| 56 |
+
# README
|
| 57 |
+
safe_upload(
|
| 58 |
+
os.path.join(BASE, "hf_readmes", "EDEN-Core-Scripts_README.md"),
|
| 59 |
+
core_repo, "README.md"
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
# All algorithm .py scripts
|
| 63 |
+
for py in sorted(glob.glob(os.path.join(BASE, "**", "*.py"), recursive=True)):
|
| 64 |
+
rel = os.path.relpath(py, BASE)
|
| 65 |
+
if any(k in rel for k in ["Algo_", "eden_", "mobilevit_model"]):
|
| 66 |
+
safe_upload(py, core_repo, rel.replace(os.sep, "/"))
|
| 67 |
+
|
| 68 |
+
# ββ STEP 2 : Per-model READMEs ββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 69 |
+
print("\n" + "="*60)
|
| 70 |
+
print("STEP 2 β Per-model repo READMEs")
|
| 71 |
+
print("="*60)
|
| 72 |
+
|
| 73 |
+
for rf in sorted(glob.glob(os.path.join(BASE, "hf_readmes", "EDEN-*_README.md"))):
|
| 74 |
+
repo_name = os.path.basename(rf).replace("_README.md", "")
|
| 75 |
+
repo_id = f"{USER}/{repo_name}"
|
| 76 |
+
create_repo(repo_id, token=TOKEN, repo_type="model", exist_ok=True, private=False)
|
| 77 |
+
safe_upload(rf, repo_id, "README.md")
|
| 78 |
+
|
| 79 |
+
# ββ STEP 3 : CSV training logs ββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 80 |
+
print("\n" + "="*60)
|
| 81 |
+
print("STEP 3 β CSV training logs")
|
| 82 |
+
print("="*60)
|
| 83 |
+
|
| 84 |
+
for csv in sorted(glob.glob(os.path.join(BASE, "**", "*.csv"), recursive=True)):
|
| 85 |
+
# skip the aggregated helper CSVs
|
| 86 |
+
if any(skip in csv for skip in ["green_ai_", "experiment_summary", "repository"]):
|
| 87 |
+
continue
|
| 88 |
+
arch, ds = parse_arch_ds(csv)
|
| 89 |
+
if arch == "unknown" or ds == "unknown":
|
| 90 |
+
continue
|
| 91 |
+
repo_id = f"{USER}/EDEN-{arch}-{ds.replace(' ', '-')}"
|
| 92 |
+
safe_upload(csv, repo_id, os.path.basename(csv))
|
| 93 |
+
|
| 94 |
+
print("\n" + "="*60)
|
| 95 |
+
print("ALL DONE β Check https://huggingface.co/Shanmuk4622")
|
| 96 |
+
print("="*60)
|