gradio: šŸ™‹ Community Feedback on Blocks

This issue is a place for the community to try Blocks šŸ§± and give feedback on its development

What is Blocks?

Blocks allows you to build web-based demos in a flexible way using the gradio library. Blocks is a more low-level and flexible alternative to the core Interface class. Specifically, Blocks support:

  • grouping together related demos using Tabs
  • flexible positioning of components using Columns, Rows, etc. and the ability to add explanatory Markdown or Text at any point
  • flexible data flows (e.g. any number of input and output components can be displayed on screen, and functions can define data flow between any subset of inputs and outputs)
  • flexible event triggers (e.g. button clicks, element changes, etc.)

Hereā€™s an example Block:

Recording 2022-02-22 at 11 54 03

If youā€™ve used Gradio before, youā€™ll find that Blocks still allows you to build web apps:

  • entirely in Python
  • using the standard Python interpreter, which means it will run in Jupyter notebooks, colab notebooks, or any Python IDE

Getting Started with Blocks

  • Blocks is just released with Gradio 3.0. Check here for the announcement.
  • To use it, please install the latest release of Gradio: pip install gradio
  • TODO: Add [Blocks Introduction Guide Link]

You can also use Blocks in Spaces! See an example here.


Giving feedback: In the comments below, weā€™d love to hear from you:

  • Did Blocks allow you to build something cool? Share a screenshot or a link to a Blocks Demo!
  • Does Blocks not support your use case? Let us know too so that we can support it!
  • Did you find anything confusing or hard within the syntax or usage of Blocks? Letā€™s improve it together!

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 28
  • Comments: 36 (10 by maintainers)

Most upvoted comments

I have tried out blocks now and have a few pieces of feedback. I found it easy to use and was able to make my desired layout quickly with one button outputting to multiple tabs with different views. Building an interface with rows/columns is intuitive to me, very HTML-like. I prefer the control compared to the previous ā€˜magicā€™ of the standard interface. I think this new UI type will be useful for multi-step processes and for making more app-like complex demos. Having this as a more advanced option is perfect, with the standard Gradio UI as default.

Areas to improve:

  • It seems that the default dark theme is not supported (text stays black)
  • With added layout customization, supporting custom CSS is very much desired šŸ™
  • Input elements should not change in size relative to the output (add flex-shrink: 0)
  • Output elements should have a min and max width to keep styles clean

Have there been any discussions about an interface list as opposed to the context manager/blocks solution?

I think this sort of thing reads a bit better. It would sacrifice ā€œsharedā€ components from the blocks, but it would make it easier to define inputs/outputs via the shortcuts as opposed to having to define each input class instance explicitly.

interface_a = gr.Interface(
    fn_a,
    inputs='sketchpad',
    outputs='label',
    title='Pictionary App'
)

interface_b = gr.Interface(
    fn_b,
    inputs='text',
    outputs='image',
    title="Text to Image App"
)

# InterfaceList does not exist, just an idea
gr.InterfaceList([interface_a, interface_b]).launch()

I found having to do 2 nested withs to be not so intuitive. This is just one opinion from one person though!

The blocks syntax reminds me of the column/row management experience in streamlit, which I find for the most part to be confusing, and I see most folks (non-power users) just not using it - and if they do, the code is hard to read imho.

At the end of the day, if the point/driving force behind this feature is to allow folks to have more than one interface in one hosted gradio app, I think we should make it as easy as possible to do just that.

Would really love some other community members to weigh in on this, so we can see what they think. šŸ˜„

Hi @abidlabs and team: 2 quick questions on using Parallel and Series with Blocks. Iā€™ve deployed a new demo on Spaces so itā€™ll be easier to see what I mean: https://huggingface.co/spaces/chinhon/headlines_blocks_parallel_series

For Parallel:

  • is there a way to ā€œstackā€ the outputs on top of each other in 2 different windows, like gr.Interface?
  • Iā€™ve tried to work around it, but current version of Block seems to display the Parallel outputs in columns or as a list. See attached screen grabs. blocks_parallel blocks_parallel2

For Parallel and Series:

  • would performance slow significantly by combining Parallel and Series under the hood of one app via Block? Iā€™ve not tested the run times exhaustively, and the app seems to run ok so far on Spaces.

Overall, Iā€™d say Blocks still works for me mostly as an organisatonal tool to put similar apps together. Iā€™ve tried out a few version using blocks to combine different inputs and processing functions, but found myself bogged down with unnecessary complexities after a while - which detracts from the main draw of Gradio, in my view.

But thatā€™s just me/my use case. Others might have better use cases for the other features.

Iā€™m not sure if I am understanding blocks the right way, but what I feel users want is a way to dinamically load the different inputs from others. For example if you want to have 2 functionalities in the interface you can just put a gr.input.Radio and then depending and what you have clickedā€¦ load other gr.input components.

In my case I would also love to see some way to reload individual components like in this case (see the image) . Iā€™ve selected the class Staff and when I submit, I would love to be able to reload the component without the option Staff. Beware I am using Gradio as an input for different configurations to execute a model.

If you have any doubt about my use case you can reply me. Thank you for reading!

ModelInterface

PS: I would like also to be able to locate examples above the options and change the text ā€œExamplesā€ to -> ā€œDefault settingsā€ or any other text.

Every theme will have a light and dark mode. This will be toggleable by the user but, by default, respect system preferences.

So in this case you would just select (theme=peach) and both light and dark variants of that theme will be available to users of the app.

Thanks for the feedback @Lastly and @prakharrathi25! I have created an issue around the step-gating / visibility issue that you guys have mentioned: #784

Great question @brenden-connors! We are still working on themes with Blocks. We are planning on launching with a default and a dark theme next week, but then adding more themes over time. Right now, you wonā€™t find themes working correctly, but eventually something like gr.Blocks(theme="dark-peach") should work! cc @pngwn @gary149

@nateraw thanks for the feedback! letā€™s continue the conversation on https://github.com/gradio-app/gradio/issues/640

Built a block that can convert text to either audio or an image, depending on userā€™s choice.

Demo Screen Shot 2022-02-24 at 5 13 54 PM

Code

import gradio as gr

fastspeech = gr.Interface.load("huggingface/facebook/fastspeech2-en-ljspeech")
clip = gr.Interface.load("spaces/DrishtiSharma/Text-to-Image-search-using-CLIP")


def text2speech(text):
    return fastspeech(text)


def text2image(text):
    image = clip(text)[0]
    return gr.processing_utils.decode_base64_to_image(image)


block = gr.Blocks()

with block:
    text = gr.inputs.Textbox(placeholder="Try writing something..")

    with gr.Column():
        with gr.Row():
            get_audio = gr.Button("generate audio")
            get_image = gr.Button("generate image")
        with gr.Row():
            speech = gr.outputs.Audio()
            image = gr.outputs.Image()


    get_audio.click(text2speech, inputs=text, outputs=speech)
    get_image.click(text2image, inputs=text, outputs=image)

block.launch()

Feedback A few issues I faced with this and other demos: