File size: 1,104 Bytes
8acc7cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from huggingface_hub import HfApi, HfFolder, upload_file
import os

# Set these variables
REPO_ID = "harithkavish/multi-object-detection-models"
MODEL_FILES = [
    "image_classifier.keras",
    "yolov8n-seg.pt"
]
TFJS_DIR = "tfjs_model"

# Authenticate
api = HfApi()
api.set_access_token(os.environ["HF_TOKEN"])

# Upload model files
for file in MODEL_FILES:
    if os.path.exists(file):
        print(f"Uploading {file}...")
        api.upload_file(
            path_or_fileobj=file,
            path_in_repo=file,
            repo_id=REPO_ID,
            repo_type="model"
        )

# Upload TensorFlow.js model directory
if os.path.exists(TFJS_DIR):
    for root, dirs, files in os.walk(TFJS_DIR):
        for file in files:
            local_path = os.path.join(root, file)
            repo_path = os.path.relpath(local_path, ".")
            print(f"Uploading {repo_path}...")
            api.upload_file(
                path_or_fileobj=local_path,
                path_in_repo=repo_path,
                repo_id=REPO_ID,
                repo_type="model"
            )
print("Upload complete.")