-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hfsup): new integration, added back airi deploy to HF Spaces (#6)
* fix: pwa issue, special `TARGET_HUGGINGFACE_SPACE` for hf spaces, half width issue
- Loading branch information
1 parent
0eb72d9
commit de29371
Showing
25 changed files
with
836 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,11 +26,11 @@ jobs: | |
HF_TOKEN: ${{ secrets.HF_TOKEN }} | ||
HF_USERNAME: ${{ secrets.HF_USERNAME }} | ||
# - run: |- | ||
# git clone https://$HF_USERNAME:[email protected]/spaces/moeru-ai/airi --depth 1 packages/stage/dist | ||
# env: | ||
# HF_TOKEN: ${{ secrets.HF_TOKEN }} | ||
# HF_USERNAME: ${{ secrets.HF_USERNAME }} | ||
- run: |- | ||
git clone https://$HF_USERNAME:[email protected]/spaces/moeru-ai/airi --depth 1 packages/stage/dist | ||
env: | ||
HF_TOKEN: ${{ secrets.HF_TOKEN }} | ||
HF_USERNAME: ${{ secrets.HF_USERNAME }} | ||
- uses: pnpm/action-setup@v3 | ||
- uses: actions/setup-node@v4 | ||
|
@@ -40,11 +40,14 @@ jobs: | |
|
||
- run: pnpm install | ||
- run: pnpm build | ||
env: | ||
TARGET_HUGGINGFACE_SPACE: 'true' | ||
VITE_APP_TARGET_HUGGINGFACE_SPACE: 'true' | ||
|
||
- id: moonshine_web_diff | ||
working-directory: ./packages/moonshine-web/dist | ||
run: |- | ||
mv ../README.md . | ||
git lfs ls-files --all | ||
git add . | ||
if [[ -n $(git status --porcelain) ]]; then | ||
echo "changes=true" >> "$GITHUB_OUTPUT"; | ||
|
@@ -59,12 +62,13 @@ jobs: | |
git config --local user.email "[email protected]" | ||
git config --local user.name "Neko Ayaka" | ||
git commit -m "release: build ${{ github.sha }}" | ||
git lfs push origin main --all | ||
git push -f | ||
- id: whisper_webgpu_diff | ||
working-directory: ./packages/whisper-webgpu/dist | ||
run: |- | ||
mv ../README.md . | ||
git lfs ls-files --all | ||
git add . | ||
if [[ -n $(git status --porcelain) ]]; then | ||
echo "changes=true" >> "$GITHUB_OUTPUT"; | ||
|
@@ -79,24 +83,26 @@ jobs: | |
git config --local user.email "[email protected]" | ||
git config --local user.name "Neko Ayaka" | ||
git commit -m "release: build ${{ github.sha }}" | ||
git lfs push origin main --all | ||
git push -f | ||
# - id: airi_diff | ||
# working-directory: ./packages/stage/dist | ||
# run: |- | ||
# mv ../README.md . | ||
# git add . | ||
# if [[ -n $(git status --porcelain) ]]; then | ||
# echo "changes=true" >> "$GITHUB_OUTPUT"; | ||
# fi | ||
- id: airi_diff | ||
working-directory: ./packages/stage/dist | ||
run: |- | ||
git lfs ls-files --all | ||
git add . | ||
if [[ -n $(git status --porcelain) ]]; then | ||
echo "changes=true" >> "$GITHUB_OUTPUT"; | ||
fi | ||
# - if: steps.airi_diff.outputs.changes == 'true' | ||
# working-directory: ./packages/stage/dist | ||
# env: | ||
# HF_TOKEN: ${{ secrets.HF_TOKEN }} | ||
# HF_USERNAME: ${{ secrets.HF_USERNAME }} | ||
# run: |- | ||
# git config --local user.email "[email protected]" | ||
# git config --local user.name "Neko Ayaka" | ||
# git commit -m "release: build ${{ github.sha }}" | ||
# git push -f | ||
- if: steps.airi_diff.outputs.changes == 'true' | ||
working-directory: ./packages/stage/dist | ||
env: | ||
HF_TOKEN: ${{ secrets.HF_TOKEN }} | ||
HF_USERNAME: ${{ secrets.HF_USERNAME }} | ||
run: |- | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "Neko Ayaka" | ||
git commit -m "release: build ${{ github.sha }}" | ||
git lfs push origin main --all | ||
git push -f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<h1 align="center">🧑🚀 hfsup</h1> | ||
|
||
> `hfsup` stands for HuggingFace Space up, where the `up` is coming from `rollup`, `tsup`, you may think of "to make your work up and running". | ||
> | ||
> A collection of tools to help you deploy, bundle HuggingFace Spaces and related assets with ease. | ||
```shell | ||
pnpm i hfsup -D | ||
``` | ||
|
||
```ts | ||
import { LFS, SpaceCard } from 'hfsup/vite' | ||
import { defineConfig } from 'vite' | ||
|
||
export default defineConfig({ | ||
plugins: [ | ||
LFS(), | ||
SpaceCard({ | ||
title: 'Real-time Whisper WebGPU (Vue)', | ||
emoji: '🎤', | ||
colorFrom: 'gray', | ||
colorTo: 'green', | ||
sdk: 'static', | ||
pinned: false, | ||
license: 'mit', | ||
models: ['onnx-community/whisper-base'], | ||
short_description: 'Yet another Real-time Whisper with WebGPU, written in Vue', | ||
thumbnail: 'https://raw.githubusercontent.com/moeru-ai/airi/refs/heads/main/packages/whisper-webgpu/public/banner.png' | ||
}) | ||
] | ||
}) | ||
``` | ||
|
||
After bundling, a dedicated README with merged front-matter header will be generated in the root of your project: | ||
|
||
```md | ||
--- | ||
title: Real-time Whisper WebGPU (Vue) | ||
emoji: 🎤 | ||
colorFrom: gray | ||
colorTo: green | ||
sdk: static | ||
pinned: false | ||
license: mit | ||
models: | ||
- onnx-community/whisper-base | ||
short_description: Yet another Real-time Whisper with WebGPU, written in Vue | ||
thumbnail: https://raw.githubusercontent.com/moeru-ai/airi/refs/heads/main/packages/whisper-webgpu/public/banner.png | ||
--- | ||
|
||
# Real-time Whisper WebGPU (Vue) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "hfsup", | ||
"type": "module", | ||
"private": false, | ||
"description": "A collection of tools to help you deploy, bundle HuggingFace Spaces and related assets with ease.", | ||
"author": { | ||
"name": "Neko Ayaka", | ||
"email": "[email protected]", | ||
"url": "https://github.com/nekomeowww" | ||
}, | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/moeru-ai/airi.git", | ||
"directory": "packages/huggingspace" | ||
}, | ||
"sideEffects": false, | ||
"exports": { | ||
"./vite": { | ||
"types": "./dist/vite/index.d.ts", | ||
"import": "./dist/vite/index.mjs", | ||
"node": "./dist/vite/index.cjs" | ||
} | ||
}, | ||
"main": "./dist/vite/index.cjs", | ||
"module": "./dist/vite/index.mjs", | ||
"types": "./dist/vite/index.d.ts", | ||
"files": [ | ||
"README.md", | ||
"dist", | ||
"package.json" | ||
], | ||
"scripts": { | ||
"dev": "pnpm run stub", | ||
"stub": "unbuild --stub", | ||
"build": "unbuild" | ||
}, | ||
"dependencies": { | ||
"gray-matter": "^4.0.3", | ||
"vite": "^6.0.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { stat } from 'node:fs/promises' | ||
|
||
export async function exists(path: string) { | ||
try { | ||
await stat(path) | ||
return true | ||
} | ||
catch (error) { | ||
if (isENOENTError(error)) | ||
return false | ||
|
||
throw error | ||
} | ||
} | ||
|
||
export function isENOENTError(error: unknown): boolean { | ||
if (!(error instanceof Error)) | ||
return false | ||
if (!('code' in error)) | ||
return false | ||
if (error.code !== 'ENOENT') | ||
return false | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './lfs' | ||
export * from './space-card' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import type { Plugin, ResolvedConfig } from 'vite' | ||
|
||
const defaultGitAttributes = `# Default | ||
*.7z filter=lfs diff=lfs merge=lfs -text | ||
*.arrow filter=lfs diff=lfs merge=lfs -text | ||
*.bin filter=lfs diff=lfs merge=lfs -text | ||
*.bz2 filter=lfs diff=lfs merge=lfs -text | ||
*.ckpt filter=lfs diff=lfs merge=lfs -text | ||
*.ftz filter=lfs diff=lfs merge=lfs -text | ||
*.gz filter=lfs diff=lfs merge=lfs -text | ||
*.h5 filter=lfs diff=lfs merge=lfs -text | ||
*.joblib filter=lfs diff=lfs merge=lfs -text | ||
*.lfs.* filter=lfs diff=lfs merge=lfs -text | ||
*.mlmodel filter=lfs diff=lfs merge=lfs -text | ||
*.model filter=lfs diff=lfs merge=lfs -text | ||
*.msgpack filter=lfs diff=lfs merge=lfs -text | ||
*.npy filter=lfs diff=lfs merge=lfs -text | ||
*.npz filter=lfs diff=lfs merge=lfs -text | ||
*.onnx filter=lfs diff=lfs merge=lfs -text | ||
*.ot filter=lfs diff=lfs merge=lfs -text | ||
*.parquet filter=lfs diff=lfs merge=lfs -text | ||
*.pb filter=lfs diff=lfs merge=lfs -text | ||
*.pickle filter=lfs diff=lfs merge=lfs -text | ||
*.pkl filter=lfs diff=lfs merge=lfs -text | ||
*.pt filter=lfs diff=lfs merge=lfs -text | ||
*.pth filter=lfs diff=lfs merge=lfs -text | ||
*.rar filter=lfs diff=lfs merge=lfs -text | ||
*.safetensors filter=lfs diff=lfs merge=lfs -text | ||
saved_model/**/* filter=lfs diff=lfs merge=lfs -text | ||
*.tar.* filter=lfs diff=lfs merge=lfs -text | ||
*.tar filter=lfs diff=lfs merge=lfs -text | ||
*.tflite filter=lfs diff=lfs merge=lfs -text | ||
*.tgz filter=lfs diff=lfs merge=lfs -text | ||
*.wasm filter=lfs diff=lfs merge=lfs -text | ||
*.xz filter=lfs diff=lfs merge=lfs -text | ||
*.zip filter=lfs diff=lfs merge=lfs -text | ||
*.zst filter=lfs diff=lfs merge=lfs -text | ||
*tfevents* filter=lfs diff=lfs merge=lfs -text | ||
` | ||
|
||
export function LFS(options?: { | ||
enableFn?: (config: ResolvedConfig) => boolean | Promise<boolean> | ||
extraGlobs?: string[] | ||
extraAttributes?: string[] | ||
withDefault?: boolean | ||
}): Plugin { | ||
let _config: ResolvedConfig | ||
|
||
return { | ||
name: 'huggingspace:lfs-gitattributes', | ||
configResolved(config) { | ||
_config = config | ||
}, | ||
async generateBundle() { | ||
if (options?.enableFn && !(await options.enableFn(_config))) { | ||
return | ||
} | ||
|
||
const extraGlobs = options?.extraGlobs ?? [] | ||
const extraAttributes = options?.extraAttributes ?? [] | ||
const withDefault = options?.withDefault ?? true | ||
const gitAttributes = withDefault ? defaultGitAttributes : '' | ||
const extraGlobsIntoGitAttributes = extraGlobs.map((glob) => { | ||
return `${glob} filter=lfs diff=lfs merge=lfs -text` | ||
}) | ||
|
||
this.emitFile({ | ||
type: 'asset', | ||
fileName: '.gitattributes', | ||
source: `${extraAttributes.join('\n')}${extraGlobsIntoGitAttributes.join('\n')}\n${gitAttributes}`, | ||
}) | ||
}, | ||
} | ||
} |
Oops, something went wrong.