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.41k stars 2.52k forks source link

clean up component folder structure + move components out of the `app` package #3360

Closed pngwn closed 1 year ago

pngwn commented 1 year ago

Get the components out of the app. This is the really disruptive part, so I want to keep it simple conceptually.

This will get closed when all of this work is done. tracking issue for the first part:

abidlabs commented 1 year ago

Nice @pngwn!

I wonder if we should make static the required one and interactive the optional one that uses static as a fallback. As far as I understand it, some components can be used as outputs but not inputs (e.g. JSON or Markdown or Label) -- so they would support a static mode but not an interactive one?

pngwn commented 1 year ago

Ah that's a good point, yeah maybe that makes more sense!

pngwn commented 1 year ago

Well they can be used as inputs but they don't do anything (just emit a change event when the content changes), so this definitely makes sense. Will update.

abidlabs commented 1 year ago

Oh and this might be a minor point, but this is probably best time to bring it up -- can we rename the component modes "input", "output", and "example" instead of "interactive", "static", and "preview"? Naming doesn't matter if we're using these internally but since we're planning on letting users contribute custom components, this naming would be more intuitive (since they're already familiar with inputs/outputs) and be one less thing to remember

pngwn commented 1 year ago

Well, the only reason that might not make sense if you can use interactive as output and static as input if you want to. Since blocks, those distinctions aren't as clear any more.

I wonder would a new user have those distinctions or is this an interface-centric interpretation? SO users who are familiar with gradio pre-3.0 might think that way but does it still translate.

The real distinction between interactive/ static is interactive can accept user-input + responds to that input whereas static does not, but that doesn't dictate their relationship to input/output in gradio itself.

abidlabs commented 1 year ago

Well, the only reason that might not make sense if you can use interactive as output and static as input if you want to. Since blocks, those distinctions aren't as clear any more.

Good point, okay let's leave it as is then!

freddyaboulton commented 1 year ago

Chatted with @pngwn this morning about this refactor. Here is what we discussed.

The work will be split between two PRs.

The first PR will solely reorganize the component directories to match the structure mentioned in the original comment. The current code component follows this structure (except for /static/ /example/). There will have to be an Index.svelte file for each component that delegates between static and dynamic modes based on props. This should mostly unblock @abidlabs and @hannahblair to make improvements to the components.

The second PR will refactor Blocks.svelte so that components can be loaded dynamically based on props, e.g. the static, dyamic, or preview versions of each component. This will be the same infrastructure used for dynamically loading custom components. @pngwn Will take this opportunity to write some unit tests for Blocks.svelte. It might also be possible to do this work piecemeal (at least in batches).

We may need a separate metadata folder or something like that for internationalization and other misc functionality

abidlabs commented 1 year ago

Thanks @freddyaboulton @pngwn, sounds like a plan!