gradio-pr-bot commited on
Commit
8d29da4
·
verified ·
1 Parent(s): 83e3d99

Upload folder using huggingface_hub

Browse files
6.25.0/preview/package.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/preview",
3
+ "version": "0.17.0",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "author": "",
8
+ "license": "ISC",
9
+ "private": false,
10
+ "scripts": {
11
+ "build": "vite build --ssr"
12
+ },
13
+ "dependencies": {
14
+ "@sveltejs/vite-plugin-svelte": "^7.0.0",
15
+ "@types/which": "^3.0.4",
16
+ "rollup": "^4.59.0",
17
+ "svelte-preprocess": "^6.0.3",
18
+ "typescript": "^5.9.3",
19
+ "vite": "^8.0.9"
20
+ },
21
+ "exports": {
22
+ ".": {
23
+ "default": "./dist/index.js",
24
+ "import": "./dist/index.js",
25
+ "gradio": "./src/index.ts",
26
+ "svelte": "./dist/src/index.js",
27
+ "types": "./dist/index.d.ts"
28
+ },
29
+ "./package.json": "./package.json"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/gradio-app/gradio.git",
34
+ "directory": "js/preview"
35
+ }
36
+ }
6.25.0/preview/src/_deepmerge_internal.ts ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // this is a copy of the deepemerge source code but with an esm interface rather than commonjs
2
+
3
+ export const deepmerge = `
4
+ function isMergeableObject(value) {
5
+ return isNonNullObject(value)
6
+ && !isSpecial(value)
7
+ }
8
+
9
+ function isNonNullObject(value) {
10
+ return !!value && typeof value === 'object'
11
+ }
12
+
13
+ function isSpecial(value) {
14
+ var stringValue = Object.prototype.toString.call(value)
15
+
16
+ return stringValue === '[object RegExp]'
17
+ || stringValue === '[object Date]'
18
+ || isReactElement(value)
19
+ }
20
+
21
+ var canUseSymbol = typeof Symbol === 'function' && Symbol.for
22
+ var REACT_ELEMENT_TYPE = canUseSymbol ? Symbol.for('react.element') : 0xeac7
23
+
24
+ function isReactElement(value) {
25
+ return value.$$typeof === REACT_ELEMENT_TYPE
26
+ }
27
+
28
+ var defaultIsMergeableObject = isMergeableObject;
29
+
30
+ function emptyTarget(val) {
31
+ return Array.isArray(val) ? [] : {}
32
+ }
33
+
34
+ function cloneUnlessOtherwiseSpecified(value, options) {
35
+ return (options.clone !== false && options.isMergeableObject(value))
36
+ ? deepmerge(emptyTarget(value), value, options)
37
+ : value
38
+ }
39
+
40
+ function defaultArrayMerge(target, source, options) {
41
+ return target.concat(source).map(function(element) {
42
+ return cloneUnlessOtherwiseSpecified(element, options)
43
+ })
44
+ }
45
+
46
+ function getMergeFunction(key, options) {
47
+ if (!options.customMerge) {
48
+ return deepmerge
49
+ }
50
+ var customMerge = options.customMerge(key)
51
+ return typeof customMerge === 'function' ? customMerge : deepmerge
52
+ }
53
+
54
+ function getEnumerableOwnPropertySymbols(target) {
55
+ return Object.getOwnPropertySymbols
56
+ ? Object.getOwnPropertySymbols(target).filter(function(symbol) {
57
+ return Object.propertyIsEnumerable.call(target, symbol)
58
+ })
59
+ : []
60
+ }
61
+
62
+ function getKeys(target) {
63
+ return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target))
64
+ }
65
+
66
+ function propertyIsOnObject(object, property) {
67
+ try {
68
+ return property in object
69
+ } catch(_) {
70
+ return false
71
+ }
72
+ }
73
+
74
+ // Protects from prototype poisoning and unexpected merging up the prototype chain.
75
+ function propertyIsUnsafe(target, key) {
76
+ return propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet,
77
+ && !(Object.hasOwnProperty.call(target, key) // unsafe if they exist up the prototype chain,
78
+ && Object.propertyIsEnumerable.call(target, key)) // and also unsafe if they're nonenumerable.
79
+ }
80
+
81
+ function mergeObject(target, source, options) {
82
+ var destination = {}
83
+ if (options.isMergeableObject(target)) {
84
+ getKeys(target).forEach(function(key) {
85
+ destination[key] = cloneUnlessOtherwiseSpecified(target[key], options)
86
+ })
87
+ }
88
+ getKeys(source).forEach(function(key) {
89
+ if (propertyIsUnsafe(target, key)) {
90
+ return
91
+ }
92
+
93
+ if (propertyIsOnObject(target, key) && options.isMergeableObject(source[key])) {
94
+ destination[key] = getMergeFunction(key, options)(target[key], source[key], options)
95
+ } else {
96
+ destination[key] = cloneUnlessOtherwiseSpecified(source[key], options)
97
+ }
98
+ })
99
+ return destination
100
+ }
101
+
102
+ function deepmerge(target, source, options) {
103
+ options = options || {}
104
+ options.arrayMerge = options.arrayMerge || defaultArrayMerge
105
+ options.isMergeableObject = options.isMergeableObject || defaultIsMergeableObject
106
+
107
+ options.cloneUnlessOtherwiseSpecified = cloneUnlessOtherwiseSpecified
108
+
109
+ var sourceIsArray = Array.isArray(source)
110
+ var targetIsArray = Array.isArray(target)
111
+ var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray
112
+
113
+ if (!sourceAndTargetTypesMatch) {
114
+ return cloneUnlessOtherwiseSpecified(source, options)
115
+ } else if (sourceIsArray) {
116
+ return options.arrayMerge(target, source, options)
117
+ } else {
118
+ return mergeObject(target, source, options)
119
+ }
120
+ }
121
+
122
+ deepmerge.all = function deepmergeAll(array, options) {
123
+ if (!Array.isArray(array)) {
124
+ throw new Error('first argument should be an array')
125
+ }
126
+
127
+ return array.reduce(function(prev, next) {
128
+ return deepmerge(prev, next, options)
129
+ }, {})
130
+ }
131
+
132
+ export default deepmerge;
133
+ `;
6.25.0/preview/src/build.ts ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import * as fs from "fs";
2
+ import { join, dirname } from "path";
3
+ import { fileURLToPath, pathToFileURL } from "url";
4
+
5
+ import { build } from "vite";
6
+ import type { PreRenderedChunk } from "rollup";
7
+
8
+ import { plugins, make_gradio_plugin } from "./plugins";
9
+ import { examine_module } from "./index";
10
+
11
+ interface BuildOptions {
12
+ component_dir: string;
13
+ root_dir: string;
14
+ python_path: string;
15
+ }
16
+
17
+ const __dirname = dirname(fileURLToPath(import.meta.url));
18
+
19
+ export async function make_build({
20
+ component_dir,
21
+ root_dir,
22
+ python_path
23
+ }: BuildOptions): Promise<void> {
24
+ process.env.gradio_mode = "dev";
25
+ const svelte_dir = join(root_dir, "assets", "svelte");
26
+
27
+ const module_meta = examine_module(
28
+ component_dir,
29
+ root_dir,
30
+ python_path,
31
+ "build"
32
+ );
33
+ try {
34
+ for (const comp of module_meta) {
35
+ const template_dir = comp.template_dir;
36
+ const source_dir = comp.frontend_dir;
37
+
38
+ const pkg = JSON.parse(
39
+ fs.readFileSync(join(source_dir, "package.json"), "utf-8")
40
+ );
41
+ let component_config = {
42
+ plugins: [],
43
+ svelte: {
44
+ preprocess: []
45
+ },
46
+ build: {
47
+ target: []
48
+ },
49
+ optimizeDeps: {
50
+ exclude: ["svelte", "svelte/*"]
51
+ }
52
+ };
53
+
54
+ if (
55
+ comp.frontend_dir &&
56
+ fs.existsSync(join(comp.frontend_dir, "gradio.config.js"))
57
+ ) {
58
+ const m = await import(
59
+ pathToFileURL(join(comp.frontend_dir, "gradio.config.js")).href
60
+ );
61
+
62
+ component_config.plugins = m.default.plugins || [];
63
+ component_config.svelte.preprocess = m.default.svelte?.preprocess || [];
64
+ component_config.build.target = m.default.build?.target || "modules";
65
+ component_config.optimizeDeps =
66
+ m.default.optimizeDeps || component_config.optimizeDeps;
67
+ }
68
+
69
+ const exports: (string | any)[][] = [
70
+ [
71
+ join(template_dir, "component"),
72
+ [
73
+ join(__dirname, "svelte_runtime_entry.js"),
74
+ join(source_dir, pkg.exports["."].gradio)
75
+ ]
76
+ ],
77
+ ...(pkg.exports["./example"]
78
+ ? [
79
+ [
80
+ join(template_dir, "example"),
81
+ [
82
+ join(__dirname, "svelte_runtime_entry.js"),
83
+ join(source_dir, pkg.exports["./example"].gradio)
84
+ ]
85
+ ]
86
+ ]
87
+ : [])
88
+ ];
89
+
90
+ for (const [out_path, entry_path] of exports) {
91
+ try {
92
+ const x = await build({
93
+ root: source_dir,
94
+ configFile: false,
95
+ plugins: [
96
+ ...plugins(component_config),
97
+ make_gradio_plugin({ svelte_dir, component_dir })
98
+ ],
99
+ build: {
100
+ emptyOutDir: true,
101
+ outDir: out_path,
102
+ lib: {
103
+ entry: entry_path,
104
+ fileName: "index.js",
105
+ formats: ["es"]
106
+ },
107
+ minify: true,
108
+ rollupOptions: {
109
+ output: {
110
+ assetFileNames: (chunkInfo) => {
111
+ if (chunkInfo.names[0].endsWith(".css")) {
112
+ return `style.css`;
113
+ }
114
+
115
+ return chunkInfo.names[0];
116
+ },
117
+ entryFileNames: (chunkInfo: PreRenderedChunk) => {
118
+ if (
119
+ chunkInfo.name.toLocaleLowerCase() ===
120
+ "svelte_runtime_entry"
121
+ ) {
122
+ return "svelte_runtime_entry.js";
123
+ }
124
+ return "index.js";
125
+ }
126
+ }
127
+ }
128
+ }
129
+ });
130
+ } catch (e) {
131
+ throw e;
132
+ }
133
+ }
134
+ }
135
+ } catch (e) {
136
+ throw e;
137
+ }
138
+ }
6.25.0/preview/src/dev.ts ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { join } from "path";
2
+ import { pathToFileURL } from "url";
3
+ import * as fs from "fs";
4
+
5
+ import { createServer, createLogger } from "vite";
6
+ import type { PreprocessorGroup } from "svelte/compiler";
7
+
8
+ import { plugins, make_gradio_plugin } from "./plugins";
9
+ import { examine_module } from "./index";
10
+
11
+ const vite_messages_to_ignore = [
12
+ "Default and named imports from CSS files are deprecated.",
13
+ "The above dynamic import cannot be analyzed by Vite."
14
+ ];
15
+
16
+ const logger = createLogger();
17
+ const originalWarning = logger.warn;
18
+ logger.warn = (msg, options) => {
19
+ if (vite_messages_to_ignore.some((m) => msg.includes(m))) return;
20
+
21
+ originalWarning(msg, options);
22
+ };
23
+
24
+ const originalError = logger.error;
25
+
26
+ logger.error = (msg, options) => {
27
+ if (msg && msg.includes("Pre-transform error")) return;
28
+ originalError(msg, options);
29
+ };
30
+
31
+ interface ServerOptions {
32
+ component_dir: string;
33
+ root_dir: string;
34
+ frontend_port: number;
35
+ backend_port: number;
36
+ host: string;
37
+ python_path: string;
38
+ }
39
+
40
+ export async function create_server({
41
+ component_dir,
42
+ root_dir,
43
+ frontend_port,
44
+ backend_port,
45
+ host,
46
+ python_path
47
+ }: ServerOptions): Promise<void> {
48
+ process.env.gradio_mode = "dev";
49
+ const [imports, config, runtimes] = await generate_imports(
50
+ component_dir,
51
+ root_dir,
52
+ python_path
53
+ );
54
+
55
+ const svelte_dir = join(root_dir, "assets", "svelte");
56
+
57
+ try {
58
+ const server = await createServer({
59
+ customLogger: logger,
60
+ mode: "development",
61
+ configFile: false,
62
+ root: root_dir,
63
+ server: {
64
+ port: frontend_port,
65
+ host: host,
66
+ fs: {
67
+ allow: [root_dir, component_dir]
68
+ }
69
+ },
70
+ optimizeDeps: config.optimizeDeps,
71
+ cacheDir: join(component_dir, "frontend", "node_modules", ".vite"),
72
+ plugins: [
73
+ ...plugins(config),
74
+ make_gradio_plugin({
75
+ backend_port,
76
+ svelte_dir,
77
+ component_dir,
78
+ imports,
79
+ runtimes
80
+ })
81
+ ]
82
+ });
83
+
84
+ await server.listen();
85
+
86
+ console.info(
87
+ `[orange3]Frontend Server[/] (Go here): ${server.resolvedUrls?.local}`
88
+ );
89
+ } catch (e) {
90
+ console.error(e);
91
+ }
92
+ }
93
+
94
+ function find_frontend_folders(start_path: string): string[] {
95
+ if (!fs.existsSync(start_path)) {
96
+ console.warn("No directory found at:", start_path);
97
+ return [];
98
+ }
99
+
100
+ if (fs.existsSync(join(start_path, "pyproject.toml"))) return [start_path];
101
+
102
+ const results: string[] = [];
103
+ const dir = fs.readdirSync(start_path);
104
+ dir.forEach((dir) => {
105
+ const filepath = join(start_path, dir);
106
+ if (fs.existsSync(filepath)) {
107
+ if (fs.existsSync(join(filepath, "pyproject.toml")))
108
+ results.push(filepath);
109
+ }
110
+ });
111
+
112
+ return results;
113
+ }
114
+
115
+ function to_posix(_path: string): string {
116
+ const isExtendedLengthPath = /^\\\\\?\\/.test(_path);
117
+ const hasNonAscii = /[^\u0000-\u0080]+/.test(_path);
118
+
119
+ if (isExtendedLengthPath || hasNonAscii) {
120
+ return _path;
121
+ }
122
+
123
+ return _path.replace(/\\/g, "/");
124
+ }
125
+
126
+ export interface ComponentConfig {
127
+ plugins: any[];
128
+ svelte: {
129
+ preprocess: PreprocessorGroup[];
130
+ extensions?: string[];
131
+ };
132
+ build: {
133
+ target: string | string[];
134
+ };
135
+ optimizeDeps: object;
136
+ }
137
+
138
+ async function generate_imports(
139
+ component_dir: string,
140
+ root: string,
141
+ python_path: string
142
+ ): Promise<[string, ComponentConfig, string]> {
143
+ const components = find_frontend_folders(component_dir);
144
+
145
+ const component_entries = components.flatMap((component) => {
146
+ return examine_module(component, root, python_path, "dev");
147
+ });
148
+ if (component_entries.length === 0) {
149
+ console.info(
150
+ `No custom components were found in ${component_dir}. It is likely that dev mode does not work properly. Please pass the --gradio-path and --python-path CLI arguments so that gradio uses the right executables.`
151
+ );
152
+ }
153
+
154
+ let component_config: ComponentConfig = {
155
+ plugins: [],
156
+ svelte: {
157
+ preprocess: []
158
+ },
159
+ build: {
160
+ target: []
161
+ },
162
+ optimizeDeps: {
163
+ exclude: ["svelte", "svelte/*"]
164
+ }
165
+ };
166
+
167
+ await Promise.all(
168
+ component_entries.map(async (component) => {
169
+ if (
170
+ component.frontend_dir &&
171
+ fs.existsSync(join(component.frontend_dir, "gradio.config.js"))
172
+ ) {
173
+ const m = await import(
174
+ pathToFileURL(join(component.frontend_dir, "gradio.config.js")).href
175
+ );
176
+
177
+ component_config.plugins = m.default.plugins || [];
178
+ component_config.svelte.preprocess = m.default.svelte?.preprocess || [];
179
+ component_config.build.target = m.default.build?.target || "modules";
180
+ component_config.optimizeDeps =
181
+ m.default.optimizeDeps || component_config.optimizeDeps;
182
+ } else {
183
+ }
184
+ })
185
+ );
186
+
187
+ const imports = component_entries.reduce((acc, component) => {
188
+ const pkg = JSON.parse(
189
+ fs.readFileSync(join(component.frontend_dir, "package.json"), "utf-8")
190
+ );
191
+
192
+ const exports: Record<string, any | undefined> = {
193
+ component: pkg.exports["."],
194
+ example: pkg.exports["./example"]
195
+ };
196
+
197
+ if (!exports.component)
198
+ throw new Error(
199
+ "Could not find component entry point. Please check the exports field of your package.json."
200
+ );
201
+
202
+ const example = exports.example
203
+ ? `example: () => import("/@fs/${to_posix(
204
+ join(component.frontend_dir, exports.example.gradio)
205
+ )}"),\n`
206
+ : "";
207
+ return `${acc}"${component.component_class_id}": {
208
+ ${example}
209
+ component: () => import("/@fs/${to_posix(
210
+ join(component.frontend_dir, exports.component.gradio)
211
+ )}"),
212
+
213
+ },\n`;
214
+ }, "");
215
+
216
+ const runtimes = component_entries.reduce((acc, component) => {
217
+ return `${acc}"${component.component_class_id}": import("svelte"),\n`;
218
+ }, "");
219
+
220
+ return [`{${imports}}`, component_config, `{${runtimes}}`];
221
+ }
6.25.0/preview/src/index.ts ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { type ChildProcess, spawn, spawnSync } from "node:child_process";
2
+ import * as net from "net";
3
+
4
+ import { create_server, type ComponentConfig } from "./dev";
5
+ import { make_build } from "./build";
6
+ import { join, dirname } from "path";
7
+ import { fileURLToPath } from "url";
8
+
9
+ const __dirname = dirname(fileURLToPath(import.meta.url));
10
+
11
+ export interface ComponentMeta {
12
+ name: string;
13
+ template_dir: string;
14
+ frontend_dir: string;
15
+ component_class_id: string;
16
+ }
17
+
18
+ const args = process.argv.slice(2);
19
+ // get individual args as `--arg value` or `value`
20
+
21
+ function parse_args(args: string[]): Record<string, string> {
22
+ const arg_map: Record<string, string> = {};
23
+ for (let i = 0; i < args.length; i++) {
24
+ const arg = args[i];
25
+ if (arg.startsWith("--")) {
26
+ const name = arg.slice(2);
27
+ const value = args[i + 1];
28
+ arg_map[name] = value;
29
+ i++;
30
+ }
31
+ }
32
+ return arg_map;
33
+ }
34
+
35
+ const parsed_args = parse_args(args);
36
+
37
+ async function run(): Promise<void> {
38
+ if (parsed_args.mode === "build") {
39
+ await make_build({
40
+ component_dir: parsed_args["component-directory"],
41
+ root_dir: parsed_args.root,
42
+ python_path: parsed_args["python-path"]
43
+ });
44
+ } else {
45
+ const [backend_port, frontend_port] = await find_free_ports(7860, 8860);
46
+ const options = {
47
+ component_dir: parsed_args["component-directory"],
48
+ root_dir: parsed_args.root,
49
+ frontend_port,
50
+ backend_port,
51
+ host: parsed_args.host,
52
+ ...parsed_args
53
+ };
54
+ process.env.GRADIO_BACKEND_PORT = backend_port.toString();
55
+ const _process = spawn(
56
+ parsed_args["gradio-path"],
57
+ [parsed_args.app, "--watch-dirs", options.component_dir],
58
+ {
59
+ shell: false,
60
+ stdio: "pipe",
61
+ cwd: process.cwd(),
62
+ env: {
63
+ ...process.env,
64
+ GRADIO_SERVER_PORT: backend_port.toString(),
65
+ PYTHONUNBUFFERED: "true"
66
+ }
67
+ }
68
+ );
69
+
70
+ _process.stdout.setEncoding("utf8");
71
+ _process.stderr.setEncoding("utf8");
72
+
73
+ function std_out(mode: "stdout" | "stderr") {
74
+ return function (data: Buffer): void {
75
+ const _data = data.toString();
76
+
77
+ if (_data.includes("Running on")) {
78
+ create_server({
79
+ component_dir: options.component_dir,
80
+ root_dir: options.root_dir,
81
+ frontend_port,
82
+ backend_port,
83
+ host: options.host,
84
+ python_path: parsed_args["python-path"]
85
+ });
86
+ }
87
+
88
+ process[mode].write(_data);
89
+ };
90
+ }
91
+
92
+ _process.stdout.on("data", std_out("stdout"));
93
+ _process.stderr.on("data", std_out("stderr"));
94
+ _process.on("exit", () => kill_process(_process));
95
+ _process.on("close", () => kill_process(_process));
96
+ _process.on("disconnect", () => kill_process(_process));
97
+ }
98
+ }
99
+
100
+ function kill_process(process: ChildProcess): void {
101
+ process.kill("SIGKILL");
102
+ }
103
+
104
+ export { create_server };
105
+
106
+ run();
107
+
108
+ export async function find_free_ports(
109
+ start_port: number,
110
+ end_port: number
111
+ ): Promise<[number, number]> {
112
+ let found_ports: number[] = [];
113
+
114
+ for (let port = start_port; port < end_port; port++) {
115
+ if (await is_free_port(port)) {
116
+ found_ports.push(port);
117
+ if (found_ports.length === 2) {
118
+ return [found_ports[0], found_ports[1]];
119
+ }
120
+ }
121
+ }
122
+
123
+ throw new Error(
124
+ `Could not find free ports: there were not enough ports available.`
125
+ );
126
+ }
127
+
128
+ export function is_free_port(port: number): Promise<boolean> {
129
+ return new Promise((accept, reject) => {
130
+ const sock = net.createConnection(port, "127.0.0.1");
131
+ setTimeout(() => {
132
+ sock.destroy();
133
+ reject(
134
+ new Error(`Timeout while detecting free port with 127.0.0.1:${port} `)
135
+ );
136
+ }, 3000);
137
+ sock.once("connect", () => {
138
+ sock.end();
139
+ accept(false);
140
+ });
141
+ sock.once("error", (e) => {
142
+ sock.destroy();
143
+ //@ts-ignore
144
+ if (e.code === "ECONNREFUSED") {
145
+ accept(true);
146
+ } else {
147
+ reject(e);
148
+ }
149
+ });
150
+ });
151
+ }
152
+
153
+ function is_truthy<T>(value: T | null | undefined | false): value is T {
154
+ return value !== null && value !== undefined && value !== false;
155
+ }
156
+
157
+ export function examine_module(
158
+ component_dir: string,
159
+ root: string,
160
+ python_path: string,
161
+ mode: "build" | "dev"
162
+ ): ComponentMeta[] {
163
+ const _process = spawnSync(
164
+ python_path,
165
+ [join(__dirname, "examine.py"), "-m", mode],
166
+ {
167
+ cwd: join(component_dir, "backend"),
168
+ stdio: "pipe"
169
+ }
170
+ );
171
+ const exceptions: string[] = [];
172
+
173
+ const components = _process.stdout
174
+ .toString()
175
+ .trim()
176
+ .split("\n")
177
+ .map((line) => {
178
+ if (line.startsWith("|EXCEPTION|")) {
179
+ exceptions.push(line.slice("|EXCEPTION|:".length));
180
+ }
181
+ const [name, template_dir, frontend_dir, component_class_id] =
182
+ line.split("~|~|~|~");
183
+ if (name && template_dir && frontend_dir && component_class_id) {
184
+ return {
185
+ name: name.trim(),
186
+ template_dir: template_dir.trim(),
187
+ frontend_dir: frontend_dir.trim(),
188
+ component_class_id: component_class_id.trim()
189
+ };
190
+ }
191
+ return false;
192
+ })
193
+ .filter(is_truthy);
194
+ if (exceptions.length > 0) {
195
+ console.info(
196
+ `While searching for gradio custom component source directories in ${component_dir}, the following exceptions were raised. If dev mode does not work properly please pass the --gradio-path and --python-path CLI arguments so that gradio uses the right executables: ${exceptions.join(
197
+ "\n"
198
+ )}`
199
+ );
200
+ }
201
+ return components;
202
+ }
6.25.0/preview/src/placeholder.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ export default {};
6.25.0/preview/src/plugins.ts ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { Plugin, PluginOption } from "vite";
2
+ import { svelte } from "@sveltejs/vite-plugin-svelte";
3
+ import { join, dirname } from "path";
4
+ import { createRequire } from "module";
5
+ import { readFileSync } from "fs";
6
+ import { type ComponentConfig } from "./dev";
7
+ import type { PreprocessorGroup } from "svelte/compiler";
8
+ import { sveltePreprocess } from "svelte-preprocess";
9
+
10
+ const svelte_codes_to_ignore: Record<string, string> = {
11
+ "reactive-component": "Icon"
12
+ };
13
+
14
+ export function plugins(config: ComponentConfig): PluginOption[] {
15
+ const _additional_plugins = config.plugins || [];
16
+ const _additional_svelte_preprocess = config.svelte?.preprocess || [];
17
+ const _svelte_extensions = (config.svelte?.extensions || [".svelte"]).map(
18
+ (ext) => {
19
+ if (ext.trim().startsWith(".")) {
20
+ return ext;
21
+ }
22
+ return `.${ext.trim()}`;
23
+ }
24
+ );
25
+
26
+ if (!_svelte_extensions.includes(".svelte")) {
27
+ _svelte_extensions.push(".svelte");
28
+ }
29
+
30
+ return [
31
+ svelte({
32
+ inspector: false,
33
+ onwarn(warning, handler) {
34
+ if (
35
+ svelte_codes_to_ignore.hasOwnProperty(warning.code) &&
36
+ svelte_codes_to_ignore[warning.code] &&
37
+ warning.message.includes(svelte_codes_to_ignore[warning.code])
38
+ ) {
39
+ return;
40
+ }
41
+ handler!(warning);
42
+ },
43
+ prebundleSvelteLibraries: false,
44
+ compilerOptions: {
45
+ discloseVersion: false,
46
+ hmr: true
47
+ },
48
+ extensions: _svelte_extensions,
49
+ preprocess: [
50
+ sveltePreprocess({
51
+ typescript: {
52
+ compilerOptions: {
53
+ declaration: false,
54
+ declarationMap: false
55
+ }
56
+ }
57
+ }),
58
+ ...(_additional_svelte_preprocess as PreprocessorGroup[])
59
+ ]
60
+ }),
61
+ ..._additional_plugins
62
+ ];
63
+ }
64
+
65
+ function resolve_svelte_entry(id: string, base_dir: string): string | null {
66
+ const require_fn = createRequire(join(base_dir, "frontend", "_"));
67
+ try {
68
+ const svelte_pkg_path = require_fn.resolve("svelte/package.json");
69
+ const svelte_dir = dirname(svelte_pkg_path);
70
+ const pkg = JSON.parse(readFileSync(svelte_pkg_path, "utf-8"));
71
+
72
+ const subpath = id === "svelte" ? "." : "./" + id.slice("svelte/".length);
73
+
74
+ if (pkg.exports && pkg.exports[subpath]) {
75
+ const entry = pkg.exports[subpath];
76
+ const resolved =
77
+ typeof entry === "string" ? entry : entry.browser || entry.default;
78
+ if (resolved) {
79
+ return join(svelte_dir, resolved);
80
+ }
81
+ }
82
+ } catch {
83
+ return null;
84
+ }
85
+ return null;
86
+ }
87
+
88
+ interface GradioPluginOptions {
89
+ svelte_dir: string;
90
+ component_dir: string;
91
+ backend_port?: number;
92
+ imports?: string;
93
+ runtimes?: string;
94
+ }
95
+
96
+ export function make_gradio_plugin({
97
+ backend_port,
98
+ component_dir,
99
+ imports,
100
+ runtimes
101
+ }: GradioPluginOptions): Plugin {
102
+ const v_id = "virtual:component-loader";
103
+ const v_id_2 = "virtual:cc-init";
104
+ const resolved_v_id = "\0" + v_id;
105
+ const resolved_v_id_2 = "\0" + v_id_2;
106
+ return {
107
+ name: "gradio",
108
+ enforce: "pre",
109
+ resolveId(id) {
110
+ if (id === v_id) {
111
+ return resolved_v_id;
112
+ }
113
+ if (id === v_id_2) {
114
+ return resolved_v_id_2;
115
+ }
116
+
117
+ if (id.startsWith("svelte")) {
118
+ const resolved = resolve_svelte_entry(id, component_dir);
119
+ if (resolved) {
120
+ return resolved;
121
+ }
122
+ }
123
+ },
124
+ load(id) {
125
+ if (id === resolved_v_id) {
126
+ return `export default {};`;
127
+ }
128
+
129
+ if (id === resolved_v_id_2) {
130
+ return `window.__GRADIO_DEV__ = "dev";
131
+ window.__GRADIO__SERVER_PORT__ = ${backend_port};
132
+ window.__GRADIO__CC__ = ${imports};
133
+ window.__GRADIO__CC__RUNTIMES__ = ${runtimes};`;
134
+ }
135
+ },
136
+ transform(code, id) {
137
+ return code.replace('"_NORMAL_"', '"_CC_"');
138
+ }
139
+ };
140
+ }
141
+
142
+ // export const deepmerge_plugin: Plugin = {
143
+ // name: "deepmerge",
144
+ // enforce: "pre",
145
+ // resolveId(id) {
146
+ // if (id === "deepmerge") {
147
+ // return "deepmerge_internal";
148
+ // }
149
+ // },
150
+ // load(id) {
151
+ // if (id === "deepmerge_internal") {
152
+ // return deepmerge;
153
+ // }
154
+ // },
155
+ // };
6.25.0/preview/test/test/frontend/Example.svelte ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ let {
3
+ value,
4
+ type,
5
+ selected = false
6
+ }: {
7
+ value: string;
8
+ type: "gallery" | "table";
9
+ selected?: boolean;
10
+ } = $props();
11
+ </script>
12
+
13
+ <div
14
+ class:table={type === "table"}
15
+ class:gallery={type === "gallery"}
16
+ class:selected
17
+ >
18
+ {value}
19
+ </div>
20
+
21
+ <style>
22
+ .gallery {
23
+ padding: var(--size-1) var(--size-2);
24
+ }
25
+ </style>
6.25.0/preview/test/test/frontend/Index.svelte ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import "./main.css";
3
+ import { JsonView } from "@zerodevx/svelte-json-view";
4
+
5
+ import type { Gradio } from "@gradio/utils";
6
+ import { Block, Info } from "@gradio/atoms";
7
+ import { StatusTracker } from "@gradio/statustracker";
8
+ import type { ILoadingStatus as LoadingStatus } from "@gradio/statustracker";
9
+ import type { SelectData } from "@gradio/utils";
10
+
11
+ let {
12
+ elem_id = "",
13
+ elem_classes = [],
14
+ visible = true,
15
+ value = false,
16
+ container = true,
17
+ scale = null,
18
+ min_width = undefined,
19
+ loading_status,
20
+ gradio
21
+ }: {
22
+ elem_id?: string;
23
+ elem_classes?: string[];
24
+ visible?: boolean | "hidden";
25
+ value?: boolean;
26
+ container?: boolean;
27
+ scale?: number | null;
28
+ min_width?: number | undefined;
29
+ loading_status: LoadingStatus;
30
+ gradio: Gradio<{
31
+ change: never;
32
+ select: SelectData;
33
+ input: never;
34
+ }>;
35
+ } = $props();
36
+ </script>
37
+
38
+ <div class="relative flex min-h-screen flex-col justify-center overflow-hidden">
39
+ <div
40
+ class="relative bg-white px-6 pt-10 pb-8 shadow-xl ring-1 ring-gray-900/5 sm:mx-auto sm:max-w-lg sm:rounded-lg sm:px-10"
41
+ >
42
+ <div class="mx-auto max-w-md">
43
+ <h1 class="text-xl! font-bold! text-gray-900">
44
+ <span class="text-blue-500">Tailwind</span> in Gradio
45
+ </h1>
46
+ <h2><em>(i hope you're happy now)</em></h2>
47
+ <div class="divide-y divide-gray-300/50">
48
+ <div class="space-y-6 py-8 text-base leading-7 text-gray-600">
49
+ <p>
50
+ An advanced online playground for Tailwind CSS, including support
51
+ for things like:
52
+ </p>
53
+ <ul class="space-y-4 my-4!">
54
+ <li class="flex items-center">
55
+ <svg
56
+ class="h-6 w-6 flex-none fill-sky-100 stroke-sky-500 stroke-2 mr-4"
57
+ stroke-linecap="round"
58
+ stroke-linejoin="round"
59
+ >
60
+ <circle cx="12" cy="12" r="11" />
61
+ <path
62
+ d="m8 13 2.165 2.165a1 1 0 0 0 1.521-.126L16 9"
63
+ fill="none"
64
+ />
65
+ </svg>
66
+ <p class="ml-4">
67
+ Customizing your
68
+ <code class="text-sm font-bold text-gray-900"
69
+ >tailwind.config.js</code
70
+ > file
71
+ </p>
72
+ </li>
73
+ <li class="flex items-center">
74
+ <svg
75
+ class="h-6 w-6 flex-none fill-sky-100 stroke-sky-500 stroke-2 mr-4"
76
+ stroke-linecap="round"
77
+ stroke-linejoin="round"
78
+ >
79
+ <circle cx="12" cy="12" r="11" />
80
+ <path
81
+ d="m8 13 2.165 2.165a1 1 0 0 0 1.521-.126L16 9"
82
+ fill="none"
83
+ />
84
+ </svg>
85
+ <p class="ml-4">
86
+ Extracting classes with
87
+ <code class="text-sm font-bold text-gray-900">@apply</code>
88
+ </p>
89
+ </li>
90
+ <li class="flex items-center">
91
+ <svg
92
+ class="h-6 w-6 flex-none fill-sky-100 stroke-sky-500 stroke-2 mr-4"
93
+ stroke-linecap="round"
94
+ stroke-linejoin="round"
95
+ >
96
+ <circle cx="12" cy="12" r="11" />
97
+ <path
98
+ d="m8 13 2.165 2.165a1 1 0 0 0 1.521-.126L16 9"
99
+ fill="none"
100
+ />
101
+ </svg>
102
+ <p class="ml-4">Code completion with instant preview</p>
103
+ </li>
104
+ </ul>
105
+ <p>
106
+ Perfect for learning how the framework works, prototyping a new
107
+ idea, or creating a demo to share online.
108
+ </p>
109
+ </div>
110
+ <div class="pt-8 text-base font-semibold leading-7">
111
+ <p class="text-gray-900">Want to dig deeper into Tailwind?</p>
112
+ <p>
113
+ <a
114
+ href="https://tailwindcss.com/docs"
115
+ class="text-sky-500 hover:text-sky-600">Read the docs &rarr;</a
116
+ >
117
+ </p>
118
+ </div>
119
+ </div>
120
+ </div>
121
+ </div>
122
+ </div>
6.25.0/preview/test/test/frontend/package.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "gradio_test",
3
+ "version": "0.6.0",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "private": true,
9
+ "main_changeset": true,
10
+ "exports": {
11
+ ".": "./Index.svelte",
12
+ "./example": "./Example.svelte",
13
+ "./package.json": "./package.json"
14
+ },
15
+ "dependencies": {},
16
+ "devDependencies": {},
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/gradio-app/gradio.git",
20
+ "directory": "js/preview/test/test/frontend"
21
+ }
22
+ }
6.25.0/preview/vite.config.ts ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { defineConfig } from "vite";
2
+ import { cpSync, write } from "fs";
3
+ import { join } from "node:path";
4
+ import { createRequire } from "node:module";
5
+
6
+ const require = createRequire(import.meta.url);
7
+ const dir = require.resolve("./package.json");
8
+
9
+ const template_dir = join(dir, "..", "..", "..", "gradio", "templates");
10
+
11
+ export default defineConfig({
12
+ build: {
13
+ lib: {
14
+ entry: "./src/index.ts",
15
+ formats: ["es"]
16
+ },
17
+ outDir: "dist",
18
+ rollupOptions: {
19
+ external: ["fsevents", "vite", "@sveltejs/vite-plugin-svelte"]
20
+ }
21
+ },
22
+ plugins: [copy_files()]
23
+ });
24
+
25
+ export function copy_files() {
26
+ return {
27
+ name: "copy_files",
28
+ writeBundle() {
29
+ cpSync("./src/examine.py", "dist/examine.py");
30
+ cpSync("./src/svelte_runtime_entry.js", "dist/svelte_runtime_entry.js");
31
+ cpSync("./src/register.mjs", join(template_dir, "register.mjs"));
32
+ cpSync("./src/hooks.mjs", join(template_dir, "hooks.mjs"));
33
+ }
34
+ };
35
+ }