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

Gradio 5 error - Gradio 4 works - to the gradio cache dir because it was not created by the application #9809

Closed
FurkanGozukara opened this issue Oct 22, 2024 · 8 comments
Labels
bug Something isn't working pending clarification

Comments

@FurkanGozukara
Copy link

FurkanGozukara commented Oct 22, 2024

Describe the bug

The error happens here

image

    def select_image(evt: gr.SelectData, images, folder_path):
        try:
            selected_image = os.path.join(folder_path, images[evt.index][1])  # Get the full image path
            logging.info(f"Selected image: {selected_image}")
            caption = read_caption(selected_image, folder_path)
            return selected_image, caption, gr.update(visible=True)
        except Exception as e:
            logging.error(f"Error in select_image: {str(e)}")
            logging.error(traceback.format_exc())
            return None, "", gr.update(visible=False)

INFO: Could not find files for the given pattern(s).
* Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
Traceback (most recent call last):
  File "G:\Image_Caption_Editor_v8\venv\lib\site-packages\gradio\queueing.py", line 624, in process_events
    response = await route_utils.call_process_api(
  File "G:\Image_Caption_Editor_v8\venv\lib\site-packages\gradio\route_utils.py", line 323, in call_process_api
    output = await app.get_blocks().process_api(
  File "G:\Image_Caption_Editor_v8\venv\lib\site-packages\gradio\blocks.py", line 2028, in process_api
    data = await self.postprocess_data(block_fn, result["prediction"], state)
  File "G:\Image_Caption_Editor_v8\venv\lib\site-packages\gradio\blocks.py", line 1836, in postprocess_data
    outputs_cached = await processing_utils.async_move_files_to_cache(
  File "G:\Image_Caption_Editor_v8\venv\lib\site-packages\gradio\processing_utils.py", line 712, in async_move_files_to_cache
    return await client_utils.async_traverse(
  File "G:\Image_Caption_Editor_v8\venv\lib\site-packages\gradio_client\utils.py", line 1017, in async_traverse
    return await func(json_obj)
  File "G:\Image_Caption_Editor_v8\venv\lib\site-packages\gradio\processing_utils.py", line 683, in _move_to_cache
    _check_allowed(payload.path, check_in_upload_folder)
  File "G:\Image_Caption_Editor_v8\venv\lib\site-packages\gradio\processing_utils.py", line 628, in _check_allowed
    raise InvalidPathError(msg)
gradio.exceptions.InvalidPathError: Cannot move R:\mass_compute\training_imgs\1_ohwx man\IMG_20230430_140344 (2).jpg to the gradio cache dir because it was not created by the application or it is not located in either the current working directory or your system's temp directory. To fix this error, please ensure your function returns files located in either the current working directory (G:\Image_Caption_Editor_v8), your system's temp directory (C:\Users\Furkan\AppData\Local\Temp) or add R:\mass_compute\training_imgs\1_ohwx man to the allowed_paths parameter of launch().

System Info

Python 3.10.11, latest Gradio

Severity

Blocking usage of gradio

@FurkanGozukara FurkanGozukara added the bug Something isn't working label Oct 22, 2024
@abidlabs
Copy link
Member

Hi @FurkanGozukara, did you try the suggestion in the error above?

gradio.exceptions.InvalidPathError: Cannot move R:\mass_compute\training_imgs\1_ohwx man\IMG_20230430_140344 (2).jpg to the gradio cache dir because it was not created by the application or it is not located in either the current working directory or your system's temp directory. To fix this error, please ensure your function returns files located in either the current working directory (G:\Image_Caption_Editor_v8), your system's temp directory (C:\Users\Furkan\AppData\Local\Temp) or add R:\mass_compute\training_imgs\1_ohwx man to the allowed_paths parameter of launch().

For security reasons, we've made Gradio less able to access arbitrary files on your computer unless you specifically add those files as part of the allowed_paths parameter.

See: #9463

image

@FurkanGozukara
Copy link
Author

FurkanGozukara commented Oct 22, 2024

@abidlabs can you tell me what to do i am confused

i dont want to change behavior of the app how to because users can pick any folder

the app works like this - Gradio 4 works

installed into : G:\Image_Caption_Editor_v8

so i need to edit user given folder and generate a txt file there, modify txt files there

image

@abidlabs
Copy link
Member

The idea is that you need to add R:\mass_compute\training_imgs\1_ohwx man or any of its parents (even R:\ if you want) to the allowed_paths parameter in launch()

@FurkanGozukara
Copy link
Author

FurkanGozukara commented Oct 22, 2024

The idea is that you need to add R:\mass_compute\training_imgs\1_ohwx man or any of its parents (even R:\ if you want) to the allowed_paths parameter in launch()

then practically this app is unusable with Gradio 5

because what this app does is, user picks a folder and easily edit generate captions - any folder

because i can't know which drive they are going to install the app on, maybe i can add all drive letters? like C D E F G R :D

@abidlabs
Copy link
Member

Ah okay so this is generally an insecure construction -- if you deploy this app anywhere, a user of the app will be able to access and run commands across any files in your filesystem.

If you are 100% sure that this Gradio app is only going to run locally, and you're willing to risk it, yeah you could just add all of the Windows drive letters or check their existence programmatically, something like:

import string
from pathlib import Path

def get_drives():
    return [f"{d}:" for d in string.ascii_uppercase if Path(f"{d}:").exists()]

and then add them to the allowed_paths list

@abidlabs
Copy link
Member

Will go ahead and close this but let us know if you have any further questions.

@abidlabs abidlabs closed this as not planned Won't fix, can't repro, duplicate, stale Oct 23, 2024
@FurkanGozukara
Copy link
Author

@abidlabs i start app like this with bat file how it is gonna work

@echo off

call .\venv\Scripts\activate.bat

set CUDA_VISIBLE_DEVICES=0
python app.py

pause

@abidlabs
Copy link
Member

You can put the code directly in python app.py before you launch it

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

No branches or pull requests

2 participants