diff --git a/.changeset/hip-apes-help.md b/.changeset/hip-apes-help.md new file mode 100644 index 0000000000000..f62272bfc22ee --- /dev/null +++ b/.changeset/hip-apes-help.md @@ -0,0 +1,9 @@ +--- +"@gradio/atoms": minor +"@gradio/image": minor +"@gradio/imageeditor": minor +"@gradio/simpleimage": minor +"gradio": minor +--- + +feat:Add `placeholder` param to Image and ImageEditor to replace upload image text diff --git a/gradio/components/image.py b/gradio/components/image.py index 67ff6f9466b15..695949b819c0c 100644 --- a/gradio/components/image.py +++ b/gradio/components/image.py @@ -74,6 +74,7 @@ def __init__( key: int | str | None = None, mirror_webcam: bool = True, show_share_button: bool | None = None, + placeholder: str | None = None, show_fullscreen_button: bool = True, ): """ @@ -102,6 +103,7 @@ def __init__( key: if assigned, will be used to assume identity across a re-render. Components that have the same key across a re-render will have their value preserved. mirror_webcam: If True webcam will be mirrored. Default is True. 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. + placeholder: Custom text for the upload area. Overrides default upload messages when provided. Accepts new lines and `#` to designate a heading. show_fullscreen_button: If True, will show a fullscreen icon in the corner of the component that allows user to view the image in fullscreen mode. If False, icon does not appear. """ self.format = format @@ -141,6 +143,7 @@ def __init__( else show_share_button ) self.show_fullscreen_button = show_fullscreen_button + self.placeholder = placeholder super().__init__( label=label, every=every, diff --git a/gradio/components/image_editor.py b/gradio/components/image_editor.py index b59798760b78f..67487dc250813 100644 --- a/gradio/components/image_editor.py +++ b/gradio/components/image_editor.py @@ -171,6 +171,7 @@ def __init__( elem_classes: list[str] | str | None = None, render: bool = True, key: int | str | None = None, + placeholder: str | None = None, mirror_webcam: bool = True, show_share_button: bool | None = None, _selectable: bool = False, @@ -205,6 +206,7 @@ def __init__( 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. key: if assigned, will be used to assume identity across a re-render. Components that have the same key across a re-render will have their value preserved. + placeholder: Custom text for the upload area. Overrides default upload messages when provided. Accepts new lines and `#` to designate a heading. mirror_webcam: If True webcam will be mirrored. Default is True. 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. crop_size: The size of the crop box in pixels. If a tuple, the first value is the width and the second value is the height. If a string, the value must be a ratio in the form `width:height` (e.g. "16:9"). @@ -257,6 +259,7 @@ def __init__( self.layers = layers self.canvas_size = canvas_size self.show_fullscreen_button = show_fullscreen_button + self.placeholder = placeholder super().__init__( label=label, diff --git a/gradio/templates.py b/gradio/templates.py index 4ed9633fac583..be9f7e4e5a915 100644 --- a/gradio/templates.py +++ b/gradio/templates.py @@ -115,6 +115,7 @@ def __init__( elem_classes: list[str] | str | None = None, render: bool = True, key: int | str | None = None, + placeholder: str | None = None, mirror_webcam: bool = True, show_share_button: bool | None = None, _selectable: bool = False, @@ -150,6 +151,7 @@ def __init__( elem_classes=elem_classes, render=render, key=key, + placeholder=placeholder, mirror_webcam=mirror_webcam, show_share_button=show_share_button, _selectable=_selectable, @@ -210,6 +212,7 @@ def __init__( layers: bool = True, canvas_size: tuple[int, int] | None = None, show_fullscreen_button: bool = True, + placeholder: str | None = None, ): super().__init__( value=value, @@ -243,6 +246,7 @@ def __init__( layers=layers, canvas_size=canvas_size, show_fullscreen_button=show_fullscreen_button, + placeholder=placeholder, ) @@ -285,6 +289,7 @@ def __init__( elem_classes: list[str] | str | None = None, render: bool = True, key: int | str | None = None, + placeholder: str | None = None, mirror_webcam: bool = True, show_share_button: bool | None = None, _selectable: bool = False, @@ -320,6 +325,7 @@ def __init__( elem_classes=elem_classes, render=render, key=key, + placeholder=placeholder, mirror_webcam=mirror_webcam, show_share_button=show_share_button, _selectable=_selectable, diff --git a/js/atoms/src/UploadText.svelte b/js/atoms/src/UploadText.svelte index b2465b1859daf..5902eb6666eff 100644 --- a/js/atoms/src/UploadText.svelte +++ b/js/atoms/src/UploadText.svelte @@ -1,6 +1,8 @@
{paragraph}
+ {/if} + {:else} + {i18n(defs[type] || defs.file)} - {#if mode !== "short"} - - {i18n("common.or")} - - {message || i18n("upload_text.click_to_upload")} + {#if mode !== "short"} + - {i18n("common.or")} - + {message || i18n("upload_text.click_to_upload")} + {/if} {/if}