Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 74 additions & 108 deletions .github/workflows/sync-hf-space.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@ on:
branches: [master]
paths:
- "examples/demo/**"
- "src/**"
- "types/**"
- "package.json"
- "package-lock.json"
- ".github/workflows/sync-hf-space.yml"
workflow_dispatch:
inputs:
space_id:
description: "Hugging Face Space repo id to deploy to"
required: false
default: "ysdede/parakeet.js-demo"

env:
HF_SPACE_ID: ${{ github.event.inputs.space_id || 'ysdede/parakeet.js-demo' }}

jobs:
sync:
Expand All @@ -15,41 +27,64 @@ jobs:
steps:
- uses: actions/checkout@v5

- name: Create HF export
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: "22"
cache: "npm"
cache-dependency-path: |
package-lock.json
examples/demo/package-lock.json

- name: Install root dependencies for local source build
run: npm ci

- name: Use local parakeet.js package for demo build
working-directory: examples/demo
run: |
set -euo pipefail
rm -rf hf_export && mkdir -p hf_export
node -e "
const fs = require('fs');
const p = require('./package.json');
p.dependencies['parakeet.js'] = 'file:../..';
fs.writeFileSync('package.json', JSON.stringify(p, null, 2) + '\n');
"

- name: Install demo dependencies
working-directory: examples/demo
run: npm install

- name: Build demo static assets
working-directory: examples/demo
env:
PARAKEET_LOCAL: "true"
VITE_PUBLIC_BASE: "/"
run: npm run build:local

# Copy demo source (exclude dev artifacts)
rsync -a --exclude='node_modules' --exclude='dist' --exclude='.git' --exclude='public/assets' \
examples/demo/ hf_export/
- name: Create prebuilt HF static export
run: |
set -euo pipefail
rm -rf hf_export
mkdir -p hf_export

# ── 1) Remove GH-only files ────────────────────────────────
rm -rf hf_export/scripts
rm -f hf_export/package-lock.json
# Push prebuilt files to the Space root. This avoids HF-side static
# builds, which currently require account credits.
rsync -a --delete examples/demo/dist/ hf_export/

# ── 2) Remove COI serviceworker (HF has real CORS headers) ──
# HF Static Spaces serve real COOP/COEP headers via README custom_headers.
# The COI service worker is only for GitHub Pages and should not be used here.
sed -i '/<script src="coi-serviceworker.js"><\/script>/d' hf_export/index.html
rm -f hf_export/public/coi-serviceworker.js

echo "✅ HF export ready"
find hf_export -maxdepth 2 -not -path '*/node_modules/*'
rm -f hf_export/coi-serviceworker.js

- name: Write HF-specific files
run: |
# ── README.md with HF YAML frontmatter ─────────────────────
cat > hf_export/README.md << 'READMEEOF'
---
title: Parakeet.js Demo
emoji: 🦜
colorFrom: indigo
colorTo: blue
sdk: static
pinned: true
pinned: false
header: mini
fullWidth: true
app_build_command: npm install && npm run build
app_file: dist/index.html
license: mit
short_description: NVIDIA Parakeet speech recognition for the browser
models:
Expand All @@ -69,6 +104,7 @@ jobs:
custom_headers:
cross-origin-embedder-policy: require-corp
cross-origin-opener-policy: same-origin
cross-origin-resource-policy: cross-origin
preload_from_hub:
- ysdede/parakeet-tdt-0.6b-v2-onnx
- ysdede/parakeet-tdt-0.6b-v3-onnx
Expand All @@ -78,101 +114,31 @@ jobs:

Browser-based speech recognition with NVIDIA Parakeet ASR models (WebGPU/WASM).

Synced from [`ysdede/parakeet.js/examples/demo`](https://github.com/ysdede/parakeet.js/tree/master/examples/demo).
This Space is deployed from prebuilt static assets generated by GitHub Actions.
Hugging Face only serves the checked-in static files, so the Space does not
require paid static-build credits.

- [GitHub Repository](https://github.com/ysdede/parakeet.js)
- [npm Package](https://www.npmjs.com/package/parakeet.js)
- [API Documentation](https://ysdede.github.io/parakeet.js/api/)
READMEEOF

# ── vite.config.js (NPM-only, no local-source aliasing) ────
cat > hf_export/vite.config.js << 'VITEEOF'
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import fs from 'fs';
import path from 'path';

function readJson(filePath) {
try {
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
} catch {
return null;
}
}

const npmPkg = readJson(path.resolve(__dirname, 'node_modules/parakeet.js/package.json'));
const parakeetVersion = npmPkg?.version || 'unknown';

export default defineConfig({
plugins: [react()],
server: {
port: 3000,
headers: {
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'require-corp',
},
},
define: {
global: 'globalThis',
__PARAKEET_VERSION__: JSON.stringify(parakeetVersion),
__PARAKEET_SOURCE__: JSON.stringify('npm'),
},
});
VITEEOF

# ── package.json (no cross-env / dev:local scripts) ─────────
cat > hf_export/package.json << 'PKGEOF'
{
"name": "parakeet-js-demo",
"version": "1.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"parakeet.js": "^1.4.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@tailwindcss/forms": "^0.5.0",
"@tailwindcss/typography": "^0.5.0",
"@vitejs/plugin-react": "^4.0.0",
"autoprefixer": "^10.4.0",
"postcss": "^8.4.0",
"tailwindcss": "^3.4.0",
"vite": "^7.3.1"
}
}
PKGEOF

- name: Push to HF Space
touch hf_export/.nojekyll
echo "HF prebuilt static export ready:"
find hf_export -maxdepth 2 -type f | sort

- name: Push prebuilt static export to HF Space
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: |
set -e
SPACE_URL="https://ysdede:${HF_TOKEN}@huggingface.co/spaces/ysdede/parakeet.js-demo"
if git clone --depth 1 "$SPACE_URL" space_repo 2>/dev/null; then
rsync -a --delete --exclude='.git' hf_export/ space_repo/
cd space_repo
git config user.name "github-actions"
git config user.email "github-actions@users.noreply.github.com"
git add -A
if ! git diff --cached --quiet; then
git commit -m "Sync from GitHub (${GITHUB_SHA::7})"
git push origin main
fi
else
cd hf_export
git init
git config user.name "github-actions"
git config user.email "github-actions@users.noreply.github.com"
git add -A
git commit -m "Sync from GitHub (${GITHUB_SHA::7})"
git branch -M main
git remote add origin "$SPACE_URL"
git push -u origin main
set -euo pipefail
if [ -z "${HF_TOKEN:-}" ]; then
echo "HF_TOKEN secret is required" >&2
exit 1
fi

python -m pip install --upgrade huggingface_hub
hf upload "$HF_SPACE_ID" hf_export . \
--repo-type=space \
--delete '*' \
--commit-message "Sync prebuilt static demo (${GITHUB_SHA::7})"
9 changes: 3 additions & 6 deletions examples/demo/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1464,14 +1464,11 @@ export default function App() {
href="https://github.com/ysdede/parakeet.js"
target="_blank"
rel="noopener noreferrer"
className="flex items-center hover:opacity-80 transition-opacity"
className="inline-flex items-center gap-2 rounded-lg border border-gray-300 bg-gray-100 px-3 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-200 dark:hover:bg-gray-600"
title="View on GitHub"
>
<img
src="https://img.shields.io/github/stars/ysdede/parakeet%2Ejs?style=social"
alt="GitHub stars"
className="h-6"
/>
<span className="material-icons-outlined text-base">code</span>
GitHub
</a>
<button
className="flex items-center justify-center p-2 rounded-full bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 transition-colors"
Expand Down