Skip to main content

A gradio component to upload images and process point/box prompts with more visible boxes.

Project description

gradio_image_prompter_visible_box

Static Badge

A gradio component to upload images and process point/box prompts with more visible boxes.

Installation

pip install gradio_image_prompter_visible_box

Usage

import gradio as gr
from gradio_image_prompter import ImagePrompter

demo = gr.Interface(
    lambda prompts: (prompts["image"], prompts["points"]),
    ImagePrompter(show_label=False),
    [gr.Image(show_label=False), gr.Dataframe(label="Points")],
)
if __name__ == '__main__':
    demo.launch()

ImagePrompter

Initialization

name type default description
value
str | _Image.Image | np.ndarray | None
None A PIL Image, numpy array, path or URL for the default value. If callable, it will be called set the initial value.
height
int | None
None Height of the displayed image in pixels.
width
int | None
None Width of the displayed image in pixels.
image_mode
Literal[
    "1",
    "L",
    "P",
    "RGB",
    "RGBA",
    "CMYK",
    "YCbCr",
    "LAB",
    "HSV",
    "I",
    "F",
]
"RGB" "RGB" if color, or "L" if black and white. See https://pillow.readthedocs.io/en/stable/handbook/concepts.html.
sources
list[Literal["upload", "clipboard"]] | None
None List of sources for the image.
type
Literal["numpy", "pil", "filepath"]
"numpy" The format the image is converted before being passed into the prediction function.
label
str | None
None The label for this component.
every
float | None
None If `value` is a callable, run the function 'every' number of seconds while the client connection is open.
show_label
bool | None
None if True, will display label.
show_download_button
bool
True If True, will display button to download image.
container
bool
True If True, will place the component in a container - providing some extra padding around the border.
scale
int | None
None relative width compared to adjacent Components in a Row. Should be an integer.
min_width
int
160 minimum pixel width, will wrap if not sufficient screen space to satisfy this value.
interactive
bool | None
None if True, will allow users to upload and edit an image; if False, can only be used to display images.
visible
bool
True If False, component will be hidden.
elem_id
str | None
None An optional string that is assigned as the id of this component in the HTML DOM.
elem_classes
list[str] | str | None
None An optional list of strings that are assigned as the classes of this component in the HTML DOM.
render
bool
True If False, component will not render be rendered in the Blocks context.
show_share_button
bool | None
None If True, show a share icon that allows user to share outputs to Hugging Face Spaces Discussions.

Events

name description
clear This listener is triggered when the user clears the ImagePrompter using the X button for the component.
change Triggered when the value of the ImagePrompter changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See .input() for a listener that is only triggered by user input.
stream This listener is triggered when the user streams the ImagePrompter.
select Event listener for when the user selects or deselects the ImagePrompter. Uses event data gradio.SelectData to carry value referring to the label of the ImagePrompter, and selected to refer to state of the ImagePrompter. See EventData documentation on how to use this event data
upload This listener is triggered when the user uploads a file into the ImagePrompter.

User function

The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).

  • When used as an Input, the component only impacts the input signature of the user function.
  • When used as an output, the component only impacts the return signature of the user function.

The code snippet below is accurate in cases where the component is used as both an input and an output.

  • As output: Is passed, passes the uploaded image as a numpy.array, PIL.Image or str filepath depending on type. For SVGs, the type parameter is ignored and the filepath of the SVG is returned.
def predict(
    value: PromptValue | None
) -> PromptValue:
    return value

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gradio_image_prompter_visible_box-0.1.0.tar.gz (125.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file gradio_image_prompter_visible_box-0.1.0.tar.gz.

File metadata

File hashes

Hashes for gradio_image_prompter_visible_box-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a4cda0e43908662ac2a0ce9a04804945e22c66c197cd0406d21cb43e8c99115f
MD5 21a664597681df1d277ac08d785e31c8
BLAKE2b-256 8932324a25c6f4171f5d627b378925271a777645e6e8da71e768f9b97d062fe0

See more details on using hashes here.

File details

Details for the file gradio_image_prompter_visible_box-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gradio_image_prompter_visible_box-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d3c4d956ec762d361cfd588239197f12b391cdd0eda327031fc374cae2b44756
MD5 8c7b8ccb3e1973115905fcb34d79ee15
BLAKE2b-256 7a521a50dd52f6ddca98a7d51a989aa8d9346380b97974a329ffc43f4ee75a68

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page