File size: 1,236 Bytes
af44b2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# https://huggingface.co/docs/huggingface_hub/guides/upload

# PUSH model to HuggingFace manufy/mnist_model_keras
# with custom commit message

###############################
# 1 - Initial generic imports #
###############################

from icecream import ic
ic("--- Importing generic libraries ---")
from dotenv import load_dotenv, find_dotenv
import os
from datetime import datetime

###############################################################################
# 2 - Setting up environment variable HUGGINGFACE_TOKEN with write permission #
###############################################################################

ic("--- Setting HF API token ---")
load_dotenv(find_dotenv())
token = os.getenv("HUGGINGFACE_TOKEN")
formatted_now = datetime.now().strftime("%d/%m/%Y, %H:%M:%S")
ic("--- Importing HF API ---")
from huggingface_hub import HfApi, CommitOperationAdd, CommitOperationDelete
ic("--- Executing commit with custom message ---")
api = HfApi()
operations = [
    CommitOperationAdd(path_in_repo="saved_model", path_or_fileobj="mnist_model.keras")
]
api.create_commit(
    repo_id="manufy/mnist_model_keras",
    operations=operations,
    commit_message=f"Updated model at  {formatted_now}.",
    token=token
)