name: HuggingFace Model Sync on: push: branches: [main] paths: - 'models/**' - 'configs/hf-*.json' schedule: - cron: '0 2 * * 0' # Weekly Sunday 2 AM workflow_dispatch: inputs: model_id: description: 'HuggingFace model ID to sync' required: false default: 'blackroad-os/blackroad-agents' jobs: sync-to-hub: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: lfs: true - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.11' - name: Install HuggingFace Hub run: pip install huggingface_hub>=0.20.0 - name: Login to HuggingFace run: | python3 -c "from huggingface_hub import login; login(token='${{ secrets.HF_TOKEN }}')" - name: Sync models to Hub env: HF_TOKEN: ${{ secrets.HF_TOKEN }} MODEL_ID: ${{ github.event.inputs.model_id || 'blackroad-os/blackroad-agents' }} run: | python3 - <<'PYEOF' import os from huggingface_hub import HfApi, create_repo api = HfApi(token=os.environ["HF_TOKEN"]) model_id = os.environ["MODEL_ID"] # Create or update repo try: create_repo(model_id, repo_type="model", exist_ok=True, token=os.environ["HF_TOKEN"]) print(f"✓ Repo ready: {model_id}") except Exception as e: print(f"Note: {e}") # Upload model files if present if os.path.exists("models"): api.upload_folder( folder_path="models", repo_id=model_id, repo_type="model", ) print(f"✓ Models uploaded to {model_id}") # Sync README if os.path.exists("README.md"): api.upload_file( path_or_fileobj="README.md", path_in_repo="README.md", repo_id=model_id, repo_type="model", ) print(f"✓ README synced") PYEOF create-space: runs-on: ubuntu-latest if: github.event_name == 'workflow_dispatch' steps: - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.11' - name: Install dependencies run: pip install huggingface_hub gradio - name: Create/Update HF Space env: HF_TOKEN: ${{ secrets.HF_TOKEN }} ORG_NAME: ${{ github.repository_owner }} run: | python3 - <<'PYEOF' import os from huggingface_hub import HfApi, create_repo, SpaceStage api = HfApi(token=os.environ["HF_TOKEN"]) space_id = f"blackroad-os/{os.environ.get('ORG_NAME', 'blackroad')}-demo" try: create_repo(space_id, repo_type="space", space_sdk="gradio", exist_ok=True, token=os.environ["HF_TOKEN"]) print(f"✓ Space ready: https://huggingface.co/spaces/{space_id}") except Exception as e: print(f"Space: {e}") PYEOF