mnist-custom-keras-model / push-model-to-huggingface-with-upload-folder.py
Manu
updated files
54c0759
# https://huggingface.co/docs/huggingface_hub/guides/upload
# PUSH model to HuggingFace manufy/mnist_model_keras
# using upload_folder, commit message is set by defaulr and not customizable
###############################
# 1 - Initial generic imports #
###############################
from icecream import ic
ic("--- Importing generic libraries ---")
from dotenv import load_dotenv, find_dotenv
import os
###############################################################################
# 2 - Setting up environment variable HUGGINGFACE_TOKEN with write permission #
###############################################################################
ic("--- Importing HF API token ---")
load_dotenv(find_dotenv())
token = os.getenv("HUGGINGFACE_TOKEN")
# The code in the comments is not needed
# the model doen't need to be loaded to be uploaded
################################################################
# 3 - Importing keras load_model #
################################################################
# ic("--- Importing tensorflow load_model ---")
# from tensorflow.keras.models import load_model
# ic("--- Importing huggingface_hub ---")
###########################
# 3 - Loading keras model #
###########################
# ic("--- Loading local keras model ---" )
# model = load_model('mnist_model.keras')
######################################
# 3 - Uploading model to HuggingFace #
######################################
ic ("--- Importing HF API ---")
from huggingface_hub import HfApi
ic("--- Settig up HF API ---")
HuggingFace_api = HfApi()
ic("--- Uploading models ---")
HuggingFace_api.upload_folder(
folder_path="saved_models/",
repo_id="manufy/mnist_model_keras",
repo_type="model",
token=token)
########################################################################
# The following are failed attempts to upload the model to HuggingFace #
########################################################################
# upload_folder("manufy/mnist_model_keras")
# not supported in keras 3
# NotImplementedError: Cannot use 'save_pretrained_keras':
# Keras 3.x is not supported.
# Please save models manually and upload them
# using `upload_folder` or `huggingface-cli upload`.
#ic("--- Saving huggingface model ---" )
#huggingface_hub.save_pretrained_keras('saved_model/')
#push_to_hub_keras(model,
# "manufy/mnist_model_keras")
# include_optimizer = True,
# tags = ["object-detection", "some_other_tag"]
#)