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.99k stars 2.58k forks source link

Can't refresh the contents of FileExplorer component? #9785

Open Liusuthu opened 3 weeks ago

Liusuthu commented 3 weeks ago

Describe the bug

Hey dear developers, I'm not sure whether it's a bug, but it really stresses me out.

In my codes, I want to use the component FileExplorer to view my files realtime, since I will dynamically create and delete files. But I find that the displayed content in FileExploere can't change realtime after I add or delete a file. The core code can be describe simply below:

show_files=gr.FileExplorer(root_dir="./chat_data",file_count="single",interactive=True)

def flush(show_files):
    return gr.FileExplorer(root_dir="./chat_data",file_count="single",interactive=True)

flush_btn.click(flush,inputs=None,outputs=[show_files])

After a simple experiment, I think it's because the original root_dir is the same after flush, so the content won't change, if I make root_dir a different path, it will reflect the new changes. But it's really annoying.

So is there any solution if I still want to use this component for realtime viewing my files? Thank you!

I have tried the existing methods in #6096 by abidlabs, and also tried #9350 and #7788 but nothing works.

Have you searched existing issues? šŸ”Ž

Reproduction

import gradio as gr

show_files=gr.FileExplorer(root_dir="./chat_data",file_count="single",interactive=True)

def flush(show_files):
    return gr.FileExplorer(root_dir="./chat_data",file_count="single",interactive=True)

flush_btn.click(flush,inputs=None,outputs=[show_files])

Screenshot

None

Logs

None

System Info

gradio==4.44.1

Severity

I can work around it

abidlabs commented 3 weeks ago

We'll take a look. Related: https://github.com/gradio-app/gradio/issues/9350

abidlabs commented 3 weeks ago

Have you tried setting something like every=1 so like gr.FileExplorer(root_dir="./chat_data",file_count="single",interactive=True, every=1), which I think should refresh the contents every second?

Liusuthu commented 3 weeks ago

Thanks for your reply! I did try it, but nothing worked.

You can reproduce this error as follows:

import gradio as gr

with gr.Blocks() as demo:
    show_files=gr.FileExplorer(root_dir="./chat_data",file_count="single",interactive=True, every=1)

demo.launch()

I just manually add/delete files in ./chat_date folder, and the content can't be refreshed per second.

By the way, my gradio version is 4.44.1, but I also tried 5.3.0 and the problem exists.