Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open source Inference widgets + optimize for community contributions #87

Merged
merged 27 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
54ec6e4
npm init svelte@next + tweaks
julien-c Jun 9, 2021
57ffdd2
rm lib/ from main python-centric .gitignore
julien-c Jun 9, 2021
f0f0478
svelte: set typescript as default
julien-c Jun 9, 2021
ec13192
prettier: pin to same versions as moon-landing, and do not format .ts…
julien-c Jun 9, 2021
88bf27c
cp files from moon-landing
julien-c Jun 9, 2021
a8f119f
Add slimmed down version of ViewUtils.ts + fix paths to it
julien-c Jun 9, 2021
dc9056e
move ModelData around to be able to use it here
julien-c Jun 9, 2021
b0ee9e1
Fix more imports + add attributes to ModelData
julien-c Jun 9, 2021
8e35ac7
import pipeline icons...
julien-c Jun 9, 2021
6b7065f
other (non-pipeline) icons
julien-c Jun 9, 2021
ef51b37
add (last?) missing svelte file
julien-c Jun 9, 2021
b60a3c3
apiUrl: set a sane actual default
julien-c Jun 9, 2021
56e2fa9
Yay it's working! 🎉
julien-c Jun 9, 2021
f147ea4
Slightly slimmed down Tailwind setup from hf.co
julien-c Jun 10, 2021
1c60789
Better type for `apiToken`
julien-c Jun 10, 2021
82d53ef
make more model attributes optional
julien-c Jun 10, 2021
01e846f
Add /:model page (w/ just one widget) + static adapter
julien-c Jun 10, 2021
39cbc7f
/:model is capable of displaying error
julien-c Jun 10, 2021
85e0bfb
[ci] do not run Python tests on widgets
julien-c Jun 10, 2021
5442ea0
[ci] svelte
julien-c Jun 10, 2021
5f7719c
CD of static site
julien-c Jun 10, 2021
8a89d67
ci: netlify push to prod?
julien-c Jun 10, 2021
cb1b231
Add dark mode switcher for ease of dev
julien-c Jun 10, 2021
5b15dd8
Fixes for dark mode
julien-c Jun 10, 2021
57fa692
more models
julien-c Jun 10, 2021
ec32849
basic readme
julien-c Jun 10, 2021
da67b6f
ok ok
julien-c Jun 10, 2021
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
58 changes: 58 additions & 0 deletions .github/workflows/js-widgets-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: JS Widgets

on:
push:
paths:
- "widgets/**"
pull_request:
paths:
- "widgets/**"


jobs:
build:

runs-on: ubuntu-latest

timeout-minutes: 10

steps:
- uses: actions/checkout@v1
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 14
- working-directory: widgets
run: |
npm ci
- name: Check style
working-directory: widgets
run: |
npm run lint
- name: Check svelte
working-directory: widgets
run: |
npm run check
- name: Build front
working-directory: widgets
run: |
npm run build

# CD of static site
- name: Netlify install
working-directory: widgets
run: |
npm i netlify-cli

- name: Netlify find out whether push to prod
if: endsWith(github.ref, '/master')
run: |
echo "::set-env name=NETLIFY_EXTRA_FLAG::--prod"

- name: Netlify deploy
working-directory: widgets
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: 69b9df00-bfdd-4499-bd7f-6add4d703d99
run: |
npx netlify deploy --auth "$NETLIFY_AUTH_TOKEN" --dir ./build/ --site ${NETLIFY_SITE_ID} ${NETLIFY_EXTRA_FLAG}
2 changes: 2 additions & 0 deletions .github/workflows/python-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ on:
- main
paths-ignore:
- "interfaces/**"
- "widgets/**"
pull_request:
types: [assigned, opened, synchronize, reopened]
paths-ignore:
- "interfaces/**"
- "widgets/**"

jobs:
check_code_quality:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ on:
- main
paths-ignore:
- "interfaces/**"
- "widgets/**"
pull_request:
types: [assigned, opened, synchronize, reopened]
paths-ignore:
- "interfaces/**"
- "widgets/**"

jobs:
build:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
Expand Down
2 changes: 1 addition & 1 deletion interfaces/DefaultWidget.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PipelineType } from './Types';
import type { PipelineType } from './Types';

type LanguageCode = string;

Expand Down
28 changes: 1 addition & 27 deletions interfaces/Libraries.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ModelData } from "./Types";

/**
* Add your new library here.
Expand All @@ -18,33 +19,6 @@ export enum ModelLibrary {

export const ALL_MODEL_LIBRARY_KEYS = Object.keys(ModelLibrary) as (keyof typeof ModelLibrary)[];

/**
* subset of model metadata that
* a code snippet can depend on.
*/
interface ModelData {
/**
* id of model (e.g. 'user/repo_name')
*/
modelId: string;
/**
* is this model private?
*/
private: boolean;
/**
* all the model tags
*/
tags: string[];
/**
* this is transformers-specific
*/
autoArchitecture: string;
/**
* this dictionary has useful information about the model configuration
*/
config?: Record<string, any>;
}


/**
* Elements configurable by a model library.
Expand Down
42 changes: 42 additions & 0 deletions interfaces/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,45 @@ export const PIPELINE_TYPE_PRETTY_NAMES: { [key in PipelineType]: string } = {
"image-segmentation": "Image Segmentation",
};



/**
* Public interface for model metadata
*/
export interface ModelData {
/**
* id of model (e.g. 'user/repo_name')
*/
modelId: string;
/**
* is this model private?
*/
private?: boolean;
/**
* this dictionary has useful information about the model configuration
*/
config?: Record<string, any>;
/**
* all the model tags
*/
tags?: string[];
/**
* this is transformers-specific
*/
autoArchitecture?: string;
/**
* Pipeline type
*/
pipeline_tag?: (keyof typeof PipelineType) | undefined;
/**
* for relevant models, get mask token
*/
mask_token?: string | undefined;
/**
* Example data that will be fed into the widget.
*
* can be set in the model card metadata (under `widget`),
* or by default in `DefaultWidget.ts`
*/
widgetData?: Record<string, any>[] | undefined;
}
4 changes: 4 additions & 0 deletions widgets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
node_modules
/.svelte-kit
/package
3 changes: 3 additions & 0 deletions widgets/.netlify/state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"siteId": "69b9df00-bfdd-4499-bd7f-6add4d703d99"
}
10 changes: 10 additions & 0 deletions widgets/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.svelte-kit/**
static/**
build/**
node_modules/**
*.js
*.mjs
*.cjs
*.md
*.ts
*.css
3 changes: 3 additions & 0 deletions widgets/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"useTabs": true
}
31 changes: 31 additions & 0 deletions widgets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# huggingface-widgets

Open-source version of the inference widgets from huggingface.co

> Built with Svelte and SvelteKit

**Demo page:** https://huggingface-widgets.netlify.app/

## Documentation

For now checkout the Pull Request's description: https://github.com/huggingface/huggingface_hub/pull/87

TODO: write more documentation

## How to develop

Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:

```bash
npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open
```

## Build for production

```bash
npm run build
```

Loading