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

Can not use gradio.File inside Docker container #8633

Closed
1 task done
PashaWNN opened this issue Jun 26, 2024 · 3 comments
Closed
1 task done

Can not use gradio.File inside Docker container #8633

PashaWNN opened this issue Jun 26, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@PashaWNN
Copy link

PashaWNN commented Jun 26, 2024

Describe the bug

Can not find the uploaded file while Gradio is in Docker container.
While I run it without docker (just python3 gradio.py), it is working OK.

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

  1. Create app.py and Dockerfile with the following code:
import tempfile
import gradio

temporary_directory = tempfile.TemporaryDirectory()


def run_app(test_filename):
    out_file = tempfile.NamedTemporaryFile(dir=temporary_directory.name, mode='w')
    with open(test_filename, 'r') as test_file:
        out_file.write(test_file.read())
        out_file.flush()
    return out_file.name


iface = gradio.Interface(
    fn=run_app,
    inputs=[
        gradio.File(label='Test file', file_types=['.txt'], type='filepath'),
    ],
    outputs=[gradio.File()],
    allow_flagging='never',
).launch()
FROM python:3.10-slim

RUN apt-get update

RUN apt-get -y full-upgrade

RUN apt-get install -y --no-install-recommends \
	libcairo2 libdouble-conversion3 libxml2 lib3mf1 libzip4 libharfbuzz0b \
	libboost-thread1.74.0 libboost-program-options1.74.0 libboost-filesystem1.74.0 \
	libboost-regex1.74.0 libmpfr6 libqscintilla2-qt5-15 \
	libqt5multimedia5 libqt5concurrent5 libtbb12 libglu1-mesa \
	libglew2.2 xvfb xauth

RUN apt-get clean


WORKDIR /usr/src/app
RUN mkdir /tmp/gradio
RUN pip install --no-cache-dir gradio
COPY . .
RUN pip install -r requirements.txt
EXPOSE 7860
ENV GRADIO_SERVER_NAME="0.0.0.0"
ENV GRADIO_TEMP_DIR="/tmp/gradio"

CMD ["python", "app.py"]
  1. Run it (docker build -t gradio-app . && docker run -p 7860:7860 gradio-app) and try to upload the file

Screenshot

No response

Logs

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/gradio/queueing.py", line 532, in process_events
    response = await route_utils.call_process_api(
  File "/usr/local/lib/python3.10/site-packages/gradio/route_utils.py", line 276, in call_process_api
    output = await app.get_blocks().process_api(
  File "/usr/local/lib/python3.10/site-packages/gradio/blocks.py", line 1938, in process_api
    data = await self.postprocess_data(block_fn, result["prediction"], state)
  File "/usr/local/lib/python3.10/site-packages/gradio/blocks.py", line 1761, in postprocess_data
    prediction_value = block.postprocess(prediction_value)
  File "/usr/local/lib/python3.10/site-packages/gradio/components/file.py", line 193, in postprocess
    size=Path(value).stat().st_size,
  File "/usr/local/lib/python3.10/pathlib.py", line 1097, in stat
    return self._accessor.stat(self, follow_symlinks=follow_symlinks)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmp52s9_i2i/tmpq0guqj89'


### System Info

```shell
MacOS 14.5, MacBook Pro M1 2020.

Env inside Docker container:

Gradio Environment Information:
------------------------------
Operating System: Linux
gradio version: 4.36.1
gradio_client version: 1.0.1

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

aiofiles: 23.2.1
altair: 5.3.0
fastapi: 0.111.0
ffmpy: 0.3.2
gradio-client==1.0.1 is not installed.
httpx: 0.27.0
huggingface-hub: 0.23.4
importlib-resources: 6.4.0
jinja2: 3.1.4
markupsafe: 2.1.5
matplotlib: 3.9.0
numpy: 2.0.0
orjson: 3.10.5
packaging: 23.2
pandas: 2.2.2
pillow: 10.3.0
pydantic: 2.7.4
pydub: 0.25.1
python-multipart: 0.0.9
pyyaml: 6.0.1
ruff: 0.4.10
semantic-version: 2.10.0
tomlkit==0.12.0 is not installed.
typer: 0.12.3
typing-extensions: 4.12.2
urllib3: 2.2.2
uvicorn: 0.30.1
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.


gradio_client dependencies in your environment:

fsspec: 2024.6.0
httpx: 0.27.0
huggingface-hub: 0.23.4
packaging: 23.2
typing-extensions: 4.12.2
websockets: 11.0.3



### Severity

Blocking usage of gradio
@PashaWNN PashaWNN added the bug Something isn't working label Jun 26, 2024
@PashaWNN
Copy link
Author

What I've found out so far:

  1. The error is not platform-specific: same happens with Gradio deployment on HuggingFaces
  2. The error is not version specific: there are examples on the Internet, where gr.File is used with the same Gradio version
  3. If you change the GRADIO_TEMP_DIR to somewhat outside /tmp directory — everything is working OK

@freddyaboulton
Copy link
Collaborator

Hi @PashaWNN . You need to set delete=False in the NamedTemporaryFile otherwise it will be deleted as soon as it's closed.

@PashaWNN
Copy link
Author

Hi, just checked that and you're right, my bad.

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

2 participants