Open russosalv opened 2 days ago
Hi @russosalv - this is expected with gradio 5. We won't serve files located outside your current working directory unless you specify them in allowed_paths
Hi @freddyaboulton thx for reply how to declare that it's allowed to go down in the directory?
Can you try something like
with gr.Blocks() as demo:
...
demo.launch(allowed_paths=["Folder1/"])
@freddyaboulton alo adding
current_path = os.path.dirname(os.path.abspath(__file__))
...
ui.launch(allowed_paths=[current_path])
still ahve same error
I can't repro this actually @russosalv . I just tried with the file_explorer
demo in the repo
import gradio as gr
from pathlib import Path
current_file_path = Path(__file__).resolve()
absolute_path = (current_file_path.parent / ".." / ".." / "gradio").resolve()
with gr.Blocks() as demo:
gr.Markdown('### `FileExplorer` to `FileExplorer` -- `file_count="multiple"`')
submit_btn = gr.Button("Select")
with gr.Row():
file = gr.FileExplorer(
glob="**/components/*.py",
# value=["themes/utils"],
root_dir=absolute_path,
ignore_glob="**/__init__.py",
)
file2 = gr.File()
submit_btn.click(lambda x: x, file, file2)
if __name__ == "__main__":
demo.launch(allowed_paths=[str(absolute_path)])
If the playgrounds
directory is in allowed_paths
then you should be able to process those files.
@freddyaboulton try to execute this code and inspect Folder 2
import gradio as gr
from pathlib import Path
current_file_path = Path(__file__).resolve()
absolute_path = (current_file_path.parent).resolve()
# create a Folder called Folder1 in the same directory as this file
new_folder = absolute_path / "Folder1"
new_folder.mkdir(exist_ok=True)
# insert a fake txt file into the new folder
fake_txt = new_folder / "fake.txt"
fake_txt.write_text("Hello World")
# create a Folder called Folder2 in the directory new_folder
new_folder2 = new_folder / "Folder2"
new_folder2.mkdir(exist_ok=True)
# insert a fake txt file into the new folder
fake_txt2 = new_folder2 / "fake2.txt"
fake_txt2.write_text("Hello World 2")
with gr.Blocks() as demo:
gr.Markdown('### `FileExplorer` to `FileExplorer` -- `file_count="multiple"`')
submit_btn = gr.Button("Select")
with gr.Row():
file = gr.FileExplorer(
glob="**/components/*.py",
# value=["themes/utils"],
root_dir=absolute_path,
ignore_glob="**/__init__.py",
)
file2 = gr.File()
submit_btn.click(lambda x: x, file, file2)
if __name__ == "__main__":
demo.launch(allowed_paths=[str(absolute_path)])
then open folder1, and Folder 2 => you will have error
Describe the bug
Using Gradio File in Windows, if you try to go down in folder (more then 1 step) receive raise InvalidPathError() gradio.exceptions.InvalidPathError
filesystem is: Folder1 -> Folder2 -> Folder3 -> File
Have you searched existing issues? 🔎
Reproduction
Screenshot
No response
Logs
No response
System Info
Severity
Blocking usage of gradio