diff --git a/.changeset/weak-games-sing.md b/.changeset/weak-games-sing.md new file mode 100644 index 0000000000000..e124b979b8496 --- /dev/null +++ b/.changeset/weak-games-sing.md @@ -0,0 +1,7 @@ +--- +"@gradio/preview": minor +"gradio": minor +"gradio_test": minor +--- + +feat:fix cc build diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 0e44af19801bf..4fdef1073b623 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -168,6 +168,7 @@ jobs: with: path: | gradio/templates/* + gradio/node/* key: gradio-lib-front-end-${{ hashFiles('js/**', 'client/js/**')}} - name: Install pnpm if: steps.frontend-cache.outputs.cache-hit != 'true' diff --git a/gradio/cli/commands/components/_create_utils.py b/gradio/cli/commands/components/_create_utils.py index c28dc37820cbd..9974fa1ba55b6 100644 --- a/gradio/cli/commands/components/_create_utils.py +++ b/gradio/cli/commands/components/_create_utils.py @@ -191,7 +191,9 @@ def delete_contents(directory: str | Path) -> None: shutil.rmtree(child) -def _create_frontend(name: str, component: ComponentFiles, directory: Path): +def _create_frontend( + name: str, component: ComponentFiles, directory: Path, package_name: str +): frontend = directory / "frontend" frontend.mkdir(exist_ok=True) @@ -217,7 +219,7 @@ def ignore(s, names): ignore=ignore, ) source_package_json = json.loads(Path(frontend / "package.json").read_text()) - source_package_json["name"] = name.lower() + source_package_json["name"] = package_name source_package_json = _modify_js_deps(source_package_json, "dependencies", p) source_package_json = _modify_js_deps(source_package_json, "devDependencies", p) (frontend / "package.json").write_text(json.dumps(source_package_json, indent=2)) diff --git a/gradio/cli/commands/components/build.py b/gradio/cli/commands/components/build.py index 87487e0116606..42ef190ea8395 100644 --- a/gradio/cli/commands/components/build.py +++ b/gradio/cli/commands/components/build.py @@ -35,7 +35,9 @@ def _build( node = shutil.which("node") if not node: - raise ValueError("node must be installed in order to run dev mode.") + raise ValueError( + "node must be installed in order to run build command." + ) node_cmds = [ node, @@ -47,7 +49,6 @@ def _build( "--mode", "build", ] - pipe = subprocess.run(node_cmds, capture_output=True, text=True) if pipe.returncode != 0: live.update(":red_square: Build failed!") diff --git a/gradio/cli/commands/components/create.py b/gradio/cli/commands/components/create.py index 88a1e0fb94aea..a99dc7aa82c6c 100644 --- a/gradio/cli/commands/components/create.py +++ b/gradio/cli/commands/components/create.py @@ -96,7 +96,9 @@ def _create( _create_utils._create_backend(name, component, directory, package_name) live.update(":snake: Created backend code", add_sleep=0.2) - _create_utils._create_frontend(name.lower(), component, directory=directory) + _create_utils._create_frontend( + name.lower(), component, directory=directory, package_name=package_name + ) live.update(":art: Created frontend code", add_sleep=0.2) if install: diff --git a/js/preview/src/build.ts b/js/preview/src/build.ts index 85eb152aefab9..28d9ffc684802 100644 --- a/js/preview/src/build.ts +++ b/js/preview/src/build.ts @@ -2,7 +2,7 @@ import * as fs from "fs"; import { join } from "path"; import { build } from "vite"; import { plugins, make_gradio_plugin } from "./plugins"; - +import type { PreRenderedChunk } from "rollup"; import { examine_module } from "./index"; interface BuildOptions { @@ -29,7 +29,7 @@ export async function make_build({ const exports: string[][] = [ ["component", pkg.exports["."] as string], - ["exmaple", pkg.exports["./example"] as string] + ["example", pkg.exports["./example"] as string] ].filter(([_, path]) => !!path); for (const [entry, path] of exports) { @@ -43,23 +43,29 @@ export async function make_build({ emptyOutDir: true, outDir: join(template_dir, entry), lib: { - entry: join(source_dir, entry, "index.ts"), + entry: join(source_dir, path), fileName: "index.js", formats: ["es"] }, + minify: true, rollupOptions: { output: { - entryFileNames: "[name].js" + entryFileNames: (chunkInfo: PreRenderedChunk) => { + if (chunkInfo.isEntry) { + return "index.js"; + } + return `${chunkInfo.name.toLocaleLowerCase()}.js`; + } } } } }); } catch (e) { - console.error(e); + throw e; } } } } catch (e) { - console.error(e); + throw e; } } diff --git a/js/preview/test/imageslider/backend/imageslider/__init__.py b/js/preview/test/imageslider/backend/imageslider/__init__.py deleted file mode 100644 index 190fe0e643857..0000000000000 --- a/js/preview/test/imageslider/backend/imageslider/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ - -from .imageslider import ImageSlider - -__all__ = ['ImageSlider'] diff --git a/js/preview/test/imageslider/backend/imageslider/imageslider.py b/js/preview/test/imageslider/backend/imageslider/imageslider.py deleted file mode 100644 index 0b54b42cfbd04..0000000000000 --- a/js/preview/test/imageslider/backend/imageslider/imageslider.py +++ /dev/null @@ -1,337 +0,0 @@ -"""gr.Image() component.""" - -from __future__ import annotations - -import warnings -from pathlib import Path -from typing import Any, Literal - -import numpy as np -import PIL -import PIL.ImageOps -from gradio_client import utils as client_utils -from gradio_client.documentation import document, set_documentation_group -from PIL import Image as _Image # using _ to minimize namespace pollution - -from gradio import processing_utils, utils -from gradio.components.base import Component, StreamingInput, _Keywords -from gradio.data_classes import FileData -from gradio.events import Events - -set_documentation_group("component") -_Image.init() # fixes https://github.com/gradio-app/gradio/issues/2843 - - -@document() -class ImageSlider(StreamingInput, Component): - """ - Creates an image component that can be used to upload/draw images (as an input) or display images (as an output). - Preprocessing: passes the uploaded image as a {numpy.array}, {PIL.Image} or {str} filepath depending on `type` -- unless `tool` is `sketch` AND source is one of `upload` or `webcam`. In these cases, a {dict} with keys `image` and `mask` is passed, and the format of the corresponding values depends on `type`. - Postprocessing: expects a {numpy.array}, {PIL.Image} or {str} or {pathlib.Path} filepath to an image and displays the image. - Examples-format: a {str} filepath to a local file that contains the image. - Demos: image_mod, image_mod_default_image - Guides: image-classification-in-pytorch, image-classification-in-tensorflow, image-classification-with-vision-transformers, building-a-pictionary_app, create-your-own-friends-with-a-gan - """ - - EVENTS = [ - Events.edit, - Events.clear, - Events.change, - Events.stream, - Events.select, - Events.upload, - ] - data_model = FileData - - def __init__( - self, - value: str | _Image.Image | np.ndarray | None = None, - *, - shape: tuple[int, int] | None = None, - height: int | None = None, - width: int | None = None, - image_mode: Literal[ - "1", "L", "P", "RGB", "RGBA", "CMYK", "YCbCr", "LAB", "HSV", "I", "F" - ] = "RGB", - invert_colors: bool = False, - source: Literal["upload", "webcam", "canvas"] = "upload", - tool: Literal["editor", "select", "sketch", "color-sketch"] | None = None, - type: Literal["numpy", "pil", "filepath"] = "numpy", - label: str | None = None, - every: float | None = None, - show_label: bool | None = None, - show_download_button: bool = True, - container: bool = True, - scale: int | None = None, - min_width: int = 160, - interactive: bool | None = None, - visible: bool = True, - streaming: bool = False, - elem_id: str | None = None, - elem_classes: list[str] | str | None = None, - render: bool = True, - root_url: str | None = None, - _skip_init_processing: bool = False, - mirror_webcam: bool = True, - brush_radius: float | None = None, - brush_color: str = "#000000", - mask_opacity: float = 0.7, - show_share_button: bool | None = None, - **kwargs, - ): - """ - Parameters: - value: A PIL Image, numpy array, path or URL for the default value that Image component is going to take. If callable, the function will be called whenever the app loads to set the initial value of the component. - shape: (width, height) shape to crop and resize image when passed to function. If None, matches input image size. Pass None for either width or height to only crop and resize the other. - height: Height of the displayed image in pixels. - width: Width of the displayed image in pixels. - image_mode: "RGB" if color, or "L" if black and white. See https://pillow.readthedocs.io/en/stable/handbook/concepts.html for other supported image modes and their meaning. - invert_colors: whether to invert the image as a preprocessing step. - source: Source of image. "upload" creates a box where user can drop an image file, "webcam" allows user to take snapshot from their webcam, "canvas" defaults to a white image that can be edited and drawn upon with tools. - tool: Tools used for editing. "editor" allows a full screen editor (and is the default if source is "upload" or "webcam"), "select" provides a cropping and zoom tool, "sketch" allows you to create a binary sketch (and is the default if source="canvas"), and "color-sketch" allows you to created a sketch in different colors. "color-sketch" can be used with source="upload" or "webcam" to allow sketching on an image. "sketch" can also be used with "upload" or "webcam" to create a mask over an image and in that case both the image and mask are passed into the function as a dictionary with keys "image" and "mask" respectively. - type: The format the image is converted to before being passed into the prediction function. "numpy" converts the image to a numpy array with shape (height, width, 3) and values from 0 to 255, "pil" converts the image to a PIL image object, "filepath" passes a str path to a temporary file containing the image. - label: component name in interface. - every: If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute. - show_label: if True, will display label. - show_download_button: If True, will display button to download image. - container: If True, will place the component in a container - providing some extra padding around the border. - scale: relative width compared to adjacent Components in a Row. For example, if Component A has scale=2, and Component B has scale=1, A will be twice as wide as B. Should be an integer. - min_width: minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first. - interactive: if True, will allow users to upload and edit an image; if False, can only be used to display images. If not provided, this is inferred based on whether the component is used as an input or output. - visible: If False, component will be hidden. - streaming: If True when used in a `live` interface, will automatically stream webcam feed. Only valid is source is 'webcam'. - elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles. - elem_classes: An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles. - render: If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later. - root_url: The remote URL that of the Gradio app that this component belongs to. Used in `gr.load()`. Should not be set manually. - mirror_webcam: If True webcam will be mirrored. Default is True. - brush_radius: Size of the brush for Sketch. Default is None which chooses a sensible default - brush_color: Color of the brush for Sketch as hex string. Default is "#000000". - mask_opacity: Opacity of mask drawn on image, as a value between 0 and 1. - show_share_button: If True, will show a share icon in the corner of the component that allows user to share outputs to Hugging Face Spaces Discussions. If False, icon does not appear. If set to None (default behavior), then the icon appears if this Gradio app is launched on Spaces, but not otherwise. - """ - self.brush_radius = brush_radius - self.brush_color = brush_color - self.mask_opacity = mask_opacity - self.mirror_webcam = mirror_webcam - valid_types = ["numpy", "pil", "filepath"] - if type not in valid_types: - raise ValueError( - f"Invalid value for parameter `type`: {type}. Please choose from one of: {valid_types}" - ) - self.type = type - self.shape = shape - self.height = height - self.width = width - self.image_mode = image_mode - valid_sources = ["upload", "webcam", "canvas"] - if source not in valid_sources: - raise ValueError( - f"Invalid value for parameter `source`: {source}. Please choose from one of: {valid_sources}" - ) - self.source = source - if tool is None: - self.tool = "sketch" if source == "canvas" else "editor" - else: - self.tool = tool - self.invert_colors = invert_colors - self.streaming = streaming - self.show_download_button = show_download_button - if streaming and source != "webcam": - raise ValueError("Image streaming only available if source is 'webcam'.") - self.show_share_button = ( - (utils.get_space() is not None) - if show_share_button is None - else show_share_button - ) - super().__init__( - label=label, - every=every, - show_label=show_label, - container=container, - scale=scale, - min_width=min_width, - interactive=interactive, - visible=visible, - elem_id=elem_id, - elem_classes=elem_classes, - render=render, - root_url=root_url, - _skip_init_processing=_skip_init_processing, - value=value, - **kwargs, - ) - - def get_config(self): - return { - "image_mode": self.image_mode, - "shape": self.shape, - "height": self.height, - "width": self.width, - "source": self.source, - "tool": self.tool, - "value": self.value, - "streaming": self.streaming, - "mirror_webcam": self.mirror_webcam, - "brush_radius": self.brush_radius, - "brush_color": self.brush_color, - "mask_opacity": self.mask_opacity, - "selectable": self.selectable, - "show_share_button": self.show_share_button, - "show_download_button": self.show_download_button, - **Component.get_config(self), - } - - @staticmethod - def update( - value: Any | Literal[_Keywords.NO_VALUE] | None = _Keywords.NO_VALUE, - height: int | None = None, - width: int | None = None, - label: str | None = None, - show_label: bool | None = None, - show_download_button: bool | None = None, - container: bool | None = None, - scale: int | None = None, - min_width: int | None = None, - interactive: bool | None = None, - visible: bool | None = None, - brush_radius: float | None = None, - brush_color: str | None = None, - mask_opacity: float | None = None, - show_share_button: bool | None = None, - ): - return { - "height": height, - "width": width, - "label": label, - "show_label": show_label, - "show_download_button": show_download_button, - "container": container, - "scale": scale, - "min_width": min_width, - "interactive": interactive, - "visible": visible, - "value": value, - "brush_radius": brush_radius, - "brush_color": brush_color, - "mask_opacity": mask_opacity, - "show_share_button": show_share_button, - "__type__": "update", - } - - def _format_image( - self, im: _Image.Image | None - ) -> np.ndarray | _Image.Image | str | None: - """Helper method to format an image based on self.type""" - if im is None: - return im - fmt = im.format - if self.type == "pil": - return im - elif self.type == "numpy": - return np.array(im) - elif self.type == "filepath": - path = self.pil_to_temp_file( - im, dir=self.DEFAULT_TEMP_DIR, format=fmt or "png" - ) - self.temp_files.add(path) - return path - else: - raise ValueError( - "Unknown type: " - + str(self.type) - + ". Please choose from: 'numpy', 'pil', 'filepath'." - ) - - def preprocess( - self, x: str | dict[str, str] - ) -> np.ndarray | _Image.Image | str | dict | None: - """ - Parameters: - x: base64 url data, or (if tool == "sketch") a dict of image and mask base64 url data - Returns: - image in requested format, or (if tool == "sketch") a dict of image and mask in requested format - """ - if x is None: - return x - - mask = "" - if self.tool == "sketch" and self.source in ["upload", "webcam"]: - assert isinstance(x, dict) - x, mask = x["image"], x["mask"] - - if isinstance(x, str): - im = processing_utils.decode_base64_to_image(x) - else: - im = PIL.Image.open(self.make_temp_copy_if_needed(x["name"])) - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - im = im.convert(self.image_mode) - if self.shape is not None: - im = processing_utils.resize_and_crop(im, self.shape) - if self.invert_colors: - im = PIL.ImageOps.invert(im) - if ( - self.source == "webcam" - and self.mirror_webcam is True - and self.tool != "color-sketch" - ): - im = PIL.ImageOps.mirror(im) - - if self.tool == "sketch" and self.source in ["upload", "webcam"]: - mask_im = processing_utils.decode_base64_to_image(mask) - - if mask_im.mode == "RGBA": # whiten any opaque pixels in the mask - alpha_data = mask_im.getchannel("A").convert("L") - mask_im = _Image.merge("RGB", [alpha_data, alpha_data, alpha_data]) - return { - "image": self._format_image(im), - "mask": self._format_image(mask_im), - } - - return self._format_image(im) - - def postprocess( - self, y: np.ndarray | _Image.Image | str | Path | None - ) -> str | None: - """ - Parameters: - y: image as a numpy array, PIL Image, string/Path filepath, or string URL - Returns: - base64 url data - """ - if y is None: - return None - if isinstance(y, np.ndarray): - path = self.base64_to_temp_file_if_needed( - processing_utils.encode_array_to_base64(y), "file.png" - ) - elif isinstance(y, _Image.Image): - path = self.base64_to_temp_file_if_needed( - processing_utils.encode_pil_to_base64(y), "file.png" - ) - elif isinstance(y, (str, Path)): - name = y if isinstance(y, str) else y.name - if client_utils.is_http_url_like(name): - path = self.download_temp_copy_if_needed(name) - else: - path = self.make_temp_copy_if_needed(name) - else: - raise ValueError("Cannot process this value as an Image") - return FileData(name=path, data=None, is_file=True) - - def check_streamable(self): - if self.source != "webcam" and self.streaming: - raise ValueError("Image streaming only available if source is 'webcam'.") - - def as_example(self, input_data: str | None) -> str: - if input_data is None: - return "" - elif ( - self.root_url - ): # If an externally hosted image, don't convert to absolute path - return input_data - return str(utils.abspath(input_data)) - - def example_inputs(self) -> Any: - return "https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png" diff --git a/js/preview/test/imageslider/demo/app.py b/js/preview/test/imageslider/demo/app.py deleted file mode 100644 index 62e6e1c893943..0000000000000 --- a/js/preview/test/imageslider/demo/app.py +++ /dev/null @@ -1,9 +0,0 @@ -import gradio as gr -from imageslider import ImageSlider - -with gr.Blocks() as demo: - ImageSlider(label="asd", interactive=True) - ImageSlider(label="Static", interactive=False) - - -demo.launch() diff --git a/js/preview/test/imageslider/frontend/CHANGELOG.md b/js/preview/test/imageslider/frontend/CHANGELOG.md deleted file mode 100644 index 64e63beeb3a0f..0000000000000 --- a/js/preview/test/imageslider/frontend/CHANGELOG.md +++ /dev/null @@ -1,12 +0,0 @@ -# imageslider - -## 0.2.1-beta.0 - -### Patch Changes - -- Updated dependencies [[`13ed8a485`](https://github.com/gradio-app/gradio/commit/13ed8a485d5e31d7d75af87fe8654b661edcca93), [`465f58957`](https://github.com/gradio-app/gradio/commit/465f58957f70c7cf3e894beef8a117b28339e3c1)]: - - @gradio/atoms@0.2.0-beta.4 - - @gradio/icons@0.2.0-beta.1 - - @gradio/statustracker@0.3.0-beta.6 - - @gradio/upload@0.3.0-beta.4 - - @gradio/utils@0.2.0-beta.4 diff --git a/js/preview/test/imageslider/frontend/example/Image.svelte b/js/preview/test/imageslider/frontend/example/Image.svelte deleted file mode 100644 index 4544ce0b6882d..0000000000000 --- a/js/preview/test/imageslider/frontend/example/Image.svelte +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - diff --git a/js/preview/test/imageslider/frontend/example/index.ts b/js/preview/test/imageslider/frontend/example/index.ts deleted file mode 100644 index f77af3dcfa039..0000000000000 --- a/js/preview/test/imageslider/frontend/example/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default } from "./Image.svelte"; diff --git a/js/preview/test/imageslider/frontend/interactive/Cropper.svelte b/js/preview/test/imageslider/frontend/interactive/Cropper.svelte deleted file mode 100644 index c26bf2a0775cc..0000000000000 --- a/js/preview/test/imageslider/frontend/interactive/Cropper.svelte +++ /dev/null @@ -1,33 +0,0 @@ - - - - - diff --git a/js/preview/test/imageslider/frontend/interactive/Image.svelte b/js/preview/test/imageslider/frontend/interactive/Image.svelte deleted file mode 100644 index 748e3834a737d..0000000000000 --- a/js/preview/test/imageslider/frontend/interactive/Image.svelte +++ /dev/null @@ -1,447 +0,0 @@ - - - - -
- {#if source === "upload"} - - {#if (value === null && !static_image) || streaming} - - {:else if tool === "select"} - - (handle_clear(e), (tool = "editor"))} - /> - {:else if tool === "editor"} - (tool = "select")} - on:clear={handle_clear} - editable - /> - - - - - - {:else if (tool === "sketch" || tool === "color-sketch") && (value !== null || static_image)} - {#key static_image} - - {/key} - {#if img_width > 0} - - sketch.undo()} - on:clear_mask={handle_mask_clear} - on:remove_image={handle_sketch_clear} - /> - {#if tool === "color-sketch" || tool === "sketch"} - - {/if} - {/if} - {:else} - - - - hello - {/if} - - {:else if source === "canvas"} - sketch.undo()} - on:remove_image={handle_sketch_clear} - /> - {#if tool === "color-sketch"} - - {/if} - - {:else if (value === null && !static_image) || streaming} - {#if source === "webcam" && !static_image} - - tool === "color-sketch" ? handle_upload(e) : handle_save(e, true)} - on:stream={handle_save} - on:error - {streaming} - {pending} - {mirror_webcam} - /> - {/if} - {:else if tool === "select"} - - (handle_clear(e), (tool = "editor"))} - /> - {:else if tool === "editor"} - (tool = "select")} - on:clear={handle_clear} - editable - /> - - - - - - {:else if (tool === "sketch" || tool === "color-sketch") && (value !== null || static_image)} - {#key static_image} - - {/key} - {#if img_width > 0} - - sketch.undo()} - on:remove_image={handle_sketch_clear} - /> - {#if tool === "color-sketch" || tool === "sketch"} - - {/if} - {/if} - {:else} - - - - - - {/if} -
- - diff --git a/js/preview/test/imageslider/frontend/interactive/InteractiveImage.svelte b/js/preview/test/imageslider/frontend/interactive/InteractiveImage.svelte deleted file mode 100644 index 6c1aeb84673fc..0000000000000 --- a/js/preview/test/imageslider/frontend/interactive/InteractiveImage.svelte +++ /dev/null @@ -1,104 +0,0 @@ - - - - - - - - gradio.dispatch("edit")} - on:clear={() => gradio.dispatch("clear")} - on:stream={() => gradio.dispatch("stream")} - on:drag={({ detail }) => (dragging = detail)} - on:upload={() => gradio.dispatch("upload")} - on:select={({ detail }) => gradio.dispatch("select", detail)} - on:share={({ detail }) => gradio.dispatch("share", detail)} - on:error={({ detail }) => { - loading_status = loading_status || {}; - loading_status.status = "error"; - gradio.dispatch("error", detail); - }} - {label} - {show_label} - {pending} - {streaming} - {mirror_webcam} - i18n={gradio.i18n} - > - - - diff --git a/js/preview/test/imageslider/frontend/interactive/ModifySketch.svelte b/js/preview/test/imageslider/frontend/interactive/ModifySketch.svelte deleted file mode 100644 index 8e603f247e958..0000000000000 --- a/js/preview/test/imageslider/frontend/interactive/ModifySketch.svelte +++ /dev/null @@ -1,45 +0,0 @@ - - -
- dispatch("undo")} /> - - {#if show_eraser} - { - dispatch("clear_mask"); - event.stopPropagation(); - }} - /> - {/if} - - { - dispatch("remove_image"); - event.stopPropagation(); - }} - /> -
- - diff --git a/js/preview/test/imageslider/frontend/interactive/Sketch.svelte b/js/preview/test/imageslider/frontend/interactive/Sketch.svelte deleted file mode 100644 index ea2654080f460..0000000000000 --- a/js/preview/test/imageslider/frontend/interactive/Sketch.svelte +++ /dev/null @@ -1,624 +0,0 @@ - - -
- {#if line_count === 0} -
- Start drawing -
- {/if} - {#each canvas_types as { name, zIndex, opacity }} - - {/each} -
- - diff --git a/js/preview/test/imageslider/frontend/interactive/SketchSettings.svelte b/js/preview/test/imageslider/frontend/interactive/SketchSettings.svelte deleted file mode 100644 index 54303f98177d3..0000000000000 --- a/js/preview/test/imageslider/frontend/interactive/SketchSettings.svelte +++ /dev/null @@ -1,77 +0,0 @@ - - -
- - (show_size = !show_size)} - /> - {#if show_size} - - {/if} - - - {#if mode !== "mask"} - - (show_col = !show_col)} - /> - {#if show_col} - - {/if} - - {/if} -
- - diff --git a/js/preview/test/imageslider/frontend/interactive/Webcam.svelte b/js/preview/test/imageslider/frontend/interactive/Webcam.svelte deleted file mode 100644 index e1ec1195a9002..0000000000000 --- a/js/preview/test/imageslider/frontend/interactive/Webcam.svelte +++ /dev/null @@ -1,204 +0,0 @@ - - -
- -
- - diff --git a/js/preview/test/imageslider/frontend/interactive/index.ts b/js/preview/test/imageslider/frontend/interactive/index.ts deleted file mode 100644 index dbae9def8ba49..0000000000000 --- a/js/preview/test/imageslider/frontend/interactive/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as Webcam } from "./Webcam.svelte"; -export { default } from "./InteractiveImage.svelte"; diff --git a/js/preview/test/imageslider/frontend/package.json b/js/preview/test/imageslider/frontend/package.json deleted file mode 100644 index 47718cc42d11c..0000000000000 --- a/js/preview/test/imageslider/frontend/package.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "imageslider", - "version": "0.2.1-beta.0", - "description": "Gradio UI packages", - "type": "module", - "main": "./index.svelte", - "author": "", - "license": "ISC", - "private": true, - "dependencies": { - "@gradio/atoms": "workspace:^", - "@gradio/icons": "workspace:^", - "@gradio/statustracker": "workspace:^", - "@gradio/upload": "workspace:^", - "@gradio/utils": "workspace:^", - "cropperjs": "^1.5.12", - "lazy-brush": "^1.0.1", - "resize-observer-polyfill": "^1.5.1" - }, - "main_changeset": true, - "exports": { - "./package.json": "./package.json", - "./interactive": "./interactive/index.ts", - "./static": "./static/index.ts", - "./example": "./example/index.ts" - } -} diff --git a/js/preview/test/imageslider/frontend/shared/utils.ts b/js/preview/test/imageslider/frontend/shared/utils.ts deleted file mode 100644 index e737479e39f22..0000000000000 --- a/js/preview/test/imageslider/frontend/shared/utils.ts +++ /dev/null @@ -1,24 +0,0 @@ -export const get_coordinates_of_clicked_image = ( - evt: MouseEvent -): [number, number] | null => { - let image = evt.currentTarget as HTMLImageElement; - - const imageRect = image.getBoundingClientRect(); - const xScale = image.naturalWidth / imageRect.width; - const yScale = image.naturalHeight / imageRect.height; - if (xScale > yScale) { - const displayed_height = image.naturalHeight / xScale; - const y_offset = (imageRect.height - displayed_height) / 2; - var x = Math.round((evt.clientX - imageRect.left) * xScale); - var y = Math.round((evt.clientY - imageRect.top - y_offset) * xScale); - } else { - const displayed_width = image.naturalWidth / yScale; - const x_offset = (imageRect.width - displayed_width) / 2; - var x = Math.round((evt.clientX - imageRect.left - x_offset) * yScale); - var y = Math.round((evt.clientY - imageRect.top) * yScale); - } - if (x < 0 || x >= image.naturalWidth || y < 0 || y >= image.naturalHeight) { - return null; - } - return [x, y]; -}; diff --git a/js/preview/test/imageslider/frontend/src/Image.svelte b/js/preview/test/imageslider/frontend/src/Image.svelte deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/js/preview/test/imageslider/frontend/static/ImagePreview.svelte b/js/preview/test/imageslider/frontend/static/ImagePreview.svelte deleted file mode 100644 index f0c06d1c339f8..0000000000000 --- a/js/preview/test/imageslider/frontend/static/ImagePreview.svelte +++ /dev/null @@ -1,95 +0,0 @@ - - - -{#if value_ === null} - -{:else} -
- {#if show_download_button} - - - - {/if} - {#if show_share_button} - { - if (!value) return ""; - let url = await uploadToHuggingFace(value, "base64"); - return ``; - }} - {value} - /> - {/if} -
- - - - -{/if} - - diff --git a/js/preview/test/imageslider/frontend/static/StaticImage.svelte b/js/preview/test/imageslider/frontend/static/StaticImage.svelte deleted file mode 100644 index 30cae5f8138f4..0000000000000 --- a/js/preview/test/imageslider/frontend/static/StaticImage.svelte +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - gradio.dispatch("select", detail)} - on:share={({ detail }) => gradio.dispatch("share", detail)} - on:error={({ detail }) => gradio.dispatch("error", detail)} - {root} - {value} - {label} - {show_label} - {show_download_button} - {selectable} - {show_share_button} - i18n={gradio.i18n} - /> - diff --git a/js/preview/test/imageslider/frontend/static/index.ts b/js/preview/test/imageslider/frontend/static/index.ts deleted file mode 100644 index 8d950f3e426fd..0000000000000 --- a/js/preview/test/imageslider/frontend/static/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default } from "./StaticImage.svelte"; diff --git a/js/preview/test/imageslider/pyproject.toml b/js/preview/test/imageslider/pyproject.toml deleted file mode 100644 index 5c39ab3f4e0a2..0000000000000 --- a/js/preview/test/imageslider/pyproject.toml +++ /dev/null @@ -1,40 +0,0 @@ -[build-system] -requires = ["hatchling", "hatch-requirements-txt", "hatch-fancy-pypi-readme>=22.5.0"] -build-backend = "hatchling.build" - -[project] -name = "imageslider" -version = "0.0.1" -description = "Python library for easily interacting with trained machine learning models" -license = "Apache-2.0" -requires-python = ">=3.8" -authors = [ - { name = "YOUR NAME", email = "YOUREMAIL@domain.com" }, -] -keywords = ["machine learning", "reproducibility", "visualization"] -# Add dependencies here -dependencies = [] -classifiers = [ - 'Development Status :: 3 - Alpha', - 'License :: OSI Approved :: Apache Software License', - 'Operating System :: OS Independent', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3 :: Only', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - 'Topic :: Scientific/Engineering', - 'Topic :: Scientific/Engineering :: Artificial Intelligence', - 'Topic :: Scientific/Engineering :: Visualization', -] - -[tool.hatch.build] -artifacts = [ - "/backend/imageslider/templates", - "*.pyi" -] -packages = ["/backend/imageslider"] - -[tool.hatch.metadata] -allow-direct-references = true \ No newline at end of file diff --git a/js/preview/test/newnewtext/.gitignore b/js/preview/test/newnewtext/.gitignore deleted file mode 100644 index 80a3eb23390b7..0000000000000 --- a/js/preview/test/newnewtext/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -# Python build -.eggs/ -dist/ -*.pyc -__pycache__/ -*.py[cod] -*$py.class -__tmp/* -*.pyi -templates/ \ No newline at end of file diff --git a/js/preview/test/newnewtext/backend/newnewtext/__init__.py b/js/preview/test/newnewtext/backend/newnewtext/__init__.py deleted file mode 100644 index 4c7b7a5942bd6..0000000000000 --- a/js/preview/test/newnewtext/backend/newnewtext/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ - -from .newnewtext import NewNewText - -__all__ = ['NewNewText'] diff --git a/js/preview/test/newnewtext/backend/newnewtext/newnewtext.py b/js/preview/test/newnewtext/backend/newnewtext/newnewtext.py deleted file mode 100644 index 68745b63862cf..0000000000000 --- a/js/preview/test/newnewtext/backend/newnewtext/newnewtext.py +++ /dev/null @@ -1,196 +0,0 @@ -"""gr.Textbox() component.""" - -from __future__ import annotations - -from typing import Any, Callable, Literal - -from gradio_client.documentation import document, set_documentation_group - -from gradio.components.base import ( - Component, - FormComponent, - _Keywords, -) -from gradio.events import Events - -set_documentation_group("component") - - -@document() -class NewNewText(FormComponent): - """ - Creates a textarea for user to enter string input or display string output. - Preprocessing: passes textarea value as a {str} into the function. - Postprocessing: expects a {str} returned from function and sets textarea value to it. - Examples-format: a {str} representing the textbox input. - - Demos: hello_world, diff_texts, sentence_builder - Guides: creating-a-chatbot, real-time-speech-recognition - """ - - EVENTS = [Events.change, Events.input, Events.select, Events.submit, Events.focus] - - def __init__( - self, - value: str | Callable | None = "", - *, - lines: int = 1, - max_lines: int = 20, - placeholder: str | None = None, - label: str | None = None, - info: str | None = None, - every: float | None = None, - show_label: bool | None = None, - container: bool = True, - scale: int | None = None, - min_width: int = 160, - interactive: bool | None = None, - visible: bool = True, - elem_id: str | None = None, - autofocus: bool = False, - elem_classes: list[str] | str | None = None, - type: Literal["text", "password", "email"] = "text", - text_align: Literal["left", "right"] | None = None, - rtl: bool = False, - show_copy_button: bool = False, - **kwargs, - ): - """ - Parameters: - value: default text to provide in textarea. If callable, the function will be called whenever the app loads to set the initial value of the component. - lines: minimum number of line rows to provide in textarea. - max_lines: maximum number of line rows to provide in textarea. - placeholder: placeholder hint to provide behind textarea. - label: component name in interface. - info: additional component description. - every: If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute. - show_label: if True, will display label. - container: If True, will place the component in a container - providing some extra padding around the border. - scale: relative width compared to adjacent Components in a Row. For example, if Component A has scale=2, and Component B has scale=1, A will be twice as wide as B. Should be an integer. - min_width: minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first. - interactive: if True, will be rendered as an editable textbox; if False, editing will be disabled. If not provided, this is inferred based on whether the component is used as an input or output. - visible: If False, component will be hidden. - autofocus: If True, will focus on the textbox when the page loads. - elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles. - elem_classes: An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles. - render: If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later. - root_url: The remote URL that of the Gradio app that this component belongs to. Used in `gr.load()`. Should not be set manually. - type: The type of textbox. One of: 'text', 'password', 'email', Default is 'text'. - text_align: How to align the text in the textbox, can be: "left", "right", or None (default). If None, the alignment is left if `rtl` is False, or right if `rtl` is True. Can only be changed if `type` is "text". - rtl: If True and `type` is "text", sets the direction of the text to right-to-left (cursor appears on the left of the text). Default is False, which renders cursor on the right. - show_copy_button: If True, includes a copy button to copy the text in the textbox. Only applies if show_label is True. - """ - if type not in ["text", "password", "email"]: - raise ValueError('`type` must be one of "text", "password", or "email".') - - self.lines = lines - if type == "text": - self.max_lines = max(lines, max_lines) - else: - self.max_lines = 1 - self.placeholder = placeholder - self.show_copy_button = show_copy_button - self.autofocus = autofocus - super().__init__( - label=label, - info=info, - every=every, - show_label=show_label, - container=container, - scale=scale, - min_width=min_width, - interactive=interactive, - visible=visible, - elem_id=elem_id, - elem_classes=elem_classes, - render=render, - root_url=root_url, - _skip_init_processing=_skip_init_processing, - value=value, - **kwargs, - ) - self.type = type - self.rtl = rtl - self.text_align = text_align - - def get_config(self): - return { - "lines": self.lines, - "max_lines": self.max_lines, - "placeholder": self.placeholder, - "value": self.value, - "type": self.type, - "autofocus": self.autofocus, - "show_copy_button": self.show_copy_button, - "container": self.container, - "text_align": self.text_align, - "rtl": self.rtl, - **Component.get_config(self), - } - - @staticmethod - def update( - value: str | Literal[_Keywords.NO_VALUE] | None = _Keywords.NO_VALUE, - lines: int | None = None, - max_lines: int | None = None, - placeholder: str | None = None, - label: str | None = None, - info: str | None = None, - show_label: bool | None = None, - container: bool | None = None, - scale: int | None = None, - min_width: int | None = None, - visible: bool | None = None, - interactive: bool | None = None, - type: Literal["text", "password", "email"] | None = None, - text_align: Literal["left", "right"] | None = None, - rtl: bool | None = None, - show_copy_button: bool | None = None, - autofocus: bool | None = None, - ): - return { - "lines": lines, - "max_lines": max_lines, - "placeholder": placeholder, - "label": label, - "info": info, - "show_label": show_label, - "container": container, - "scale": scale, - "min_width": min_width, - "visible": visible, - "value": value, - "type": type, - "interactive": interactive, - "show_copy_button": show_copy_button, - "autofocus": autofocus, - "text_align": text_align, - "rtl": rtl, - "__type__": "update", - } - - def preprocess(self, x: str | None) -> str | None: - """ - Preprocesses input (converts it to a string) before passing it to the function. - Parameters: - x: text - Returns: - text - """ - return None if x is None else str(x) - - def postprocess(self, y: str | None) -> str | None: - """ - Postproccess the function output y by converting it to a str before passing it to the frontend. - Parameters: - y: function output to postprocess. - Returns: - text - """ - return None if y is None else str(y) - - def api_info(self) -> dict[str, list[str]]: - return {"type": "string"} - - def example_inputs(self) -> Any: - return "Hello!!" diff --git a/js/preview/test/newnewtext/demo/__init__.py b/js/preview/test/newnewtext/demo/__init__.py deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/js/preview/test/newnewtext/demo/app.py b/js/preview/test/newnewtext/demo/app.py deleted file mode 100644 index 9d96f3fb5f23d..0000000000000 --- a/js/preview/test/newnewtext/demo/app.py +++ /dev/null @@ -1,7 +0,0 @@ -import gradio as gr -from newnewtext import NewNewText - -with gr.Blocks() as demo: - NewNewText() - -demo.launch() diff --git a/js/preview/test/newnewtext/frontend/CHANGELOG.md b/js/preview/test/newnewtext/frontend/CHANGELOG.md deleted file mode 100644 index 91858c7794976..0000000000000 --- a/js/preview/test/newnewtext/frontend/CHANGELOG.md +++ /dev/null @@ -1,7 +0,0 @@ -# newnewtext - -## 0.2.0-beta.0 - -### Features - -- [#5498](https://github.com/gradio-app/gradio/pull/5498) [`85ba6de13`](https://github.com/gradio-app/gradio/commit/85ba6de136a45b3e92c74e410bb27e3cbe7138d7) - Adds the ability to build the frontend and backend of custom components in preparation for publishing to pypi using `gradio_component build`. Thanks [@pngwn](https://github.com/pngwn)! \ No newline at end of file diff --git a/js/preview/test/newnewtext/frontend/example/Textbox.svelte b/js/preview/test/newnewtext/frontend/example/Textbox.svelte deleted file mode 100644 index 1fdf7500fa285..0000000000000 --- a/js/preview/test/newnewtext/frontend/example/Textbox.svelte +++ /dev/null @@ -1,46 +0,0 @@ - - -
- {value} -
- - diff --git a/js/preview/test/newnewtext/frontend/example/index.ts b/js/preview/test/newnewtext/frontend/example/index.ts deleted file mode 100644 index 42397adf0d930..0000000000000 --- a/js/preview/test/newnewtext/frontend/example/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default } from "./Textbox.svelte"; diff --git a/js/preview/test/newnewtext/frontend/interactive/InteractiveTextbox.svelte b/js/preview/test/newnewtext/frontend/interactive/InteractiveTextbox.svelte deleted file mode 100644 index 47226d4eebe2b..0000000000000 --- a/js/preview/test/newnewtext/frontend/interactive/InteractiveTextbox.svelte +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - {#if loading_status} - - {/if} - - gradio.dispatch("change", value)} - on:input={() => gradio.dispatch("input")} - on:submit={() => gradio.dispatch("submit")} - on:blur={() => gradio.dispatch("blur")} - on:select={(e) => gradio.dispatch("select", e.detail)} - on:focus={() => gradio.dispatch("focus")} - /> - diff --git a/js/preview/test/newnewtext/frontend/interactive/index.ts b/js/preview/test/newnewtext/frontend/interactive/index.ts deleted file mode 100644 index a036461c736fd..0000000000000 --- a/js/preview/test/newnewtext/frontend/interactive/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default } from "./InteractiveTextbox.svelte"; diff --git a/js/preview/test/newnewtext/frontend/package.json b/js/preview/test/newnewtext/frontend/package.json deleted file mode 100644 index b188ca12a0d4c..0000000000000 --- a/js/preview/test/newnewtext/frontend/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "newnewtext", - "version": "0.2.0-beta.0", - "description": "Gradio UI packages", - "type": "module", - "main": "index.svelte", - "author": "", - "license": "ISC", - "private": true, - "main_changeset": true, - "exports": { - "./package.json": "./package.json", - "./interactive": "./interactive/index.ts", - "./static": "./static/index.ts", - "./example": "./example/index.ts" - }, - "dependencies": { - "@gradio/atoms": "workspace:^", - "@gradio/icons": "workspace:^", - "@gradio/statustracker": "workspace:^", - "@gradio/utils": "workspace:^" - } -} diff --git a/js/preview/test/newnewtext/frontend/shared/Dynamic.svelte b/js/preview/test/newnewtext/frontend/shared/Dynamic.svelte deleted file mode 100644 index 21555e35dbcba..0000000000000 --- a/js/preview/test/newnewtext/frontend/shared/Dynamic.svelte +++ /dev/null @@ -1,296 +0,0 @@ - - - -