Initial SSR refactor (#9102)
* changes * asd * fix tests * fix lint * fix ts * fix ts * cleanup * cleanup * fix * Apply suggestions from code review Co-authored-by: Yuichiro Tachibana (Tsuchiya) <t.yic.yt@gmail.com> * fix * add changeset * fix gitignore * fix changeset * fix lockfile * format * fix * add changeset * githunore * kit bopilerplate * add changeset * fix website * add changeset --------- Co-authored-by: Yuichiro Tachibana (Tsuchiya) <t.yic.yt@gmail.com> Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
19
.changeset/wise-buttons-act.md
Normal file
@ -0,0 +1,19 @@
|
||||
---
|
||||
"@gradio/audio": patch
|
||||
"@gradio/build": patch
|
||||
"@gradio/button": patch
|
||||
"@gradio/chatbot": patch
|
||||
"@gradio/core": patch
|
||||
"@gradio/dataframe": patch
|
||||
"@gradio/lite": patch
|
||||
"@gradio/plot": patch
|
||||
"@gradio/spa": patch
|
||||
"@gradio/storybook": patch
|
||||
"@gradio/video": patch
|
||||
"@gradio/wasm": patch
|
||||
"app": patch
|
||||
"gradio": patch
|
||||
"website": patch
|
||||
---
|
||||
|
||||
feat:Initial SSR refactor
|
@ -18,7 +18,7 @@
|
||||
**/.mypy_cache/**
|
||||
!test-strategy.md
|
||||
**/js/_space-test/**
|
||||
../js/app/src/lite/theme.css
|
||||
../js/lite/src/theme.css
|
||||
../js/storybook/theme.css
|
||||
**/gradio_cached_examples/**
|
||||
**/storybook-static/**
|
||||
|
@ -3,5 +3,6 @@
|
||||
"singleQuote": false,
|
||||
"trailingComma": "none",
|
||||
"printWidth": 80,
|
||||
"plugins": ["prettier-plugin-svelte"]
|
||||
"plugins": ["prettier-plugin-svelte"],
|
||||
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ export default [
|
||||
"**/*.spec.ts",
|
||||
"**/*.test.ts",
|
||||
"**/*.node-test.ts",
|
||||
"js/app/test/**/*",
|
||||
"js/spa/test/**/*",
|
||||
"**/*vite.config.ts",
|
||||
"**/_website/**/*",
|
||||
"**/_spaces-test/**/*",
|
||||
|
@ -8,7 +8,7 @@ import kl from "kleur";
|
||||
|
||||
const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
||||
const TEST_APP_PATH = join(__dirname, "./test.py");
|
||||
const TEST_FILES_PATH = join(__dirname, "..", "js", "app", "test");
|
||||
const TEST_FILES_PATH = join(__dirname, "..", "js", "spa", "test");
|
||||
const ROOT = join(__dirname, "..");
|
||||
|
||||
const test_files = readdirSync(TEST_FILES_PATH)
|
||||
|
@ -1,3 +1,3 @@
|
||||
import config from "../js/app/vite.config";
|
||||
import config from "../js/spa/vite.config";
|
||||
|
||||
export default config;
|
||||
|
@ -48,4 +48,4 @@ runs:
|
||||
run: |
|
||||
. venv/bin/activate
|
||||
python -m pip install -U build hatch packaging>=23.2 # packaging>=23.2 is needed to build Lite due to https://github.com/pypa/hatch/issues/1381
|
||||
pnpm --filter @gradio/app build:lite
|
||||
pnpm --filter @gradio/lite build
|
||||
|
2
.github/workflows/test-functional-lite.yml
vendored
@ -53,7 +53,7 @@ jobs:
|
||||
- name: Run Lite E2E tests
|
||||
run: |
|
||||
. venv/bin/activate
|
||||
pnpm --filter @gradio/app test:browser:lite
|
||||
pnpm --filter @gradio/lite test:browser
|
||||
- name: Get the performance result
|
||||
run: |
|
||||
export LITE_APP_LOAD_TIME=$(jq -r '.app_load_time' .lite-perf.json)
|
||||
|
1
.github/workflows/trigger-changeset.yml
vendored
@ -4,6 +4,7 @@ on:
|
||||
types: [opened, synchronize, reopened, edited, labeled, unlabeled]
|
||||
branches:
|
||||
- main
|
||||
- 5.0-dev
|
||||
issue_comment:
|
||||
types: [edited]
|
||||
|
||||
|
5
.gitignore
vendored
@ -8,12 +8,15 @@ __pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
build/
|
||||
!js/build/
|
||||
!js/build/dist/
|
||||
__tmp/*
|
||||
*.pyi
|
||||
!gradio/stubs/**/*.pyi
|
||||
py.typed
|
||||
.ipynb_checkpoints/
|
||||
.python-version
|
||||
=23.2
|
||||
|
||||
# JS build
|
||||
gradio/templates/*
|
||||
@ -38,6 +41,8 @@ coverage.xml
|
||||
test.txt
|
||||
**/snapshots/**/*.png
|
||||
playwright-report/
|
||||
.hypothesis
|
||||
.lite-perf.json
|
||||
|
||||
# Demos
|
||||
demo/tmp.zip
|
||||
|
2
.vscode/settings.json
vendored
@ -21,6 +21,6 @@
|
||||
},
|
||||
"typescript.tsdk": "node_modules/typescript/lib",
|
||||
"i18n-ally.localesPaths": [
|
||||
"js/app/src/lang"
|
||||
"js/spa/src/lang"
|
||||
]
|
||||
}
|
||||
|
49
=23.2
@ -1,49 +0,0 @@
|
||||
Requirement already satisfied: build in ./venv/lib/python3.8/site-packages (1.2.1)
|
||||
Requirement already satisfied: hatch in ./venv/lib/python3.8/site-packages (1.12.0)
|
||||
Requirement already satisfied: packaging in ./venv/lib/python3.8/site-packages (24.1)
|
||||
Requirement already satisfied: pyproject_hooks in ./venv/lib/python3.8/site-packages (from build) (1.0.0)
|
||||
Requirement already satisfied: importlib-metadata>=4.6 in ./venv/lib/python3.8/site-packages (from build) (7.0.1)
|
||||
Requirement already satisfied: tomli>=1.1.0 in ./venv/lib/python3.8/site-packages (from build) (2.0.1)
|
||||
Requirement already satisfied: click>=8.0.6 in ./venv/lib/python3.8/site-packages (from hatch) (8.1.7)
|
||||
Requirement already satisfied: hatchling>=1.24.2 in ./venv/lib/python3.8/site-packages (from hatch) (1.24.2)
|
||||
Requirement already satisfied: httpx>=0.22.0 in ./venv/lib/python3.8/site-packages (from hatch) (0.27.0)
|
||||
Requirement already satisfied: hyperlink>=21.0.0 in ./venv/lib/python3.8/site-packages (from hatch) (21.0.0)
|
||||
Requirement already satisfied: keyring>=23.5.0 in ./venv/lib/python3.8/site-packages (from hatch) (25.2.0)
|
||||
Requirement already satisfied: pexpect~=4.8 in ./venv/lib/python3.8/site-packages (from hatch) (4.8.0)
|
||||
Requirement already satisfied: platformdirs>=2.5.0 in ./venv/lib/python3.8/site-packages (from hatch) (4.2.1)
|
||||
Requirement already satisfied: rich>=11.2.0 in ./venv/lib/python3.8/site-packages (from hatch) (13.7.0)
|
||||
Requirement already satisfied: shellingham>=1.4.0 in ./venv/lib/python3.8/site-packages (from hatch) (1.5.4)
|
||||
Requirement already satisfied: tomli-w>=1.0 in ./venv/lib/python3.8/site-packages (from hatch) (1.0.0)
|
||||
Requirement already satisfied: tomlkit>=0.11.1 in ./venv/lib/python3.8/site-packages (from hatch) (0.12.0)
|
||||
Requirement already satisfied: userpath~=1.7 in ./venv/lib/python3.8/site-packages (from hatch) (1.9.2)
|
||||
Requirement already satisfied: uv>=0.1.35 in ./venv/lib/python3.8/site-packages (from hatch) (0.1.42)
|
||||
Requirement already satisfied: virtualenv>=20.26.1 in ./venv/lib/python3.8/site-packages (from hatch) (20.26.1)
|
||||
Requirement already satisfied: zstandard<1 in ./venv/lib/python3.8/site-packages (from hatch) (0.22.0)
|
||||
Requirement already satisfied: pathspec>=0.10.1 in ./venv/lib/python3.8/site-packages (from hatchling>=1.24.2->hatch) (0.12.1)
|
||||
Requirement already satisfied: pluggy>=1.0.0 in ./venv/lib/python3.8/site-packages (from hatchling>=1.24.2->hatch) (1.0.0)
|
||||
Requirement already satisfied: trove-classifiers in ./venv/lib/python3.8/site-packages (from hatchling>=1.24.2->hatch) (2024.4.10)
|
||||
Requirement already satisfied: anyio in ./venv/lib/python3.8/site-packages (from httpx>=0.22.0->hatch) (3.6.1)
|
||||
Requirement already satisfied: certifi in ./venv/lib/python3.8/site-packages (from httpx>=0.22.0->hatch) (2022.6.15)
|
||||
Requirement already satisfied: httpcore==1.* in ./venv/lib/python3.8/site-packages (from httpx>=0.22.0->hatch) (1.0.5)
|
||||
Requirement already satisfied: idna in ./venv/lib/python3.8/site-packages (from httpx>=0.22.0->hatch) (3.3)
|
||||
Requirement already satisfied: sniffio in ./venv/lib/python3.8/site-packages (from httpx>=0.22.0->hatch) (1.2.0)
|
||||
Requirement already satisfied: h11<0.15,>=0.13 in ./venv/lib/python3.8/site-packages (from httpcore==1.*->httpx>=0.22.0->hatch) (0.14.0)
|
||||
Requirement already satisfied: zipp>=0.5 in ./venv/lib/python3.8/site-packages (from importlib-metadata>=4.6->build) (3.17.0)
|
||||
Requirement already satisfied: jaraco.classes in ./venv/lib/python3.8/site-packages (from keyring>=23.5.0->hatch) (3.4.0)
|
||||
Requirement already satisfied: jaraco.functools in ./venv/lib/python3.8/site-packages (from keyring>=23.5.0->hatch) (4.0.1)
|
||||
Requirement already satisfied: jaraco.context in ./venv/lib/python3.8/site-packages (from keyring>=23.5.0->hatch) (5.3.0)
|
||||
Requirement already satisfied: importlib-resources in ./venv/lib/python3.8/site-packages (from keyring>=23.5.0->hatch) (6.1.1)
|
||||
Requirement already satisfied: SecretStorage>=3.2 in ./venv/lib/python3.8/site-packages (from keyring>=23.5.0->hatch) (3.3.3)
|
||||
Requirement already satisfied: jeepney>=0.4.2 in ./venv/lib/python3.8/site-packages (from keyring>=23.5.0->hatch) (0.8.0)
|
||||
Requirement already satisfied: ptyprocess>=0.5 in ./venv/lib/python3.8/site-packages (from pexpect~=4.8->hatch) (0.7.0)
|
||||
Requirement already satisfied: markdown-it-py>=2.2.0 in ./venv/lib/python3.8/site-packages (from rich>=11.2.0->hatch) (3.0.0)
|
||||
Requirement already satisfied: pygments<3.0.0,>=2.13.0 in ./venv/lib/python3.8/site-packages (from rich>=11.2.0->hatch) (2.17.2)
|
||||
Requirement already satisfied: typing-extensions<5.0,>=4.0.0 in ./venv/lib/python3.8/site-packages (from rich>=11.2.0->hatch) (4.9.0)
|
||||
Requirement already satisfied: distlib<1,>=0.3.7 in ./venv/lib/python3.8/site-packages (from virtualenv>=20.26.1->hatch) (0.3.8)
|
||||
Requirement already satisfied: filelock<4,>=3.12.2 in ./venv/lib/python3.8/site-packages (from virtualenv>=20.26.1->hatch) (3.15.3)
|
||||
Requirement already satisfied: mdurl~=0.1 in ./venv/lib/python3.8/site-packages (from markdown-it-py>=2.2.0->rich>=11.2.0->hatch) (0.1.2)
|
||||
Requirement already satisfied: cryptography>=2.0 in ./venv/lib/python3.8/site-packages (from SecretStorage>=3.2->keyring>=23.5.0->hatch) (42.0.5)
|
||||
Requirement already satisfied: more-itertools in ./venv/lib/python3.8/site-packages (from jaraco.classes->keyring>=23.5.0->hatch) (10.2.0)
|
||||
Requirement already satisfied: backports.tarfile in ./venv/lib/python3.8/site-packages (from jaraco.context->keyring>=23.5.0->hatch) (1.1.1)
|
||||
Requirement already satisfied: cffi>=1.12 in ./venv/lib/python3.8/site-packages (from cryptography>=2.0->SecretStorage>=3.2->keyring>=23.5.0->hatch) (1.16.0)
|
||||
Requirement already satisfied: pycparser in ./venv/lib/python3.8/site-packages (from cffi>=1.12->cryptography>=2.0->SecretStorage>=3.2->keyring>=23.5.0->hatch) (2.22)
|
@ -133,7 +133,7 @@ bash scripts/run_all_tests.sh
|
||||
pnpm test
|
||||
```
|
||||
|
||||
- Browser tests are located in `js/app/test` and are defined as `*spec.ts` files. To run browser tests:
|
||||
- Browser tests are located in `js/spa/test` and are defined as `*spec.ts` files. To run browser tests:
|
||||
|
||||
```
|
||||
pnpm test:browser
|
||||
@ -257,7 +257,7 @@ bash scripts/run_lite.sh
|
||||
|
||||
If you make changes to the Python code during development, you will need to rebuild the Python packages loaded to Graio-Lite. To do this, run:
|
||||
```
|
||||
pnpm --filter @gradio/app pybuild
|
||||
pnpm --filter @gradio/lite pybuild
|
||||
```
|
||||
|
||||
To generate the release build, run:
|
||||
@ -309,7 +309,7 @@ Verify that you've used the correct filename of your gradio app, and that you're
|
||||
|
||||
---
|
||||
|
||||
```ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL @gradio/app@1.0.0 build:local: vite build --mode production:local --emptyOutDir "--emptyOutDir"```
|
||||
```ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL @gradio/spa@1.0.0 build:local: vite build --mode production:local --emptyOutDir "--emptyOutDir"```
|
||||
|
||||
Delete `/node_modules` and `pnpm-lock.yaml`:
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
f7311342c5e04ba58dd320ef66cfecd0
|
@ -1,7 +1,8 @@
|
||||
import { sveltekit } from "@sveltejs/kit/vite";
|
||||
import { defineConfig } from "vite";
|
||||
import { inject_component_loader } from "../app/build_plugins";
|
||||
import { inject_component_loader } from "../build/dist/index.js";
|
||||
|
||||
//@ts-ignore
|
||||
export default defineConfig(({ mode }) => ({
|
||||
plugins: [sveltekit(), inject_component_loader({ mode })]
|
||||
}));
|
||||
|
22
js/app/.gitignore
vendored
@ -1 +1,21 @@
|
||||
/src/lite/theme.css
|
||||
node_modules
|
||||
|
||||
# Output
|
||||
.output
|
||||
.vercel
|
||||
/.svelte-kit
|
||||
/build
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Env
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
!.env.test
|
||||
|
||||
# Vite
|
||||
vite.config.js.timestamp-*
|
||||
vite.config.ts.timestamp-*
|
||||
|
38
js/app/README.md
Normal file
@ -0,0 +1,38 @@
|
||||
# create-svelte
|
||||
|
||||
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).
|
||||
|
||||
## Creating a project
|
||||
|
||||
If you're seeing this, you've probably already done this step. Congrats!
|
||||
|
||||
```bash
|
||||
# create a new project in the current directory
|
||||
npm create svelte@latest
|
||||
|
||||
# create a new project in my-app
|
||||
npm create svelte@latest my-app
|
||||
```
|
||||
|
||||
## Developing
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
## Building
|
||||
|
||||
To create a production version of your app:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
You can preview the production build with `npm run preview`.
|
||||
|
||||
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
|
@ -1,96 +1,26 @@
|
||||
{
|
||||
"name": "@gradio/app",
|
||||
"version": "1.39.2",
|
||||
"name": "app",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite --port 9876",
|
||||
"dev:lite": "run-p dev:lite:*",
|
||||
"dev:lite:self": "vite --port 9876 --mode development:lite",
|
||||
"dev:lite:worker": "pnpm --filter @gradio/wasm dev",
|
||||
"build": "vite build --mode production --emptyOutDir",
|
||||
"cssbuild": "python ../../scripts/generate_theme.py --outfile ./src/lite/theme.css",
|
||||
"pybuild:gradio": "cd ../../ && hatch build -t lite",
|
||||
"pybuild:gradio-client": "cd ../../client/python && python -m build",
|
||||
"pybuild": "run-p pybuild:*",
|
||||
"build:lite": "pnpm pybuild && pnpm cssbuild && pnpm --filter @gradio/client build && pnpm --filter @gradio/wasm build && vite build --mode production:lite",
|
||||
"dev": "vite dev",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"test:snapshot": "pnpm exec playwright test snapshots/ --config=../../.config/playwright.config.js",
|
||||
"test:browser": "pnpm exec playwright test test/ --grep-invert 'reload.spec.ts' --config=../../.config/playwright.config.js",
|
||||
"test:browser:dev": "pnpm exec playwright test test/ --ui --config=../../.config/playwright.config.js",
|
||||
"test:browser:reload": "CI=1 pnpm exec playwright test test/ --grep 'reload.spec.ts' --config=../../.config/playwright.config.js",
|
||||
"test:browser:lite": "GRADIO_E2E_TEST_LITE=1 pnpm test:browser",
|
||||
"test:browser:lite:dev": "GRADIO_E2E_TEST_LITE=1 pnpm test:browser:dev",
|
||||
"build:css": "pollen -c pollen.config.cjs -o src/pollen-dev.css"
|
||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||
"lint": "prettier --check .",
|
||||
"format": "prettier --write ."
|
||||
},
|
||||
"dependencies": {
|
||||
"@gradio/accordion": "workspace:^",
|
||||
"@gradio/annotatedimage": "workspace:^",
|
||||
"@gradio/atoms": "workspace:^",
|
||||
"@gradio/audio": "workspace:^",
|
||||
"@gradio/box": "workspace:^",
|
||||
"@gradio/button": "workspace:^",
|
||||
"@gradio/chatbot": "workspace:^",
|
||||
"@gradio/checkbox": "workspace:^",
|
||||
"@gradio/checkboxgroup": "workspace:^",
|
||||
"@gradio/client": "workspace:^",
|
||||
"@gradio/code": "workspace:^",
|
||||
"@gradio/colorpicker": "workspace:^",
|
||||
"@gradio/column": "workspace:^",
|
||||
"@gradio/dataframe": "workspace:^",
|
||||
"@gradio/dataset": "workspace:^",
|
||||
"@gradio/datetime": "workspace:^",
|
||||
"@gradio/downloadbutton": "workspace:^",
|
||||
"@gradio/dropdown": "workspace:^",
|
||||
"@gradio/fallback": "workspace:^",
|
||||
"@gradio/file": "workspace:^",
|
||||
"@gradio/fileexplorer": "workspace:^",
|
||||
"@gradio/form": "workspace:^",
|
||||
"@gradio/gallery": "workspace:^",
|
||||
"@gradio/group": "workspace:^",
|
||||
"@gradio/highlightedtext": "workspace:^",
|
||||
"@gradio/html": "workspace:^",
|
||||
"@gradio/icons": "workspace:^",
|
||||
"@gradio/image": "workspace:^",
|
||||
"@gradio/imageeditor": "workspace:^",
|
||||
"@gradio/json": "workspace:^",
|
||||
"@gradio/label": "workspace:^",
|
||||
"@gradio/markdown": "workspace:^",
|
||||
"@gradio/model3d": "workspace:^",
|
||||
"@gradio/multimodaltextbox": "workspace:^",
|
||||
"@gradio/nativeplot": "workspace:^",
|
||||
"@gradio/number": "workspace:^",
|
||||
"@gradio/paramviewer": "workspace:^",
|
||||
"@gradio/plot": "workspace:^",
|
||||
"@gradio/radio": "workspace:^",
|
||||
"@gradio/row": "workspace:^",
|
||||
"@gradio/simpledropdown": "workspace:^",
|
||||
"@gradio/simpleimage": "workspace:^",
|
||||
"@gradio/simpletextbox": "workspace:^",
|
||||
"@gradio/slider": "workspace:^",
|
||||
"@gradio/state": "workspace:^",
|
||||
"@gradio/statustracker": "workspace:^",
|
||||
"@gradio/tabitem": "workspace:^",
|
||||
"@gradio/tabs": "workspace:^",
|
||||
"@gradio/textbox": "workspace:^",
|
||||
"@gradio/theme": "workspace:^",
|
||||
"@gradio/timer": "workspace:^",
|
||||
"@gradio/upload": "workspace:^",
|
||||
"@gradio/uploadbutton": "workspace:^",
|
||||
"@gradio/utils": "workspace:^",
|
||||
"@gradio/video": "workspace:^",
|
||||
"@gradio/wasm": "workspace:^",
|
||||
"@huggingface/space-header": "^1.0.3",
|
||||
"@types/eventsource": "^1.1.15",
|
||||
"cross-env": "^7.0.3",
|
||||
"d3-dsv": "^3.0.1",
|
||||
"eventsource": "^2.0.2",
|
||||
"mime-types": "^2.1.34",
|
||||
"postcss": "^8.4.21",
|
||||
"postcss-prefix-selector": "^1.16.0"
|
||||
"devDependencies": {
|
||||
"@sveltejs/adapter-auto": "^3.0.0",
|
||||
"@sveltejs/kit": "^2.0.0",
|
||||
"@sveltejs/vite-plugin-svelte": "^3.0.0",
|
||||
"prettier": "^3.1.1",
|
||||
"prettier-plugin-svelte": "^3.1.2",
|
||||
"svelte": "^4.2.7",
|
||||
"svelte-check": "^3.6.0",
|
||||
"typescript": "^5.0.0",
|
||||
"vite": "^5.0.3"
|
||||
},
|
||||
"msw": {
|
||||
"workerDirectory": "public"
|
||||
},
|
||||
"main_changeset": true
|
||||
"type": "module"
|
||||
}
|
||||
|
13
js/app/src/app.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
// See https://kit.svelte.dev/docs/types#app
|
||||
// for information about these interfaces
|
||||
declare global {
|
||||
namespace App {
|
||||
// interface Error {}
|
||||
// interface Locals {}
|
||||
// interface PageData {}
|
||||
// interface PageState {}
|
||||
// interface Platform {}
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
12
js/app/src/app.html
Normal file
@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
%sveltekit.head%
|
||||
</head>
|
||||
<body data-sveltekit-preload-data="hover">
|
||||
<div style="display: contents">%sveltekit.body%</div>
|
||||
</body>
|
||||
</html>
|
1
js/app/src/lib/index.ts
Normal file
@ -0,0 +1 @@
|
||||
// place files you want to import through the `$lib` alias in this folder.
|
4
js/app/src/routes/+page.svelte
Normal file
@ -0,0 +1,4 @@
|
||||
<h1>Welcome to SvelteKit</h1>
|
||||
<p>
|
||||
Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation
|
||||
</p>
|
BIN
js/app/static/favicon.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
18
js/app/svelte.config.js
Normal file
@ -0,0 +1,18 @@
|
||||
import adapter from "@sveltejs/adapter-auto";
|
||||
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
|
||||
|
||||
/** @type {import('@sveltejs/kit').Config} */
|
||||
const config = {
|
||||
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
|
||||
// for more information about preprocessors
|
||||
preprocess: vitePreprocess(),
|
||||
|
||||
kit: {
|
||||
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
|
||||
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
|
||||
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
|
||||
adapter: adapter()
|
||||
}
|
||||
};
|
||||
|
||||
export default config;
|
20
js/app/tsconfig.json
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"extends": "./.svelte-kit/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"skipLibCheck": true,
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"moduleResolution": "bundler",
|
||||
"module": "esnext"
|
||||
}
|
||||
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
|
||||
// except $lib which is handled by https://kit.svelte.dev/docs/configuration#files
|
||||
//
|
||||
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
|
||||
// from the referenced tsconfig.json - TypeScript does not merge them in
|
||||
}
|
@ -1,217 +1,6 @@
|
||||
import { sveltekit } from "@sveltejs/kit/vite";
|
||||
import { defineConfig } from "vite";
|
||||
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
||||
import sveltePreprocess from "svelte-preprocess";
|
||||
// @ts-ignore
|
||||
import custom_media from "postcss-custom-media";
|
||||
import global_data from "@csstools/postcss-global-data";
|
||||
// @ts-ignore
|
||||
import prefixer from "postcss-prefix-selector";
|
||||
import { readFileSync } from "fs";
|
||||
import { resolve } from "path";
|
||||
|
||||
const version_path = resolve(__dirname, "../../gradio/package.json");
|
||||
const theme_token_path = resolve(__dirname, "../theme/src/tokens.css");
|
||||
const version_raw = JSON.parse(
|
||||
readFileSync(version_path, { encoding: "utf-8" })
|
||||
).version.trim();
|
||||
const version = version_raw.replace(/\./g, "-");
|
||||
|
||||
function convert_to_pypi_prerelease(version: string) {
|
||||
return version.replace(
|
||||
/(\d+\.\d+\.\d+)-([-a-z]+)\.(\d+)/,
|
||||
(match, v, tag, tag_version) => {
|
||||
if (tag === "beta") {
|
||||
return `${v}b${tag_version}`;
|
||||
} else if (tag === "alpha") {
|
||||
return `${v}a${tag_version}`;
|
||||
} else {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const python_version = convert_to_pypi_prerelease(version_raw);
|
||||
|
||||
const client_version_path = resolve(
|
||||
__dirname,
|
||||
"../../client/python/gradio_client/package.json"
|
||||
);
|
||||
const client_version_raw = JSON.parse(
|
||||
readFileSync(client_version_path, {
|
||||
encoding: "utf-8"
|
||||
})
|
||||
).version.trim();
|
||||
|
||||
const client_python_version = convert_to_pypi_prerelease(client_version_raw);
|
||||
|
||||
import {
|
||||
inject_ejs,
|
||||
generate_cdn_entry,
|
||||
generate_dev_entry,
|
||||
handle_ce_css,
|
||||
inject_component_loader,
|
||||
resolve_svelte,
|
||||
mock_modules
|
||||
} from "./build_plugins";
|
||||
|
||||
const GRADIO_VERSION = version_raw || "asd_stub_asd";
|
||||
const CDN_BASE = "https://gradio.s3-us-west-2.amazonaws.com";
|
||||
const TEST_MODE = process.env.TEST_MODE || "happy-dom";
|
||||
|
||||
//@ts-ignore
|
||||
export default defineConfig(({ mode }) => {
|
||||
const targets = {
|
||||
production: "../../gradio/templates/frontend",
|
||||
"dev:custom": "../../gradio/templates/frontend"
|
||||
};
|
||||
const production = mode === "production" || mode === "production:lite";
|
||||
const development = mode === "development" || mode === "development:lite";
|
||||
const is_lite = mode.endsWith(":lite");
|
||||
|
||||
return {
|
||||
base: "./",
|
||||
|
||||
server: {
|
||||
port: 9876,
|
||||
open: is_lite ? "/lite.html" : "/"
|
||||
},
|
||||
|
||||
build: {
|
||||
sourcemap: true,
|
||||
target: "esnext",
|
||||
minify: production,
|
||||
outDir: is_lite ? resolve(__dirname, "../lite/dist") : targets[mode],
|
||||
// To build Gradio-lite as a library, we can't use the library mode
|
||||
// like `lib: is_lite && {}`
|
||||
// because it inevitably enables inlining of all the static file assets,
|
||||
// while we need to disable inlining for the wheel files to pass their URLs to `micropip.install()`.
|
||||
// So we build it as an app and only use the bundled JS and CSS files as library assets, ignoring the HTML file.
|
||||
// See also `lite.ts` about it.
|
||||
rollupOptions: is_lite
|
||||
? {
|
||||
input: "./lite.html",
|
||||
output: {
|
||||
// To use it as a library, we don't add the hash to the file name.
|
||||
entryFileNames: "lite.js",
|
||||
assetFileNames: (file) => {
|
||||
if (file.name?.endsWith(".whl")) {
|
||||
// Python wheel files must follow the naming rules to be installed, so adding a hash to the name is not allowed.
|
||||
return `assets/[name].[ext]`;
|
||||
}
|
||||
if (file.name === "lite.css") {
|
||||
// To use it as a library, we don't add the hash to the file name.
|
||||
return `[name].[ext]`;
|
||||
} else {
|
||||
return `assets/[name]-[hash].[ext]`;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
: {
|
||||
external: ["./svelte/svelte.js"],
|
||||
makeAbsoluteExternalsRelative: false
|
||||
}
|
||||
},
|
||||
|
||||
define: {
|
||||
BUILD_MODE: production ? JSON.stringify("prod") : JSON.stringify("dev"),
|
||||
BACKEND_URL: production
|
||||
? JSON.stringify("")
|
||||
: JSON.stringify("http://localhost:7860/"),
|
||||
GRADIO_VERSION: JSON.stringify(version)
|
||||
},
|
||||
css: {
|
||||
postcss: {
|
||||
plugins: [
|
||||
prefixer({
|
||||
prefix: `.gradio-container-${version}`,
|
||||
// @ts-ignore
|
||||
transform(prefix, selector, prefixedSelector, fileName) {
|
||||
if (selector.indexOf("gradio-container") > -1) {
|
||||
return prefix;
|
||||
} else if (
|
||||
selector.indexOf(":root") > -1 ||
|
||||
selector.indexOf("dark") > -1 ||
|
||||
selector.indexOf("body") > -1 ||
|
||||
fileName.indexOf(".svelte") > -1
|
||||
) {
|
||||
return selector;
|
||||
} else if (
|
||||
// For the custom element <gradio-lite>. See theme/src/global.css for the details.
|
||||
/^gradio-lite(\:[^\:]+)?/.test(selector)
|
||||
) {
|
||||
return selector;
|
||||
}
|
||||
return prefixedSelector;
|
||||
}
|
||||
}),
|
||||
custom_media()
|
||||
]
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
resolve_svelte(development && !is_lite),
|
||||
|
||||
svelte({
|
||||
inspector: false,
|
||||
compilerOptions: {
|
||||
dev: true,
|
||||
discloseVersion: false,
|
||||
accessors: true
|
||||
},
|
||||
hot: !process.env.VITEST && !production,
|
||||
preprocess: sveltePreprocess({
|
||||
postcss: {
|
||||
plugins: [
|
||||
global_data({ files: [theme_token_path] }),
|
||||
custom_media()
|
||||
]
|
||||
}
|
||||
})
|
||||
}),
|
||||
generate_dev_entry({
|
||||
enable:
|
||||
!development &&
|
||||
!is_lite && // At the moment of https://github.com/gradio-app/gradio/pull/6398, I skipped to make Gradio-lite work custom component. Will do it, and remove this condition.
|
||||
mode !== "test"
|
||||
}),
|
||||
inject_ejs(),
|
||||
generate_cdn_entry({ version: GRADIO_VERSION, cdn_base: CDN_BASE }),
|
||||
handle_ce_css(),
|
||||
inject_component_loader({ mode }),
|
||||
mode === "test" && mock_modules()
|
||||
],
|
||||
optimizeDeps: {
|
||||
exclude: ["@ffmpeg/ffmpeg", "@ffmpeg/util"]
|
||||
},
|
||||
test: {
|
||||
setupFiles: [resolve(__dirname, "../../.config/setup_vite_tests.ts")],
|
||||
environment: TEST_MODE,
|
||||
include:
|
||||
TEST_MODE === "node"
|
||||
? ["**/*.node-test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"]
|
||||
: ["**/*.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
|
||||
exclude: ["**/node_modules/**", "**/gradio/gradio/**"],
|
||||
globals: true,
|
||||
onConsoleLog(log, type) {
|
||||
if (log.includes("was created with unknown prop")) return false;
|
||||
}
|
||||
},
|
||||
|
||||
resolve: {
|
||||
alias: {
|
||||
// For the Wasm app to import the wheel file URLs.
|
||||
"gradio.whl": resolve(
|
||||
__dirname,
|
||||
`../../dist-lite/gradio-${python_version}-py3-none-any.whl`
|
||||
),
|
||||
"gradio_client.whl": resolve(
|
||||
__dirname,
|
||||
`../../client/python/dist/gradio_client-${client_python_version}-py3-none-any.whl`
|
||||
)
|
||||
}
|
||||
},
|
||||
assetsInclude: ["**/*.whl"] // To pass URLs of built wheel files to the Wasm worker.
|
||||
};
|
||||
export default defineConfig({
|
||||
plugins: [sveltekit()]
|
||||
});
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { test, describe, assert, afterEach, vi } from "vitest";
|
||||
import { test, describe, assert, afterEach } from "vitest";
|
||||
import { cleanup, render } from "@gradio/tootils";
|
||||
import Audio from "./";
|
||||
import type { LoadingStatus } from "@gradio/statustracker";
|
||||
import { setupi18n } from "../app/src/i18n";
|
||||
import { setupi18n } from "../core/src/i18n";
|
||||
import ResizeObserver from "resize-observer-polyfill";
|
||||
|
||||
global.ResizeObserver = ResizeObserver;
|
||||
|
@ -7,7 +7,7 @@
|
||||
import AudioPlayer from "../player/AudioPlayer.svelte";
|
||||
|
||||
import type { IBlobEvent, IMediaRecorder } from "extendable-media-recorder";
|
||||
import type { I18nFormatter } from "js/app/src/gradio_helper";
|
||||
import type { I18nFormatter } from "js/core/src/gradio_helper";
|
||||
import AudioRecorder from "../recorder/AudioRecorder.svelte";
|
||||
import StreamAudio from "../streaming/StreamAudio.svelte";
|
||||
import { SelectSource } from "@gradio/atoms";
|
||||
|
3
js/build/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# `@gradio/build`
|
||||
|
||||
Build utilities for the gradio frontend + lite.
|
316
js/build/dist/index.js
vendored
Normal file
@ -0,0 +1,316 @@
|
||||
// src/index.ts
|
||||
import { parse } from "node-html-parser";
|
||||
import { join } from "path";
|
||||
import { writeFileSync } from "fs";
|
||||
import * as url from "url";
|
||||
import { readdirSync, existsSync, readFileSync, statSync } from "fs";
|
||||
function inject_ejs() {
|
||||
return {
|
||||
name: "inject-ejs",
|
||||
enforce: "post",
|
||||
transformIndexHtml: (html) => {
|
||||
const replace_gradio_info_info_html = html.replace(
|
||||
/%gradio_api_info%/,
|
||||
`<script>window.gradio_api_info = {{ gradio_api_info | toorjson }};</script>`
|
||||
);
|
||||
return replace_gradio_info_info_html.replace(
|
||||
/%gradio_config%/,
|
||||
`<script>window.gradio_config = {{ config | toorjson }};</script>`
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
function generate_cdn_entry({
|
||||
version,
|
||||
cdn_base
|
||||
}) {
|
||||
return {
|
||||
name: "generate-cdn-entry",
|
||||
enforce: "post",
|
||||
writeBundle(config, bundle) {
|
||||
if (!config.dir || !bundle["index.html"] || bundle["index.html"].type !== "asset")
|
||||
return;
|
||||
const source = bundle["index.html"].source;
|
||||
const tree = parse(source);
|
||||
const script = Array.from(
|
||||
tree.querySelectorAll("script[type=module]")
|
||||
).find((node) => node.attributes.src?.includes("assets"));
|
||||
const output_location = join(config.dir, "gradio.js");
|
||||
writeFileSync(output_location, make_entry(script?.attributes.src || ""));
|
||||
if (!script) return;
|
||||
const transformed_html = bundle["index.html"].source.substring(0, script?.range[0]) + `<script type="module" crossorigin src="${cdn_base}/${version}/gradio.js"></script>` + bundle["index.html"].source.substring(
|
||||
script?.range[1],
|
||||
source.length
|
||||
);
|
||||
const share_html_location = join(config.dir, "share.html");
|
||||
writeFileSync(share_html_location, transformed_html);
|
||||
}
|
||||
};
|
||||
}
|
||||
var RE_SVELTE_IMPORT = /import\s+([\w*{},\s]+)\s+from\s+['"](svelte|svelte\/internal)['"]/g;
|
||||
function generate_dev_entry({ enable }) {
|
||||
return {
|
||||
name: "generate-dev-entry",
|
||||
transform(code, id) {
|
||||
if (!enable) return;
|
||||
const new_code = code.replace(RE_SVELTE_IMPORT, (str, $1, $2) => {
|
||||
return `const ${$1.replace(/\* as /, "").replace(/ as /g, ": ")} = window.__gradio__svelte__internal;`;
|
||||
});
|
||||
return {
|
||||
code: new_code,
|
||||
map: null
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
function make_entry(script) {
|
||||
return `import("${script}");
|
||||
`;
|
||||
}
|
||||
function handle_ce_css() {
|
||||
return {
|
||||
enforce: "post",
|
||||
name: "custom-element-css",
|
||||
writeBundle(config, bundle) {
|
||||
let file_to_insert = {
|
||||
filename: "",
|
||||
source: ""
|
||||
};
|
||||
if (!config.dir || !bundle["index.html"] || bundle["index.html"].type !== "asset")
|
||||
return;
|
||||
for (const key in bundle) {
|
||||
const chunk = bundle[key];
|
||||
if (chunk.type === "chunk") {
|
||||
const _chunk = chunk;
|
||||
const found = _chunk.code?.indexOf("ENTRY_CSS");
|
||||
if (found > -1)
|
||||
file_to_insert = {
|
||||
filename: join(config.dir, key),
|
||||
source: _chunk.code
|
||||
};
|
||||
}
|
||||
}
|
||||
const tree = parse(bundle["index.html"].source);
|
||||
const { style, fonts } = Array.from(
|
||||
tree.querySelectorAll("link[rel=stylesheet]")
|
||||
).reduce(
|
||||
(acc, next) => {
|
||||
if (/.*\/index(.*?)\.css/.test(next.attributes.href)) {
|
||||
return { ...acc, style: next };
|
||||
}
|
||||
return { ...acc, fonts: [...acc.fonts, next.attributes.href] };
|
||||
},
|
||||
{ fonts: [], style: void 0 }
|
||||
);
|
||||
writeFileSync(
|
||||
file_to_insert.filename,
|
||||
file_to_insert.source.replace("__ENTRY_CSS__", style.attributes.href).replace(
|
||||
'"__FONTS_CSS__"',
|
||||
`[${fonts.map((f) => `"${f}"`).join(",")}]`
|
||||
)
|
||||
);
|
||||
const share_html_location = join(config.dir, "share.html");
|
||||
const share_html = readFileSync(share_html_location, "utf8");
|
||||
const share_tree = parse(share_html);
|
||||
const node = Array.from(
|
||||
share_tree.querySelectorAll("link[rel=stylesheet]")
|
||||
).find((node2) => /.*\/index(.*?)\.css/.test(node2.attributes.href));
|
||||
if (!node) return;
|
||||
const transformed_html = share_html.substring(0, node.range[0]) + share_html.substring(node.range[1], share_html.length);
|
||||
writeFileSync(share_html_location, transformed_html);
|
||||
}
|
||||
};
|
||||
}
|
||||
var __filename = url.fileURLToPath(import.meta.url);
|
||||
var __dirname = url.fileURLToPath(new URL(".", import.meta.url));
|
||||
function get_export_path(path, root, pkg_json) {
|
||||
if (!pkg_json.exports) return void 0;
|
||||
const _path = join(root, "..", `${pkg_json.exports[`${path}`]}`);
|
||||
return existsSync(_path) ? _path : void 0;
|
||||
}
|
||||
var ignore_list = [
|
||||
"tootils",
|
||||
"_cdn-test",
|
||||
"_spaces-test",
|
||||
"_website",
|
||||
"app",
|
||||
"atoms",
|
||||
"fallback",
|
||||
"icons",
|
||||
"lite",
|
||||
"preview",
|
||||
"simpledropdown",
|
||||
"simpleimage",
|
||||
"simpletextbox",
|
||||
"storybook",
|
||||
"theme",
|
||||
"timeseries",
|
||||
"tooltip",
|
||||
"upload",
|
||||
"utils",
|
||||
"wasm"
|
||||
];
|
||||
function generate_component_imports() {
|
||||
const exports = readdirSync(join(__dirname, "..", "..")).map((dir) => {
|
||||
if (ignore_list.includes(dir)) return void 0;
|
||||
if (!statSync(join(__dirname, "..", "..", dir)).isDirectory()) return void 0;
|
||||
const package_json_path = join(__dirname, "..", "..", dir, "package.json");
|
||||
if (existsSync(package_json_path)) {
|
||||
const package_json = JSON.parse(
|
||||
readFileSync(package_json_path, "utf8")
|
||||
);
|
||||
const component = get_export_path(".", package_json_path, package_json);
|
||||
const example = get_export_path(
|
||||
"./example",
|
||||
package_json_path,
|
||||
package_json
|
||||
);
|
||||
const base = get_export_path("./base", package_json_path, package_json);
|
||||
if (!component && !example) return void 0;
|
||||
return {
|
||||
name: package_json.name,
|
||||
component,
|
||||
example,
|
||||
base
|
||||
};
|
||||
}
|
||||
return void 0;
|
||||
}).filter((x) => x !== void 0);
|
||||
const imports = exports.reduce((acc, _export) => {
|
||||
if (!_export) return acc;
|
||||
const example = _export.example ? `example: () => import("${_export.name}/example"),
|
||||
` : "";
|
||||
const base = _export.base ? `base: () => import("${_export.name}/base"),
|
||||
` : "";
|
||||
return `${acc}"${_export.name.replace("@gradio/", "")}": {
|
||||
${base}
|
||||
${example}
|
||||
component: () => import("${_export.name}")
|
||||
},
|
||||
`;
|
||||
}, "");
|
||||
return imports;
|
||||
}
|
||||
function load_virtual_component_loader(mode) {
|
||||
const loader_path = join(__dirname, "component_loader.js");
|
||||
let component_map = "";
|
||||
if (mode === "test") {
|
||||
component_map = `
|
||||
const component_map = {
|
||||
"test-component-one": {
|
||||
component: () => import("@gradio-test/test-one"),
|
||||
example: () => import("@gradio-test/test-one/example")
|
||||
},
|
||||
"dataset": {
|
||||
component: () => import("@gradio-test/test-two"),
|
||||
example: () => import("@gradio-test/test-two/example")
|
||||
},
|
||||
"image": {
|
||||
component: () => import("@gradio/image"),
|
||||
example: () => import("@gradio/image/example"),
|
||||
base: () => import("@gradio/image/base")
|
||||
},
|
||||
"audio": {
|
||||
component: () => import("@gradio/audio"),
|
||||
example: () => import("@gradio/audio/example"),
|
||||
base: () => import("@gradio/audio/base")
|
||||
},
|
||||
"video": {
|
||||
component: () => import("@gradio/video"),
|
||||
example: () => import("@gradio/video/example"),
|
||||
base: () => import("@gradio/video/base")
|
||||
},
|
||||
// "test-component-one": {
|
||||
// component: () => import("@gradio-test/test-one"),
|
||||
// example: () => import("@gradio-test/test-one/example")
|
||||
// },
|
||||
};
|
||||
`;
|
||||
} else {
|
||||
component_map = `
|
||||
const component_map = {
|
||||
${generate_component_imports()}
|
||||
};
|
||||
`;
|
||||
}
|
||||
return `${component_map}
|
||||
|
||||
${readFileSync(loader_path, "utf8")}`;
|
||||
}
|
||||
function inject_component_loader({ mode }) {
|
||||
const v_id = "virtual:component-loader";
|
||||
const resolved_v_id = "\0" + v_id;
|
||||
return {
|
||||
name: "inject-component-loader",
|
||||
enforce: "pre",
|
||||
resolveId(id) {
|
||||
if (id === v_id) return resolved_v_id;
|
||||
},
|
||||
load(id) {
|
||||
this.addWatchFile(join(__dirname, "component_loader.js"));
|
||||
if (id === resolved_v_id) {
|
||||
return load_virtual_component_loader(mode);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
function resolve_svelte(enable) {
|
||||
return {
|
||||
enforce: "pre",
|
||||
name: "resolve-svelte",
|
||||
async resolveId(id) {
|
||||
if (!enable) return;
|
||||
if (id === "./svelte/svelte.js" || id === "svelte" || id === "svelte/internal") {
|
||||
const mod = join(
|
||||
__dirname,
|
||||
"..",
|
||||
"..",
|
||||
"gradio",
|
||||
"templates",
|
||||
"frontend",
|
||||
"assets",
|
||||
"svelte",
|
||||
"svelte.js"
|
||||
);
|
||||
return { id: mod, external: "absolute" };
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
function mock_modules() {
|
||||
const v_id_1 = "@gradio-test/test-one";
|
||||
const v_id_2 = "@gradio-test/test-two";
|
||||
const v_id_1_example = "@gradio-test/test-one/example";
|
||||
const v_id_2_example = "@gradio-test/test-two/example";
|
||||
const resolved_v_id = "\0" + v_id_1;
|
||||
const resolved_v_id_2 = "\0" + v_id_2;
|
||||
const resolved_v_id_1_example = "\0" + v_id_1_example;
|
||||
const resolved_v_id_2_example = "\0" + v_id_2_example;
|
||||
const fallback_example = "@gradio/fallback/example";
|
||||
const resolved_fallback_example = "\0" + fallback_example;
|
||||
return {
|
||||
name: "mock-modules",
|
||||
enforce: "pre",
|
||||
resolveId(id) {
|
||||
if (id === v_id_1) return resolved_v_id;
|
||||
if (id === v_id_2) return resolved_v_id_2;
|
||||
if (id === v_id_1_example) return resolved_v_id_1_example;
|
||||
if (id === v_id_2_example) return resolved_v_id_2_example;
|
||||
if (id === fallback_example) return resolved_fallback_example;
|
||||
},
|
||||
load(id) {
|
||||
if (id === resolved_v_id || id === resolved_v_id_2 || id === resolved_v_id_1_example || id === resolved_v_id_2_example || id === resolved_fallback_example) {
|
||||
return `export default {}`;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
export {
|
||||
generate_cdn_entry,
|
||||
generate_dev_entry,
|
||||
handle_ce_css,
|
||||
inject_component_loader,
|
||||
inject_ejs,
|
||||
mock_modules,
|
||||
resolve_svelte
|
||||
};
|
19
js/build/package.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "@gradio/build",
|
||||
"version": "0.0.1",
|
||||
"description": "Gradio UI packages",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"private": "true",
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"scripts": {
|
||||
"build": "esbuild src/index.ts --platform=node --format=esm --target=node18 --bundle --packages=external --outfile=dist/index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@gradio/theme": "workspace:^",
|
||||
"esbuild": "^0.21.0",
|
||||
"svelte-i18n": "^3.6.0"
|
||||
},
|
||||
"main_changeset": true
|
||||
}
|
81
js/build/src/component_loader.js
Normal file
@ -0,0 +1,81 @@
|
||||
// @ts-nocheck
|
||||
|
||||
const request_map = {};
|
||||
|
||||
export function load_component({ api_url, name, id, variant }) {
|
||||
const comps = window.__GRADIO__CC__;
|
||||
|
||||
const _component_map = {
|
||||
// eslint-disable-next-line no-undef
|
||||
...component_map,
|
||||
...(!comps ? {} : comps)
|
||||
};
|
||||
|
||||
let _id = id || name;
|
||||
|
||||
if (request_map[`${_id}-${variant}`]) {
|
||||
return { component: request_map[`${_id}-${variant}`], name };
|
||||
}
|
||||
try {
|
||||
if (!_component_map?.[_id]?.[variant] && !_component_map?.[name]?.[variant])
|
||||
throw new Error();
|
||||
|
||||
request_map[`${_id}-${variant}`] = (
|
||||
_component_map?.[_id]?.[variant] || // for dev mode custom components
|
||||
_component_map?.[name]?.[variant]
|
||||
)();
|
||||
|
||||
return {
|
||||
name,
|
||||
component: request_map[`${_id}-${variant}`]
|
||||
};
|
||||
} catch (e) {
|
||||
if (!_id) throw new Error(`Component not found: ${name}`);
|
||||
try {
|
||||
request_map[`${_id}-${variant}`] = get_component_with_css(
|
||||
api_url,
|
||||
_id,
|
||||
variant
|
||||
);
|
||||
|
||||
return {
|
||||
name,
|
||||
component: request_map[`${_id}-${variant}`]
|
||||
};
|
||||
} catch (e) {
|
||||
if (variant === "example") {
|
||||
request_map[`${_id}-${variant}`] = import("@gradio/fallback/example");
|
||||
|
||||
return {
|
||||
name,
|
||||
component: request_map[`${_id}-${variant}`]
|
||||
};
|
||||
}
|
||||
console.error(`failed to load: ${name}`);
|
||||
console.error(e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function load_css(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const link = document.createElement("link");
|
||||
link.rel = "stylesheet";
|
||||
link.href = url;
|
||||
document.head.appendChild(link);
|
||||
link.onload = () => resolve();
|
||||
link.onerror = () => reject();
|
||||
});
|
||||
}
|
||||
|
||||
function get_component_with_css(api_url, id, variant) {
|
||||
return Promise.all([
|
||||
load_css(`${api_url}/custom_component/${id}/${variant}/style.css`),
|
||||
import(
|
||||
/* @vite-ignore */ `${api_url}/custom_component/${id}/${variant}/index.js`
|
||||
)
|
||||
]).then(([_, module]) => {
|
||||
return module;
|
||||
});
|
||||
}
|
@ -213,12 +213,12 @@ const ignore_list = [
|
||||
"wasm"
|
||||
];
|
||||
function generate_component_imports(): string {
|
||||
const exports = readdirSync(join(__dirname, ".."))
|
||||
const exports = readdirSync(join(__dirname, "..", ".."))
|
||||
.map((dir) => {
|
||||
if (ignore_list.includes(dir)) return undefined;
|
||||
if (!statSync(join(__dirname, "..", dir)).isDirectory()) return undefined;
|
||||
if (!statSync(join(__dirname, "..","..", dir)).isDirectory()) return undefined;
|
||||
|
||||
const package_json_path = join(__dirname, "..", dir, "package.json");
|
||||
const package_json_path = join(__dirname, "..","..", dir, "package.json");
|
||||
if (existsSync(package_json_path)) {
|
||||
const package_json = JSON.parse(
|
||||
readFileSync(package_json_path, "utf8")
|
||||
@ -246,6 +246,7 @@ function generate_component_imports(): string {
|
||||
})
|
||||
.filter((x) => x !== undefined);
|
||||
|
||||
|
||||
const imports = exports.reduce((acc, _export) => {
|
||||
if (!_export) return acc;
|
||||
|
2
js/button/main.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export { default as default } from "./Index.svelte";
|
||||
export { default as BaseButton } from "./shared/Button.svelte";
|
@ -20,7 +20,7 @@
|
||||
import type { MessageRole } from "../types";
|
||||
import { MarkdownCode as Markdown } from "@gradio/markdown";
|
||||
import type { FileData, Client } from "@gradio/client";
|
||||
import type { I18nFormatter } from "js/app/src/gradio_helper";
|
||||
import type { I18nFormatter } from "js/core/src/gradio_helper";
|
||||
import Pending from "./Pending.svelte";
|
||||
import MessageBox from "./MessageBox.svelte";
|
||||
|
||||
@ -29,7 +29,8 @@
|
||||
|
||||
import Component from "./Component.svelte";
|
||||
import LikeButtons from "./ButtonPanel.svelte";
|
||||
import type { LoadedComponent } from "../../app/src/types";
|
||||
import type { LoadedComponent } from "../../core/src/types";
|
||||
|
||||
import CopyAll from "./CopyAll.svelte";
|
||||
|
||||
export let _fetch: typeof fetch;
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { test, describe, assert, afterEach, vi } from "vitest";
|
||||
import { cleanup, render } from "@gradio/tootils";
|
||||
import event from "@testing-library/user-event";
|
||||
import { setupi18n } from "../app/src/i18n";
|
||||
import { setupi18n } from "../core/src/i18n";
|
||||
|
||||
import CheckboxGroup from "./Index.svelte";
|
||||
import type { LoadingStatus } from "@gradio/statustracker";
|
||||
|
1
js/core/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/src/lite/theme.css
|
1
js/core/blocks.ts
Normal file
@ -0,0 +1 @@
|
||||
export { default as default } from "./src/Blocks.svelte";
|
4
js/core/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export { default as Embed } from "./src/Embed.svelte";
|
||||
export { prefix_css, mount_css } from "./src/css";
|
||||
export * from "./src/i18n";
|
||||
export * from "./src/types";
|
1
js/core/login.ts
Normal file
@ -0,0 +1 @@
|
||||
export { default as default } from "./src/Login.svelte";
|
78
js/core/package.json
Normal file
@ -0,0 +1,78 @@
|
||||
{
|
||||
"name": "@gradio/core",
|
||||
"version": "0.0.1",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@gradio/accordion": "workspace:^",
|
||||
"@gradio/annotatedimage": "workspace:^",
|
||||
"@gradio/atoms": "workspace:^",
|
||||
"@gradio/audio": "workspace:^",
|
||||
"@gradio/box": "workspace:^",
|
||||
"@gradio/button": "workspace:^",
|
||||
"@gradio/chatbot": "workspace:^",
|
||||
"@gradio/checkbox": "workspace:^",
|
||||
"@gradio/checkboxgroup": "workspace:^",
|
||||
"@gradio/client": "workspace:^",
|
||||
"@gradio/code": "workspace:^",
|
||||
"@gradio/colorpicker": "workspace:^",
|
||||
"@gradio/column": "workspace:^",
|
||||
"@gradio/dataframe": "workspace:^",
|
||||
"@gradio/dataset": "workspace:^",
|
||||
"@gradio/datetime": "workspace:^",
|
||||
"@gradio/downloadbutton": "workspace:^",
|
||||
"@gradio/dropdown": "workspace:^",
|
||||
"@gradio/fallback": "workspace:^",
|
||||
"@gradio/file": "workspace:^",
|
||||
"@gradio/fileexplorer": "workspace:^",
|
||||
"@gradio/form": "workspace:^",
|
||||
"@gradio/gallery": "workspace:^",
|
||||
"@gradio/group": "workspace:^",
|
||||
"@gradio/highlightedtext": "workspace:^",
|
||||
"@gradio/html": "workspace:^",
|
||||
"@gradio/icons": "workspace:^",
|
||||
"@gradio/image": "workspace:^",
|
||||
"@gradio/imageeditor": "workspace:^",
|
||||
"@gradio/json": "workspace:^",
|
||||
"@gradio/label": "workspace:^",
|
||||
"@gradio/markdown": "workspace:^",
|
||||
"@gradio/model3d": "workspace:^",
|
||||
"@gradio/multimodaltextbox": "workspace:^",
|
||||
"@gradio/nativeplot": "workspace:^",
|
||||
"@gradio/number": "workspace:^",
|
||||
"@gradio/paramviewer": "workspace:^",
|
||||
"@gradio/plot": "workspace:^",
|
||||
"@gradio/radio": "workspace:^",
|
||||
"@gradio/row": "workspace:^",
|
||||
"@gradio/simpledropdown": "workspace:^",
|
||||
"@gradio/simpleimage": "workspace:^",
|
||||
"@gradio/simpletextbox": "workspace:^",
|
||||
"@gradio/slider": "workspace:^",
|
||||
"@gradio/state": "workspace:^",
|
||||
"@gradio/statustracker": "workspace:^",
|
||||
"@gradio/tabitem": "workspace:^",
|
||||
"@gradio/tabs": "workspace:^",
|
||||
"@gradio/textbox": "workspace:^",
|
||||
"@gradio/theme": "workspace:^",
|
||||
"@gradio/timer": "workspace:^",
|
||||
"@gradio/upload": "workspace:^",
|
||||
"@gradio/uploadbutton": "workspace:^",
|
||||
"@gradio/utils": "workspace:^",
|
||||
"@gradio/video": "workspace:^",
|
||||
"@gradio/wasm": "workspace:^"
|
||||
},
|
||||
"msw": {
|
||||
"workerDirectory": "public"
|
||||
},
|
||||
"main_changeset": true,
|
||||
"exports": {
|
||||
"./blocks": {
|
||||
"svelte": "./src/Blocks.svelte"
|
||||
},
|
||||
"./login": {
|
||||
"svelte": "./src/Login.svelte"
|
||||
},
|
||||
"./package.json": "./package.json",
|
||||
".": "./index.ts"
|
||||
},
|
||||
"main": "./index.ts"
|
||||
}
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 349 B After Width: | Height: | Size: 349 B |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 742 B After Width: | Height: | Size: 742 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.5 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 767 B After Width: | Height: | Size: 767 B |
@ -2,7 +2,7 @@
|
||||
import { createEventDispatcher } from "svelte";
|
||||
import api_logo from "./img/api-logo.svg";
|
||||
import Clear from "./img/clear.svelte";
|
||||
import Button from "../../../button/shared/Button.svelte";
|
||||
import { BaseButton } from "@gradio/button";
|
||||
|
||||
export let root: string;
|
||||
export let api_count: number;
|
||||
@ -19,7 +19,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<span class="counts">
|
||||
<Button
|
||||
<BaseButton
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
elem_id="start-api-recorder"
|
||||
@ -27,7 +27,7 @@
|
||||
>
|
||||
<div class="loading-dot self-baseline"></div>
|
||||
<p class="self-baseline btn-text">API Recorder</p>
|
||||
</Button>
|
||||
</BaseButton>
|
||||
<p>
|
||||
<span class="url">{api_count}</span> API endpoint{#if api_count > 1}s{/if}<br
|
||||
/>
|
@ -54,7 +54,8 @@
|
||||
class="highlight">import</span
|
||||
> Client{#if has_file_path}, handle_file{/if}
|
||||
|
||||
client = Client(<span class="token string">"{space_id || root}"</span>{#if username !== null}, auth=("{username}", **password**){/if})
|
||||
client = Client(<span class="token string">"{space_id || root}"</span
|
||||
>{#if username !== null}, auth=("{username}", **password**){/if})
|
||||
result = client.<span class="highlight">predict</span
|
||||
>(<!--
|
||||
-->{#each endpoint_parameters as { python_type, example_input, parameter_name, parameter_has_default, parameter_default }, i}<!--
|
||||
@ -104,8 +105,7 @@ const result = await client.predict({#if named}<span class="api-name"
|
||||
class="example-inputs"
|
||||
>{parameter_name}: example{component}</span
|
||||
>, <!--
|
||||
--><span class="desc"
|
||||
><!--
|
||||
--><span class="desc"><!--
|
||||
--></span
|
||||
><!--
|
||||
-->{:else}<!--
|
||||
@ -137,8 +137,12 @@ console.log(result.data);
|
||||
<div bind:this={bash_post_code}>
|
||||
<pre>curl -X POST {root}call/{dependency.api_name} -s -H "Content-Type: application/json" -d '{"{"}
|
||||
"data": [{#each endpoint_parameters as { label, parameter_name, type, python_type, component, example_input, serializer }, i}
|
||||
<!--
|
||||
-->{represent_value(example_input, python_type.type, "bash")}{#if i < endpoint_parameters.length - 1},
|
||||
<!--
|
||||
-->{represent_value(
|
||||
example_input,
|
||||
python_type.type,
|
||||
"bash"
|
||||
)}{#if i < endpoint_parameters.length - 1},
|
||||
{/if}
|
||||
{/each}
|
||||
]{"}"}' \
|
@ -134,7 +134,8 @@
|
||||
class="highlight">import</span
|
||||
> Client, file
|
||||
|
||||
client = Client(<span class="token string">"{short_root}"</span>{#if username !== null}, auth=("{username}", **password**){/if})
|
||||
client = Client(<span class="token string">"{short_root}"</span
|
||||
>{#if username !== null}, auth=("{username}", **password**){/if})
|
||||
{#each py_zipped as { call, api_name }}<!--
|
||||
-->
|
||||
client.<span class="highlight"
|
||||
@ -156,9 +157,11 @@ const app = await Client.connect(<span class="token string">"{short_root}"</span
|
||||
>{#if username !== null}, {auth: ["{username}", **password**]}{/if});
|
||||
{#each js_zipped as { call, api_name }}<!--
|
||||
-->
|
||||
await client.predict(<span class="api-name">
|
||||
await client.predict(<span
|
||||
class="api-name">
|
||||
"/{api_name}"</span
|
||||
>{#if call}, {/if}{call});
|
||||
>{#if call},
|
||||
{/if}{call});
|
||||
{/each}</pre>
|
||||
</div>
|
||||
</code>
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 749 B After Width: | Height: | Size: 749 B |
Before Width: | Height: | Size: 742 B After Width: | Height: | Size: 742 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 545 B After Width: | Height: | Size: 545 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 483 B After Width: | Height: | Size: 483 B |
Before Width: | Height: | Size: 715 B After Width: | Height: | Size: 715 B |
@ -6,6 +6,6 @@ To add your language, do the following steps:
|
||||
|
||||
1. Create a new json file in this directory
|
||||
2. Name the file after the language code (Here's a list: http://4umi.com/web/html/languagecodes.php)
|
||||
3. Please provide clear and complete translations. Take a look at the [`en.json`](https://github.com/gradio-app/gradio/blob/master/js/app/public/lang/en.json) file for the corresponding English text.
|
||||
3. Please provide clear and complete translations. Take a look at the [`en.json`](https://github.com/gradio-app/gradio/blob/master/js/core/public/lang/en.json) file for the corresponding English text.
|
||||
|
||||
That's it!
|