mnist-custom-keras-model / push-model-to-huggingface-with-commit.py
Manu
updated files
54c0759
# 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, Repository
# Crear una instancia del repositorio
ic("--- Creating repository instance ---")
repo = Repository(local_dir="saved_models")
# Iterar sobre cada archivo en el directorio 'saved_models'
for root, dirs, files in os.walk("saved_models"):
for file in files:
file_path = os.path.join(root, file)
# Agregar cada archivo al commit
repo.add(CommitOperationAdd(path_in_repo=file_path, path_or_fileobj=file_path))
# Realizar el commit
repo.commit("Commit message")
#ic("--- Executing commit with custom message ---")
#api = HfApi()∫
#operations = [∫
# CommitOperationAdd(path_in_repo="saved_models", path_or_fileobj="saved_models")
# #CommitOperationAdd(path_in_repo="saved_models", path_or_fileobj="saved_models/keras/mnist_model.h5")
#]
#api.create_commit(
## repo_id="manufy/mnist_model_keras",
# operations=operations,
# commit_message=f"Updated models at {formatted_now}.",
# token=token
#)