fix(ci): download ONNX directly from HF Hub instead of full export pipeline

- No need to install TensorFlow (3GB) — just pip install huggingface_hub
- Download pre-built model.onnx directly (saved from notebook export)
- Cuts CI time from ~10 min to ~30 seconds

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
MythEclipse
2026-06-11 20:23:39 +00:00
co-authored by Claude
parent 04d2bebdfe
commit df09bbca89
+14 -25
View File
@@ -41,52 +41,41 @@ jobs:
with: with:
python-version: '3.11' python-version: '3.11'
- name: Download model from Hugging Face & export ONNX - name: Download ONNX model from Hugging Face
if: matrix.service.name == 'ml' if: matrix.service.name == 'ml'
working-directory: Machine_Learning working-directory: Machine_Learning
env: env:
HF_TOKEN: ${{ secrets.HF_TOKEN }} HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: | run: |
set -euo pipefail set -eu
echo "::group::Install huggingface_hub"
python -m pip install --upgrade pip -q
python -m pip install huggingface_hub -q
echo "::endgroup::"
# Diagnostic echo "::group::Check HF_TOKEN"
echo "::group::Environment check"
if [ -z "${HF_TOKEN:-}" ]; then if [ -z "${HF_TOKEN:-}" ]; then
echo "ERROR: HF_TOKEN secret is not set." echo "ERROR: HF_TOKEN secret is not set."
echo "Add it at: https://github.com/ATLAS-PJK-GM007/ZeaVis-Edu/settings/secrets/actions" echo "Add it: https://github.com/ATLAS-PJK-GM007/ZeaVis-Edu/settings/secrets/actions"
echo "Name: HF_TOKEN Value: your Hugging Face token"
exit 1 exit 1
fi fi
echo "HF_TOKEN is set (length: ${#HF_TOKEN})" echo "HF_TOKEN is set (length: ${#HF_TOKEN})"
echo "::endgroup::" echo "::endgroup::"
echo "::group::Install dependencies" echo "::group::Download model.onnx"
python -m pip install --upgrade pip
python -m pip install 'tensorflow>=2.13.0' 'tf2onnx>=1.16.1' 'onnx>=1.16.0' 'huggingface_hub'
echo "::endgroup::"
echo "::group::Download model from Hugging Face"
python -c " python -c "
from huggingface_hub import hf_hub_download from huggingface_hub import hf_hub_download
import os import os
os.makedirs('best_model', exist_ok=True) os.makedirs('model', exist_ok=True)
path = hf_hub_download( path = hf_hub_download(
repo_id='MythEclipse2737/corn-leaf-disease-classifier', repo_id='MythEclipse2737/corn-leaf-disease-classifier',
filename='best_model.keras', filename='model/model.onnx',
token=os.environ['HF_TOKEN'], token=os.environ['HF_TOKEN'],
local_dir='best_model', local_dir='.',
) )
print(f'Model downloaded to {path}') print(f'Downloaded: {path}')
" "
echo "::endgroup::" ls -lh model/model.onnx
echo "::group::Export SavedModel + TFLite"
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
python save_model.py
echo "::endgroup::"
echo "::group::Export ONNX"
python convert_onnx.py
echo "::endgroup::" echo "::endgroup::"
- name: Log in to GHCR - name: Log in to GHCR