diff --git a/.changeset/stale-bags-study.md b/.changeset/stale-bags-study.md new file mode 100644 index 0000000000000..c57fb7bec10bd --- /dev/null +++ b/.changeset/stale-bags-study.md @@ -0,0 +1,8 @@ +--- +"@gradio/row": patch +"@gradio/tabitem": patch +"@gradio/tabs": patch +"gradio": patch +--- + +fix:Allow propogation of fill_height through Rows and Tabs, via scale diff --git a/demo/tabbed_interface_lite/run.ipynb b/demo/tabbed_interface_lite/run.ipynb index 26c5707d663ec..2b8ca0ee20c0d 100644 --- a/demo/tabbed_interface_lite/run.ipynb +++ b/demo/tabbed_interface_lite/run.ipynb @@ -1 +1 @@ -{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: tabbed_interface_lite"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "\n", "hello_world = gr.Interface(lambda name: \"Hello \" + name, \"text\", \"text\")\n", "bye_world = gr.Interface(lambda name: \"Bye \" + name, \"text\", \"text\")\n", "\n", "demo = gr.TabbedInterface([hello_world, bye_world], [\"Hello World\", \"Bye World\"])\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5} \ No newline at end of file +{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: tabbed_interface_lite"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "\n", "hello_world = gr.Interface(lambda name: \"Hello \" + name, \"text\", \"text\")\n", "bye_world = gr.Interface(lambda name: \"Bye \" + name, \"text\", \"text\")\n", "chat = gr.ChatInterface(lambda *args: \"Hello \" + args[0])\n", "\n", "demo = gr.TabbedInterface([hello_world, bye_world, chat], [\"Hello World\", \"Bye World\", \"Chat\"])\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5} \ No newline at end of file diff --git a/demo/tabbed_interface_lite/run.py b/demo/tabbed_interface_lite/run.py index d4bde163c758d..cfba160c21c5b 100644 --- a/demo/tabbed_interface_lite/run.py +++ b/demo/tabbed_interface_lite/run.py @@ -2,8 +2,9 @@ hello_world = gr.Interface(lambda name: "Hello " + name, "text", "text") bye_world = gr.Interface(lambda name: "Bye " + name, "text", "text") +chat = gr.ChatInterface(lambda *args: "Hello " + args[0]) -demo = gr.TabbedInterface([hello_world, bye_world], ["Hello World", "Bye World"]) +demo = gr.TabbedInterface([hello_world, bye_world, chat], ["Hello World", "Bye World", "Chat"]) if __name__ == "__main__": demo.launch() diff --git a/gradio/chat_interface.py b/gradio/chat_interface.py index cb729b11b7573..0770a9e156d78 100644 --- a/gradio/chat_interface.py +++ b/gradio/chat_interface.py @@ -260,7 +260,7 @@ def __init__( with Column(): self._render_header() if self.save_history: - with Row(): + with Row(scale=1): self._render_history_area() with Column(scale=6): self._render_chatbot_area( @@ -288,6 +288,7 @@ def _render_history_area(self): variant="primary", size="md", icon=utils.get_icon_path("plus.svg"), + # scale=0, ) self.chat_history_dataset = Dataset( components=[Textbox(visible=False)], diff --git a/gradio/interface.py b/gradio/interface.py index fe10d63fc662f..2d02671033491 100644 --- a/gradio/interface.py +++ b/gradio/interface.py @@ -971,6 +971,7 @@ def __init__( css=css, js=js, head=head, + fill_height=True, ) if tab_names is None: tab_names = [f"Tab {i}" for i in range(len(interface_list))] @@ -981,7 +982,10 @@ def __init__( ) with Tabs(): for interface, tab_name in zip(interface_list, tab_names, strict=False): - with Tab(label=tab_name): + with Tab( + label=tab_name, + scale=1 if interface.fill_height else 0, + ): interface.render() diff --git a/gradio/layouts/row.py b/gradio/layouts/row.py index 0bcc0e47e3f85..2d9d94d3ec34b 100644 --- a/gradio/layouts/row.py +++ b/gradio/layouts/row.py @@ -1,5 +1,6 @@ from __future__ import annotations +import warnings from typing import Literal from gradio_client.documentation import document @@ -30,6 +31,7 @@ def __init__( visible: bool = True, elem_id: str | None = None, elem_classes: list[str] | str | None = None, + scale: int = 0, render: bool = True, height: int | str | None = None, max_height: int | str | None = None, @@ -43,6 +45,7 @@ def __init__( visible: If False, row 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. elem_classes: An optional string or list of strings that are assigned as the class of this component in the HTML DOM. Can be used for targeting CSS styles. + scale: relative height compared to adjacent elements. 1 or greater indicates the Row will expand in height, and any child columns will also expand to fill the height. render: If False, this layout will not be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later. height: The height of the row, specified in pixels if a number is passed, or in CSS units if a string is passed. If content exceeds the height, the row will scroll vertically. If not set, the row will expand to fit the content. max_height: The maximum height of the row, specified in pixels if a number is passed, or in CSS units if a string is passed. If content exceeds the height, the row will scroll vertically. If content is shorter than the height, the row will shrink to fit the content. Will not have any effect if `height` is set and is smaller than `max_height`. @@ -58,6 +61,12 @@ def __init__( self.height = height self.max_height = max_height self.min_height = min_height + if scale != round(scale): + warnings.warn( + f"'scale' value should be an integer. Using {scale} will cause issues." + ) + + self.scale = scale BlockContext.__init__( self, diff --git a/gradio/layouts/tabs.py b/gradio/layouts/tabs.py index 726b4550b2671..20f5bf06ff8c0 100644 --- a/gradio/layouts/tabs.py +++ b/gradio/layouts/tabs.py @@ -67,6 +67,7 @@ def __init__( id: int | str | None = None, elem_id: str | None = None, elem_classes: list[str] | str | None = None, + scale: int = 0, render: bool = True, ): """ @@ -76,6 +77,7 @@ def __init__( elem_id: An optional string that is assigned as the id of the