Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
machineuser commited on
Commit ·
388ac76
1
Parent(s): 767bfd8
Sync widgets demo
Browse filesFiles changed (7)
5 unmodified lines67891011121314151617185 unmodified lines**Demo page:** https://huggingface.co/spaces/huggingfacejs/inference-widgetsYou can also run the demo locally:```consolepnpm installpnpm dev```## PublishingBecause `@huggingface/widgets` depends on `@huggingface/tasks`, you need to publish `@huggingface/tasks` first, and then `@huggingface/widgets`.5 unmodified lines6789101112131415161718192021222324252627282930315 unmodified lines**Demo page:** https://huggingface.co/spaces/huggingfacejs/inference-widgets## PublishingBecause `@huggingface/widgets` depends on `@huggingface/tasks`, you need to publish `@huggingface/tasks` first, and then `@huggingface/widgets`. There should be a CI check to prevent publishing `@huggingface/widgets` if `@huggingface/tasks` hasn't been published yet.## DemoYou can run the demo locally:```consolepnpm installpnpm dev```If you want to try the "Sign-in with HF" feature locally, you will need to https://huggingface.co/settings/applications/new an OAuth application with `"openid"` and `"inference-api"` scopes and `http://localhost:5173/auth/callback/huggingface` as the redirect URL.Then you can create a `.env.local` file with the following content:```envOAUTH_CLIENT_ID=...OAUTH_CLIENT_SECRET=...```If you want to try the "Sign-in with HF" feature in a Space, you can just duplicate https://huggingface.co/spaces/huggingfacejs/inference-widgets, it should work out of the box thanks to the metadata in the `README.md` file.
37 unmodified lines38394041424337 unmodified lines"svelte": "^3.59.2"},"devDependencies": {"@fontsource/ibm-plex-mono": "^5.0.8","@fontsource/source-sans-pro": "^5.0.8","@sveltejs/adapter-node": "^1.3.1",37 unmodified lines383940414243444537 unmodified lines"svelte": "^3.59.2"},"devDependencies": {"@auth/core": "^0.18.3","@auth/sveltekit": "^0.3.14","@fontsource/ibm-plex-mono": "^5.0.8","@fontsource/source-sans-pro": "^5.0.8","@sveltejs/adapter-node": "^1.3.1",
9 unmodified lines10111213141552 unmodified lines686970717273293 unmodified lines367368369370371372857 unmodified lines123012311232123312341235204 unmodified lines144014411442144314441445158 unmodified lines160416051606160716081609161016111612161316149 unmodified linesversion: link:../tasksdevDependencies:'@fontsource/ibm-plex-mono':specifier: ^5.0.8version: 5.0.852 unmodified linesengines: {node: '>=10'}dev: true/@esbuild/android-arm64@0.18.20:resolution: {integrity: sha512-Nz4rJcchGDtENV0eMKUNa6L12zz2zBDXuhj/Vjh18zGqB44Bi7MBMSXjgunJgjRhCmKOjnPuZp4Mb6OKqtMHLQ==}engines: {node: '>=12'}293 unmodified linesfastq: 1.15.0dev: true/@polka/url@1.0.0-next.23:resolution: {integrity: sha512-C16M+IYz0rgRhWZdCmK+h58JMv8vijAA61gmz2rspCSwKwzBebpdcsiUmwrtJRdphuY30i6BSLEOP8ppbNLyLg==}dev: true857 unmodified lineshasBin: truedev: true/js-sdsl@4.4.2:resolution: {integrity: sha512-dwXFwByc/ajSV6m5bcKAPwe4yDDF6D614pxmIi5odytzxRlwqF6nwoiCek80Ixc7Cvma5awClxrzFtxCQvcM8w==}dev: true204 unmodified linesnpm-normalize-package-bin: 2.0.0dev: true/object-assign@4.1.1:resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==}engines: {node: '>=0.10.0'}158 unmodified linessource-map-js: 1.0.2dev: true/prelude-ls@1.2.1:resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==}engines: {node: '>= 0.8.0'}dev: true/publint@0.1.9:resolution: {integrity: sha512-O53y7vbePxuGFmEjgcrafMSlDpOJwOkj8YdexOt7yWlv7SB3rXoT3mHknyMJ3lf2UFH5Bmt6tnIkHcOTR6dEoA==}engines: {node: '>=16'}9 unmodified lines10111213141516171819202152 unmodified lines7475767778798081828384858687888990919293949596979899100101102103104105106107108293 unmodified lines402403404405406407408409410411857 unmodified lines1269127012711272127312741275127612771278204 unmodified lines1483148414851486148714881489149014911492158 unmodified lines16511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716789 unmodified linesversion: link:../tasksdevDependencies:'@auth/core':specifier: ^0.18.3version: 0.18.3'@auth/sveltekit':specifier: ^0.3.14version: 0.3.14(@sveltejs/kit@1.27.4)(svelte@3.59.2)'@fontsource/ibm-plex-mono':specifier: ^5.0.8version: 5.0.852 unmodified linesengines: {node: '>=10'}dev: true/@auth/core@0.18.3:resolution: {integrity: sha512-YXQWxi3pKxngt+2vo3dq8+wDANlUH8nhQgX6EVdd3Enfe3vweBtHqzaWrtWzQnVb8wdGxdhxaoOlYroEBE+/yw==}peerDependencies:nodemailer: ^6.8.0peerDependenciesMeta:nodemailer:optional: truedependencies:'@panva/hkdf': 1.1.1cookie: 0.5.0jose: 5.1.2oauth4webapi: 2.4.0preact: 10.11.3preact-render-to-string: 5.2.3(preact@10.11.3)dev: true/@auth/sveltekit@0.3.14(@sveltejs/kit@1.27.4)(svelte@3.59.2):resolution: {integrity: sha512-Ealyi4uM4V42tk4UhhRQ+iZKah0OOp12siXwgDsCj1uBOCeZwL97RkvdMDX7pg18zBP/h2qFAuMWjW5q7bSYxA==}peerDependencies:'@sveltejs/kit': ^1.0.0svelte: ^3.54.0 || ^4.0.0dependencies:'@auth/core': 0.18.3'@sveltejs/kit': 1.27.4(svelte@3.59.2)(vite@4.5.0)svelte: 3.59.2transitivePeerDependencies:- nodemailerdev: true/@esbuild/android-arm64@0.18.20:resolution: {integrity: sha512-Nz4rJcchGDtENV0eMKUNa6L12zz2zBDXuhj/Vjh18zGqB44Bi7MBMSXjgunJgjRhCmKOjnPuZp4Mb6OKqtMHLQ==}engines: {node: '>=12'}293 unmodified linesfastq: 1.15.0dev: true/@panva/hkdf@1.1.1:resolution: {integrity: sha512-dhPeilub1NuIG0X5Kvhh9lH4iW3ZsHlnzwgwbOlgwQ2wG1IqFzsgHqmKPk3WzsdWAeaxKJxgM0+W433RmN45GA==}dev: true/@polka/url@1.0.0-next.23:resolution: {integrity: sha512-C16M+IYz0rgRhWZdCmK+h58JMv8vijAA61gmz2rspCSwKwzBebpdcsiUmwrtJRdphuY30i6BSLEOP8ppbNLyLg==}dev: true857 unmodified lineshasBin: truedev: true/jose@5.1.2:resolution: {integrity: sha512-X7TOC/d8KPvx4wPUuLHVgTSdoWw0UW5TQOUwhvCvj+ZPfsf9vUPhhksYPjNBWVGPQ/6yd/JrL1gQxBnIDwYdFg==}dev: true/js-sdsl@4.4.2:resolution: {integrity: sha512-dwXFwByc/ajSV6m5bcKAPwe4yDDF6D614pxmIi5odytzxRlwqF6nwoiCek80Ixc7Cvma5awClxrzFtxCQvcM8w==}dev: true204 unmodified linesnpm-normalize-package-bin: 2.0.0dev: true/oauth4webapi@2.4.0:resolution: {integrity: sha512-ZWl8ov8HeGVyc9Icl1cag76HvIcDAp23eIIT+UVGir+dEu8BMgMlvZeZwqLVd0P8DqaumH4N+QLQXN69G1QjSA==}dev: true/object-assign@4.1.1:resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==}engines: {node: '>=0.10.0'}158 unmodified linessource-map-js: 1.0.2dev: true/preact-render-to-string@5.2.3(preact@10.11.3):resolution: {integrity: sha512-aPDxUn5o3GhWdtJtW0svRC2SS/l8D9MAgo2+AWml+BhDImb27ALf04Q2d+AHqUUOc6RdSXFIBVa2gxzgMKgtZA==}peerDependencies:preact: '>=10'dependencies:preact: 10.11.3pretty-format: 3.8.0dev: true/preact@10.11.3:resolution: {integrity: sha512-eY93IVpod/zG3uMF22Unl8h9KkrcKIRs2EGar8hwLZZDU1lkjph303V9HZBwufh2s736U6VXuhD109LYqPoffg==}dev: true/prelude-ls@1.2.1:resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==}engines: {node: '>= 0.8.0'}dev: true/pretty-format@3.8.0:resolution: {integrity: sha512-WuxUnVtlWL1OfZFQFuqvnvs6MiAGk9UNsBostyBOB0Is9wb5uRESevA6rnl/rkksXaGX3GzZhPup5d6Vp1nFew==}dev: true/publint@0.1.9:resolution: {integrity: sha512-O53y7vbePxuGFmEjgcrafMSlDpOJwOkj8YdexOt7yWlv7SB3rXoT3mHknyMJ3lf2UFH5Bmt6tnIkHcOTR6dEoA==}engines: {node: '>=16'}
6 unmodified lines7891011126 unmodified lines// interface PageData {}// interface Platform {}}}export {};6 unmodified lines789101112131415161718192021226 unmodified lines// interface PageData {}// interface Platform {}}export interface Session {access_token?: string;}}declare module "@auth/core/types" {export interface Session {access_token?: string;}}export {};
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859import { env } from "$env/dynamic/private";import { skipCSRFCheck } from "@auth/core";import { SvelteKitAuth } from "@auth/sveltekit";import type { Handle } from "@sveltejs/kit";import { sequence } from "@sveltejs/kit/hooks";
const handleSSO = env.OAUTH_CLIENT_ID && env.OAUTH_CLIENT_SECRET ? SvelteKitAuth({ // Should be fine as long as your reverse proxy is configured to only accept traffic with the correct host header trustHost: true, /** * SvelteKit has built-in CSRF protection, so we can skip the check */ skipCSRFCheck: skipCSRFCheck, providers: [ { name: "Hugging Face", id: "huggingface", type: "oidc", clientId: env.OAUTH_CLIENT_ID, clientSecret: env.OAUTH_CLIENT_SECRET, issuer: "https://huggingface.co", wellKnown: "https://huggingface.co/.well-known/openid-configuration", /** Add "inference-api" scope and remove "email" scope */ authorization: { params: { scope: "openid profile inference-api" } }, checks: ["state" as never, "pkce" as never], }, ], secret: env.OAUTH_CLIENT_SECRET, /** * Get the access_token without an account in DB, to make calls to the inference API */ callbacks: { async jwt({ token, account }) { if (account) { return { ...token, access_token: account.access_token, }; } return token; }, async session({ session, token }) { return { ...session, access_token: token.access_token, }; }, }, }) : null;
const handleGlobal: Handle = async ({ event, resolve }) => { const response = await resolve(event); return response;};
export const handle = handleSSO ? sequence(handleSSO, handleGlobal) : handleGlobal;1234567891011import { env } from "$env/dynamic/private";import type { LayoutServerLoad } from "./$types.js";
export const load: LayoutServerLoad = async ({ locals }) => { const session = await locals.getSession();
return { access_token: session?.access_token, supportsOAuth: !!env.OAUTH_CLIENT_ID && !!env.OAUTH_CLIENT_SECRET, };};4 unmodified lines56789101112131415161718192021504 unmodified lines5265275285295305315325335345354 unmodified linesimport InferenceWidget from "$lib/components/InferenceWidget/InferenceWidget.svelte";import ModeSwitcher from "$lib/components/DemoThemeSwitcher/DemoThemeSwitcher.svelte";import { onMount } from "svelte";let apiToken = "";function storeHFToken() {window.localStorage.setItem("hf_token", apiToken);}onMount(() => {const token = window.localStorage.getItem("hf_token");if (token) {apiToken = token;}});504 unmodified lines<div class="flex flex-col gap-6 py-12 px-4"><ModeSwitcher /><label><div class="text-xl font-semibold">First, Enter HF token</div><input class="form-input" type="text" bind:value={apiToken} placeholder="hf_..." on:change={storeHFToken} /></label><div><h1 class="mb-8 text-4xl font-semibold">Showcase of all types of inference widgets running</h1>4 unmodified lines5678910111213141516171819202122232425262728293031504 unmodified lines5365375385395405415425435445455465475485495505515525535545555565575585594 unmodified linesimport InferenceWidget from "$lib/components/InferenceWidget/InferenceWidget.svelte";import ModeSwitcher from "$lib/components/DemoThemeSwitcher/DemoThemeSwitcher.svelte";import { onMount } from "svelte";import { browser } from "$app/environment";export let data;let apiToken = data.access_token || "";function storeHFToken() {window.localStorage.setItem("hf_token", apiToken);}/*** If we are in an iframe, we need to open the auth page in a new tab* to avoid issues with third-party cookies in a space*/const isIframe = browser && window.self !== window.parent;onMount(() => {if (!data.supportsOAuth) {const token = window.localStorage.getItem("hf_token");if (token) {apiToken = token;}}});504 unmodified lines<div class="flex flex-col gap-6 py-12 px-4"><ModeSwitcher />{#if data.supportsOAuth}{#if !data.access_token}<form class="contents" method="post" action="/auth/signin/huggingface" target={isIframe ? "_blank" : ""}><button type="submit" title="Sign in with Hugging Face"><imgsrc="https://huggingface.co/datasets/huggingface/badges/resolve/main/sign-in-with-huggingface-xl-dark.svg"alt="Sign in with Hugging Face"class="h-12 w-auto"/></button></form>{/if}{:else}<label><div class="text-xl font-semibold">First, Enter HF token</div><input class="form-input" type="text" bind:value={apiToken} placeholder="hf_..." on:change={storeHFToken} /></label>{/if}<div><h1 class="mb-8 text-4xl font-semibold">Showcase of all types of inference widgets running</h1>
packages/widgets/README.md+16-3
packages/widgets/package.json+2
packages/widgets/pnpm-lock.yaml+64
packages/widgets/src/app.d.ts+10
packages/widgets/src/hooks.server.tsAdded+59
packages/widgets/src/routes/+layout.server.tsAdded+11
packages/widgets/src/routes/+page.svelte+32-8