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
32.03k stars 2.39k forks source link

Support more advanced filtering in FileExplorer component #8880

Open pmbarrett314 opened 1 month ago

pmbarrett314 commented 1 month ago

Is your feature request related to a problem? Please describe.
The workflow I'm trying to support is something along the lines allowing the user to select a directory while only showing certain filetypes as context to aid in selecting the correct directory. So for example I have a folder hierarchy that contains videos, images, and possibly other random files like txt files or .DS_Store. I would like only the directories to be selectable, but I would like to show the video files so the user has more context than just the directory name.

Describe the solution you'd like
I have a couple of ideas.

abidlabs commented 1 month ago

Hi @pmbarrett314, I think this would be a great case for a custom component!

we've made it possible for Gradio users to create their own custom components (using existing components, like gr.FileExplorer as a base template) -- meaning that you can write some Python and JavaScript (Svelte), and publish it as a Gradio component. You can use it in your own Gradio apps, or share it so that anyone can use it in their Gradio apps.

Here's an example of a Gradio custom component: https://github.com/PhyscalX/gradio-image-prompter -- it lets you upload images and process points or draw boxes on top of the image.

If you'd like to create your own, we've put together a Guide: https://www.gradio.app/guides/five-minute-guide, and we're happy to help.

pmbarrett314 commented 1 month ago

I'd been working with custom components as well! Scope-wise, I was on the fence about whether at least some of this might make sense as an update to the built-in component. I will definitely work on it as a custom component when I get to it.

abidlabs commented 1 month ago

Thanks @pmbarrett314, looking forward for your custom component! I'll keep this issue open and cc @aliabid94 for this thoughts.

Regex support in FileExplorer. Glob is fine, but falls apart as soon as you want two types of file. Especially since components like Video supports multiple file types I think a bit more robustness is needed. Maybe just a regex field for the FileExplorer component initializer that defaults to None and overrides the glob and ignore_glob fields if it's truthy?

Maybe we could accept a list of globs, not just a single glob

Support showing some files without allowing selecting them.

Partial interactivity feels like a case for a custom component

Also in general allowing directories and files to be selected at the same time can be problematic if the value is being passed to something that expects one or the other..

Agreed, I thought we already supported this, but it seems not.