Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gr.FileExplorer does not update view when root_dir does not change. #7788

Open
1 task done
christian-kento-rasmussen opened this issue Mar 22, 2024 · 5 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@christian-kento-rasmussen
Copy link

christian-kento-rasmussen commented Mar 22, 2024

Describe the bug

When auto updating a gr.FileExplorer component using gr.Blocks().load(every=1) the file tree does not update when a file is created. The file tree does only update when the root_dir variable changes.

As an example:

If I have gr.FileExplorer open in a folder it will show all files, however when i manually create a new file this file it not shown.
The file will only be shown if I change the root_dir to a new path and then back again to the old path.
This is shown in the code example below. (remember to create a new file in the first 10 seconds)

Expected behaviour:

The file tree will update each second to include any new files.

References

this was supposedly fixed in #6096 however it does not work.

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

import os
import time

import gradio as gr

start_time = time.time()

def set_work_dir():
    # Check if the time elapsed is between 10 and 12 seconds
    if time.time() - start_time > 10 and time.time() - start_time < 12:
        print("Changing work dir to subfolder for 2 seconds and then back again, file should then be shown.")
        # Return the subfolder path to update the root_dir of FileExplorer
        return os.getcwd() + "/qim3d"
    else:
        # Return the current working directory
        return os.getcwd() 

with gr.Blocks() as demo:
    # Create a FileExplorer widget with the root_dir set dynamically using set_work_dir function
    f = gr.FileExplorer(root_dir=set_work_dir())
    # Load the FileExplorer widget into the demo
    demo.load(lambda: gr.FileExplorer(root_dir=set_work_dir()), None, f, every=1)
    
demo.launch()

Screenshot

No response

Logs

No response

System Info

Gradio Environment Information:
------------------------------
Operating System: Darwin
gradio version: 4.19.1
gradio_client version: 0.10.0

------------------------------------------------
gradio dependencies in your environment:

aiofiles: 23.2.1
altair: 5.2.0
fastapi: 0.109.2
ffmpy: 0.3.0
gradio-client==0.10.0 is not installed.
httpx: 0.26.0
huggingface-hub: 0.20.2
importlib-resources: 6.1.1
jinja2: 3.1.2
markupsafe: 2.1.5
matplotlib: 3.8.2
numpy: 1.26.4
orjson: 3.9.10
packaging: 23.2
pandas: 2.2.0
pillow: 10.2.0
pydantic: 2.6.1
pydub: 0.25.1
python-multipart: 0.0.9
pyyaml: 6.0.1
ruff: 0.2.1
semantic-version: 2.10.0
tomlkit==0.12.0 is not installed.
typer: 0.9.0
typing-extensions: 4.9.0
uvicorn: 0.27.0.post1
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.


gradio_client dependencies in your environment:

fsspec: 2023.12.2
httpx: 0.26.0
huggingface-hub: 0.20.2
packaging: 23.2
typing-extensions: 4.9.0
websockets: 11.0.3

Severity

I can work around it

@lsl1323184983
Copy link

I also encountered the same problem. Is there any solution now?

@Lethja
Copy link

Lethja commented Mar 26, 2024

I to have this problem on a more recent version (4.21.0)

@Billijk
Copy link

Billijk commented Apr 7, 2024

+1 here. my work around is to temporarily change the root dir and back:

def update_file_explorer():
    return gr.FileExplorer(root_dir=file_root_tmp)
def update_file_explorer_2():
    return gr.FileExplorer(root_dir=file_root)

refresh_btn.click(update_file_explorer, outputs=file_explorer).then(update_file_explorer_2, outputs=file_explorer)

@tumbleintoyourheart
Copy link

+1 here. my work around is to temporarily change the root dir and back:

def update_file_explorer():
    return gr.FileExplorer(root_dir=file_root_tmp)
def update_file_explorer_2():
    return gr.FileExplorer(root_dir=file_root)

refresh_btn.click(update_file_explorer, outputs=file_explorer).then(update_file_explorer_2, outputs=file_explorer)

Can we periodically trigger this refresh_btn.click every x=1 seconds?
I've tried to add every=1 to each/ both the click and then call but it didn't work.

@suay1113
Copy link

I have encountered a similar problem. Adding a refresh button but not actually updating gr.FileExplorer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants