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.43k stars 2.53k forks source link

A guide on optional components, input-less components, output-less components, etc. #500

Closed AK391 closed 2 years ago

AK391 commented 2 years ago

Is your feature request related to a problem? Please describe. Discussed with @abidlabs to add optional output components for use cases such as https://huggingface.co/spaces/docs-demos/bart-large-mnli where multiple tasks are in one space (zero shot classification, summarization) based on the model/checkpoint selected

abidlabs commented 2 years ago

One way to do this would be to allow optional outputs ONLY AFTER the required outputs. Depending on how many values the function returns, the interface would or would not render the optional outputs.

omerXfaruq commented 2 years ago

@abidlabs @dawoodkhan82 what are your latest thoughts and status on this issue? I am finalizing #430 right now and this felt related.

abidlabs commented 2 years ago

Was talking to @aliabid94 when I learned that we already support this! You can just return None for any of the return values and the output component will not be rendered!

image

I'm going to leave this issue open as a reminder we should document this behavior somewhere. Maybe writing a mini guide on optional input and output components?

freddyaboulton commented 2 years ago

@abidlabs The behavior you talk about (returning None makes the component invisible) is actually not what happens now.

image

I think the better way of supporting "optional" rendering is via gr.update and that's already covered in the docs and guides. If anything we can add a code snippet to the forthcoming recipe/playground page (#1860). But I think we should close.

abidlabs commented 2 years ago

Ah that's interesting... agreed we'll document gr.update() as part of #1359, so I don't think we need it here.