Skip to content

Commit

Permalink
Allow passing height and width as string in Blocks.svelte (#6569)
Browse files Browse the repository at this point in the history
* Allow % string in blocks
Modify docstring in chatbot

* add % height chatbot story

* add changeset

* typo 馃ゲ

* func tweak

* formatting

* add changeset

* add changeset

* add str to height params

* update docstring for height

* Allow passing width as a string
Update width docstrings

* formatting

* add changeset

* add width/height param description

* tweak

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
hannahblair and gradio-pr-bot committed Dec 11, 2023
1 parent bdf81fe commit 4d1cbbc
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 45 deletions.
6 changes: 6 additions & 0 deletions .changeset/two-hounds-stay.md
@@ -0,0 +1,6 @@
---
"@gradio/atoms": minor
"gradio": minor
---

feat:Allow passing height and width as string in `Blocks.svelte`
8 changes: 4 additions & 4 deletions gradio/components/annotated_image.py
Expand Up @@ -51,8 +51,8 @@ def __init__(
| None = None,
*,
show_legend: bool = True,
height: int | None = None,
width: int | None = None,
height: int | str | None = None,
width: int | str | None = None,
color_map: dict[str, str] | None = None,
label: str | None = None,
every: float | None = None,
Expand All @@ -69,8 +69,8 @@ def __init__(
Parameters:
value: Tuple of base image and list of (subsection, label) pairs.
show_legend: If True, will show a legend of the subsections.
height: Height of the displayed image.
width: Width of the displayed image.
height: The height of the image, specified in pixels if a number is passed, or in CSS units if a string is passed.
width: The width of the image, specified in pixels if a number is passed, or in CSS units if a string is passed.
color_map: A dictionary mapping labels to colors. The colors must be specified as hex codes.
label: The label for this component. Appears above the component and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.
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.
Expand Down
8 changes: 4 additions & 4 deletions gradio/components/bar_plot.py
Expand Up @@ -55,8 +55,8 @@ def __init__(
"none",
]
| None = None,
height: int | None = None,
width: int | None = None,
height: int | str | None = None,
width: int | str | None = None,
y_lim: list[int] | None = None,
caption: str | None = None,
interactive: bool | None = True,
Expand Down Expand Up @@ -90,8 +90,8 @@ def __init__(
color_legend_title: The title given to the color legend. By default, uses the value of color parameter.
group_title: The label displayed on top of the subplot columns (or rows if vertical=True). Use an empty string to omit.
color_legend_position: The position of the color legend. If the string value 'none' is passed, this legend is omitted. For other valid position values see: https://vega.github.io/vega/docs/legends/#orientation.
height: The height of the plot in pixels.
width: The width of the plot in pixels.
height: The height of the plot, specified in pixels if a number is passed, or in CSS units if a string is passed.
width: The width of the plot, specified in pixels if a number is passed, or in CSS units if a string is passed.
y_lim: A tuple of list containing the limits for the y-axis, specified as [y_min, y_max].
caption: The (optional) caption to display below the plot.
interactive: Whether users should be able to interact with the plot by panning or zooming with their mouse or trackpad.
Expand Down
4 changes: 2 additions & 2 deletions gradio/components/chatbot.py
Expand Up @@ -56,7 +56,7 @@ def __init__(
elem_id: str | None = None,
elem_classes: list[str] | str | None = None,
render: bool = True,
height: int | None = None,
height: int | str | None = None,
latex_delimiters: list[dict[str, str | bool]] | None = None,
rtl: bool = False,
show_share_button: bool | None = None,
Expand All @@ -82,7 +82,7 @@ def __init__(
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.
height: height of the component in pixels.
height: The height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed.
latex_delimiters: A list of dicts of the form {"left": open delimiter (str), "right": close delimiter (str), "display": whether to display in newline (bool)} that will be used to render LaTeX expressions. If not provided, `latex_delimiters` is set to `[{ "left": "$$", "right": "$$", "display": True }]`, so only expressions enclosed in $$ delimiters will be rendered as LaTeX, and in a new line. Pass in an empty list to disable LaTeX rendering. For more information, see the [KaTeX documentation](https://katex.org/docs/autorender.html).
rtl: If True, sets the direction of the rendered text to right-to-left. Default is False, which renders text left-to-right.
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.
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/dataframe.py
Expand Up @@ -85,7 +85,7 @@ def __init__(
label: The label for this component. Appears above the component and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.
show_label: if True, will display label.
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.
height: The maximum height of the dataframe, in pixels. If more rows are created than can fit in the height, a scrollbar will appear.
height: The maximum height of the dataframe, specified in pixels if a number is passed, or in CSS units if a string is passed. If more rows are created than can fit in the height, a scrollbar will appear.
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 edit the dataframe; if False, can only be used to display data. If not provided, this is inferred based on whether the component is used as an input or output.
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/file.py
Expand Up @@ -71,7 +71,7 @@ def __init__(
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.
height: The maximum height of the file component, in pixels. If more files are uploaded than can fit in the height, a scrollbar will appear.
height: The maximum height of the file component, specified in pixels if a number is passed, or in CSS units if a string is passed. If more files are uploaded than can fit in the height, a scrollbar will appear.
interactive: if True, will allow users to upload a file; if False, can only be used to display files. 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.
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.
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/file_explorer.py
Expand Up @@ -67,7 +67,7 @@ def __init__(
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.
height: The maximum height of the file component, in pixels. If more files are uploaded than can fit in the height, a scrollbar will appear.
height: The maximum height of the file component, specified in pixels if a number is passed, or in CSS units if a string is passed. If more files are uploaded than can fit in the height, a scrollbar will appear.
interactive: if True, will allow users to upload a file; if False, can only be used to display files. 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.
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.
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/gallery.py
Expand Up @@ -88,7 +88,7 @@ def __init__(
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.
columns: Represents the number of images that should be shown in one row, for each of the six standard screen sizes (<576px, <768px, <992px, <1200px, <1400px, >1400px). If fewer than 6 are given then the last will be used for all subsequent breakpoints
rows: Represents the number of rows in the image grid, for each of the six standard screen sizes (<576px, <768px, <992px, <1200px, <1400px, >1400px). If fewer than 6 are given then the last will be used for all subsequent breakpoints
height: The height of the gallery component, in pixels. If more images are displayed than can fit in the height, a scrollbar will appear.
height: The height of the gallery component, specified in pixels if a number is passed, or in CSS units if a string is passed. If more images are displayed than can fit in the height, a scrollbar will appear.
allow_preview: If True, images in the gallery will be enlarged when they are clicked. Default is True.
preview: If True, Gallery will start in preview mode, which shows all of the images as thumbnails and allows the user to click on them to view them in full size. Only works if allow_preview is True.
selected_index: The index of the image that should be initially selected. If None, no image will be selected at start. If provided, will set Gallery to preview mode unless allow_preview is set to False.
Expand Down
8 changes: 4 additions & 4 deletions gradio/components/image.py
Expand Up @@ -46,8 +46,8 @@ def __init__(
self,
value: str | _Image.Image | np.ndarray | None = None,
*,
height: int | None = None,
width: int | None = None,
height: int | str | None = None,
width: int | str | None = None,
image_mode: Literal[
"1", "L", "P", "RGB", "RGBA", "CMYK", "YCbCr", "LAB", "HSV", "I", "F"
] = "RGB",
Expand All @@ -72,8 +72,8 @@ def __init__(
"""
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.
height: Height of the displayed image in pixels.
width: Width of the displayed image in pixels.
height: The height of the displayed image, specified in pixels if a number is passed, or in CSS units if a string is passed.
width: The width of the displayed image, specified in pixels if a number is passed, or in CSS units if a string is passed.
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.
sources: List of sources for the image. "upload" creates a box where user can drop an image file, "webcam" allows user to take snapshot from their webcam, "clipboard" allows users to paste an image from the clipboard. If None, defaults to ["upload", "webcam", "clipboard"] if streaming is False, otherwise defaults to ["webcam"].
type: The format the image is converted 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. If the image is SVG, the `type` is ignored and the filepath of the SVG is returned.
Expand Down
8 changes: 4 additions & 4 deletions gradio/components/image_editor.py
Expand Up @@ -87,8 +87,8 @@ def __init__(
self,
value: str | _Image.Image | np.ndarray | None = None,
*,
height: int | None = None,
width: int | None = None,
height: int | str | None = None,
width: int | str | None = None,
image_mode: Literal[
"1", "L", "P", "RGB", "RGBA", "CMYK", "YCbCr", "LAB", "HSV", "I", "F"
] = "RGBA",
Expand Down Expand Up @@ -121,8 +121,8 @@ def __init__(
"""
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.
height: Height of the displayed image in pixels.
width: Width of the displayed image in pixels.
height: The height of the displayed image, specified in pixels if a number is passed, or in CSS units if a string is passed.
width: The width of the displayed image, specified in pixels if a number is passed, or in CSS units if a string is passed.
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.
sources: List of sources for the image. "upload" creates a box where user can drop an image file, "webcam" allows user to take snapshot from their webcam, "clipboard" allows users to paste an image from the clipboard.
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.
Expand Down
8 changes: 4 additions & 4 deletions gradio/components/line_plot.py
Expand Up @@ -67,8 +67,8 @@ def __init__(
"none",
]
| None = None,
height: int | None = None,
width: int | None = None,
height: int | str | None = None,
width: int | str | None = None,
x_lim: list[int] | None = None,
y_lim: list[int] | None = None,
caption: str | None = None,
Expand Down Expand Up @@ -103,8 +103,8 @@ def __init__(
stroke_dash_legend_title: The title given to the stroke_dash legend. By default, uses the value of the stroke_dash parameter.
color_legend_position: The position of the color legend. If the string value 'none' is passed, this legend is omitted. For other valid position values see: https://vega.github.io/vega/docs/legends/#orientation.
stroke_dash_legend_position: The position of the stoke_dash legend. If the string value 'none' is passed, this legend is omitted. For other valid position values see: https://vega.github.io/vega/docs/legends/#orientation.
height: The height of the plot in pixels.
width: The width of the plot in pixels.
height: The height of the plot, specified in pixels if a number is passed, or in CSS units if a string is passed.
width: The width of the plot, specified in pixels if a number is passed, or in CSS units if a string is passed.
x_lim: A tuple or list containing the limits for the x-axis, specified as [x_min, x_max].
y_lim: A tuple of list containing the limits for the y-axis, specified as [y_min, y_max].
caption: The (optional) caption to display below the plot.
Expand Down
4 changes: 2 additions & 2 deletions gradio/components/model3d.py
Expand Up @@ -43,7 +43,7 @@ def __init__(
),
zoom_speed: float = 1,
pan_speed: float = 1,
height: int | None = None,
height: int | str | None = None,
label: str | None = None,
show_label: bool | None = None,
every: float | None = None,
Expand All @@ -63,7 +63,7 @@ def __init__(
camera_position: initial camera position of scene, provided as a tuple of `(alpha, beta, radius)`. Each value is optional. If provided, `alpha` and `beta` should be in degrees reflecting the angular position along the longitudinal and latitudinal axes, respectively. Radius corresponds to the distance from the center of the object to the camera.
zoom_speed: the speed of zooming in and out of the scene when the cursor wheel is rotated or when screen is pinched on a mobile device. Should be a positive float, increase this value to make zooming faster, decrease to make it slower. Affects the wheelPrecision property of the camera.
pan_speed: the speed of panning the scene when the cursor is dragged or when the screen is dragged on a mobile device. Should be a positive float, increase this value to make panning faster, decrease to make it slower. Affects the panSensibility property of the camera.
height: height of the model3D component, in pixels.
height: The height of the model3D component, specified in pixels if a number is passed, or in CSS units if a string is passed.
interactive: if True, will allow users to upload a file; if False, can only be used to display files. If not provided, this is inferred based on whether the component is used as an input or output.
label: The label for this component. Appears above the component and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.
show_label: if True, will display label.
Expand Down

0 comments on commit 4d1cbbc

Please sign in to comment.