gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
33.96k stars 2.58k forks source link

equal_height is not propagated to components in columns #3202

Closed freddyaboulton closed 1 month ago

freddyaboulton commented 1 year ago

Describe the bug

If you have a row with columns, the equal_height property of the row is not propagated down to the components within the columns.

I suspect this will be tricky to solve as there can be nested rows within rows and it's not clear that the top-level equal_height property should always take precedence.

For context, the use case here is wanting to control the relative width of components (only possible via gr.Column(scale=...) as far as I know), as well as making sure they have equal heights.

CC @ola13

Is there an existing issue for this?

Reproduction

import gradio as gr

with gr.Blocks() as demo:
    with gr.Row().style(equal_height=True):
        with gr.Column(scale=4):
            gr.Dropdown(choices=['a', 'b', 'c'], interactive=True)
        with gr.Column(scale=8):
            gr.Slider(interactive=True)

demo.launch()

Screenshot

image

Logs

-

System Info

Gradio 3.18.0

Severity

annoying

stevewalker-de commented 1 year ago

+1 Any update on this?

hunterssl commented 1 year ago

+1 I'm new to Gradio, is there any solution?

abidlabs commented 1 year ago

Not at the moment @hunterssl @stevewalker-de. Please feel free to share your code snippets and we might be able to suggest a workaround.

atesgoral commented 1 year ago

I worked around the vertical alignment issues by giving certain elements elem_ids and applying custom CSS.

For example:

custom_css = """
    #image-upload {
        flex-grow: 1;
    }
    #params .tabs {
        display: flex;
        flex-direction: column;
        flex-grow: 1;
    }
    #params .tabitem[style="display: block;"] {
        flex-grow: 1;
        display: flex !important;
    }
    #params .gap {
        flex-grow: 1;
    }
    #params .form {
        flex-grow: 1 !important;
    }
    #params .form > :last-child{
        flex-grow: 1;
    }
"""

with gr.Blocks(css=custom_css) as iface:
    with gr.Row():
        with gr.Column():
            image_upload = gr.Image(
                label="Product image",
                type="pil",
                elem_id="image-upload"
            )
        with gr.Column(elem_id="params"):
            with gr.Tab('Prompts'):
                positive_prompt = gr.Textbox(
                    label="Positive Prompt: describe what you'd like to see",
                    lines=3,
                    value=DEFAULT_POSITIVE_PROMPT
                )
                negative_prompt = gr.Textbox(
                    label="Negative Prompt: describe what you want to avoid",
                    lines=3,
                    value=DEFAULT_NEGATIVE_PROMPT
                )

Can get you this:

image
shreyanmitra commented 4 months ago

@abidlabs Any update on this?

abidlabs commented 4 months ago

Hi @shreyanmitra we are currently thinking through the best way to implement this. In particular @aliabid94 will work on a solution or provide a workaround. Hard to know exactly how long it will take, but I am hoping in the next few weeks.

abidlabs commented 1 month ago

We have a PR to fix this (#9577), although I'm not sure it will always produce the more desirable UI. For what its worth, this limitation:

For context, the use case here is wanting to control the relative width of components (only possible via gr.Column(scale=...) as far as I know), as well as making sure they have equal heights.

is no longer a limitation as all components can take a scale parameter

abidlabs commented 1 month ago

Closed via #9577