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

error when downloading files: RuntimeError: File at path /content/undefined does not exist. #3365

Closed
1 task done
MoritzLaurer opened this issue Mar 2, 2023 · 4 comments · Fixed by #3375
Closed
1 task done
Assignees
Labels
bug Something isn't working

Comments

@MoritzLaurer
Copy link

MoritzLaurer commented Mar 2, 2023

Describe the bug

When I upload a file and click submit, the uploaded file appears with a path like "/tmp/filename". When I then try to click on "download", a new browser tab opens and an error appears: Internal Server Error.

I experience this when uploading + processing a file and then wanting to download it again from the same file component.

The weird thing is that the same code worked a month ago with an older version of gradio and I've also tried it with the latest 3.19. I have the impression that this always happens when the displayed file path is /temp/filename instead of just /filename

Is there an existing issue for this?

  • I have searched the existing issues

Reproduction

The same issue also appears with the example code for File in the docs, see here: https://gradio.app/docs/#file-header

import os
from zipfile import ZipFile

import gradio as gr


def zip_files(files):
    with ZipFile("tmp.zip", "w") as zipObj:
        for idx, file in enumerate(files):
            zipObj.write(file.name, file.name.split("/")[-1])
    return "tmp.zip"

demo = gr.Interface(
    zip_files,
    gr.File(file_count="multiple", file_types=["text", ".json", ".csv"]),
    "file",
    examples=[[[os.path.join(os.path.dirname(__file__),"files/titanic.csv"), 
    os.path.join(os.path.dirname(__file__),"files/titanic.csv"), 
    os.path.join(os.path.dirname(__file__),"files/titanic.csv")]]], 
    cache_examples=True
)

if __name__ == "__main__":
    demo.launch()

Screenshot

 screenshot

new tab that pops up with the error when clicking on download (left column) in the app from the official docs:
Screenshot 2023-03-02 at 16 01 26

Logs

Stack trace from my private/local app:

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/starlette/responses.py", line 335, in __call__
    stat_result = await anyio.to_thread.run_sync(os.stat, self.path)
  File "/usr/local/lib/python3.8/dist-packages/anyio/to_thread.py", line 31, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "/usr/local/lib/python3.8/dist-packages/anyio/_backends/_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "/usr/local/lib/python3.8/dist-packages/anyio/_backends/_asyncio.py", line 867, in run
    result = context.run(func, *args)
FileNotFoundError: [Errno 2] No such file or directory: '/content/undefined'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/uvicorn/protocols/http/h11_impl.py", line 407, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/usr/local/lib/python3.8/dist-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
  File "/usr/local/lib/python3.8/dist-packages/fastapi/applications.py", line 271, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/local/lib/python3.8/dist-packages/starlette/applications.py", line 118, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.8/dist-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/usr/local/lib/python3.8/dist-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/usr/local/lib/python3.8/dist-packages/starlette/middleware/cors.py", line 84, in __call__
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.8/dist-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/usr/local/lib/python3.8/dist-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/usr/local/lib/python3.8/dist-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/usr/local/lib/python3.8/dist-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.8/dist-packages/starlette/routing.py", line 706, in __call__
    await route.handle(scope, receive, send)
  File "/usr/local/lib/python3.8/dist-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.8/dist-packages/starlette/routing.py", line 69, in app
    await response(scope, receive, send)
  File "/usr/local/lib/python3.8/dist-packages/starlette/responses.py", line 338, in __call__
    raise RuntimeError(f"File at path {self.path} does not exist.")
RuntimeError: File at path /content/undefined does not exist.

System Info

Google colab, 
gradio 3.19

Severity

serious, but I can work around it

@MoritzLaurer MoritzLaurer added the bug Something isn't working label Mar 2, 2023
@freddyaboulton
Copy link
Collaborator

freddyaboulton commented Mar 2, 2023

Thanks for filing @MoritzLaurer !

The issue with the filename showing /tmp/ and not being able to download it is a duplicate of #3335 I believe and for me it only occurs when using the example titanic files.

When I upload files myself, I am able to both download the input files and the output zip file

zip_files_submitted

@MoritzLaurer
Copy link
Author

MoritzLaurer commented Mar 2, 2023

Thanks for the quick response @freddyaboulton. True, that looks similar, but unfortunately I also get the same error in a totally unrelated script when uploading my own .csv files. Here is the colab: [removed link]

@freddyaboulton
Copy link
Collaborator

Thanks for sharing that @MoritzLaurer !

I was able to reproduce the bug in a smaller demo. The problem is that the front-end is not handling well the case when the backend updates the contents of an existing file.

import gradio as gr
import tempfile
import pathlib

def translate(input_file):
    new_name = str(pathlib.Path(input_file.name).with_name("processed"))
    with tempfile.NamedTemporaryFile(mode="w",
            prefix=new_name,
            delete=False) as f:
        f.write(open(input_file.name).read())
    return f.name, f.name

with gr.Blocks() as demo:
    with gr.Row():
        input_file = gr.File(label="Input")
        output_file = gr.File(label="Output")
    process = gr.Button(value="Process")
    
    process.click(translate, inputs=[input_file], outputs=[input_file, output_file])


demo.launch()

You can see that the file on the left (which used to be the input) can't download but the file on the right can be downloaded properly.

I would suggest you use separate file components in your demo while we work on a fix!

@MoritzLaurer
Copy link
Author

Ok, thanks for looking into this @freddyaboulton. Good to know that a separate output file component is a working solution until there is a fix

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

Successfully merging a pull request may close this issue.

2 participants