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 client handle_file function for js frontend not preserving filenames #10758

Open
1 task done
v1o6ynne opened this issue Mar 7, 2025 · 0 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@v1o6ynne
Copy link

v1o6ynne commented Mar 7, 2025

Describe the bug

In frontend js, we uploaded the image files by:

`
const processedFiles = files.map(f =>
new File([f.file], f.file.name, { type: f.file.type }) // Ensure filename is included
);

    console.log("📁 Sending files to Gradio:", processedFiles.map(file => handle_file(file)));

    const client = await Client.connect("......");

    const result = await client.predict("/predict", {
        images: processedFiles.map(file => handle_file(file)), // Ensure files are formatted correctly for Gradio

    });

`

and in backend, app.py, we try to get the original filenames but just have all filenames as blob:

`
def save_uploaded_images(images):
temp_dir = tempfile.mkdtemp(dir="/tmp/gradio") # Ensuring proper storage
saved_paths = []
seen_filenames = []

for image in images:
    # Extract the original filename from the temporary path
    original_filename = os.path.basename(image)  # Gradio stores the original name here
    raise AssertionError(f"original_filename: {original_filename}")

`

If preserving the filenames is not supported yet, does anyone know any alternative way to achieve this? Thanks a lot!

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

please refer to previous section for minimal code to reproduce

Screenshot

No response

Logs

System Info

Gradio Environment Information:
------------------------------
Operating System: Linux
gradio version: 5.15.0
gradio_client version: 1.7.0

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

aiofiles: 23.2.1
anyio: 3.7.1
audioop-lts is not installed.
fastapi: 0.115.7
ffmpy: 0.5.0
gradio-client==1.7.0 is not installed.
httpx: 1.0.0b0
huggingface-hub: 0.28.1
jinja2: 3.1.5
markupsafe: 3.0.2
numpy: 2.2.2
orjson: 3.10.15
packaging: 24.1
pandas: 2.2.3
pillow: 11.1.0
pydantic: 2.10.6
pydub: 0.25.1
python-multipart: 0.0.20
pyyaml: 6.0.2
ruff: 0.9.6
safehttpx: 0.1.6
semantic-version: 2.10.0
starlette: 0.45.3
tomlkit: 0.13.2
typer: 0.15.1
typing-extensions: 4.12.2
urllib3: 2.2.3
uvicorn: 0.34.0
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.


gradio_client dependencies in your environment:

fsspec: 2024.12.0
httpx: 1.0.0b0
huggingface-hub: 0.28.1
packaging: 24.1
typing-extensions: 4.12.2
websockets: 14.2

Severity

Blocking usage of gradio

@v1o6ynne v1o6ynne added the bug Something isn't working label Mar 7, 2025
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

1 participant