gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
32.12k stars 2.4k forks source link

"Use via API" with Bash returns an incorrect file download path #9049

Open lilacs2039 opened 1 month ago

lilacs2039 commented 1 month ago

Describe the bug

When the gradio application that returns images is used via API with the curl command, the wrong image file download path is returned.

Have you searched existing issues? 🔎

Reproduction

Run the following gradio application on a local server and execute the curl command. The incorrect file download path is returned. Accessing the download path returned by the browser yields "{"detail": "Not Found"}". The correct download path is "the path excluding the path string before /file".

App

app.py

import gradio as gr
from transformers import pipeline

pipe = pipeline(
    task="depth-estimation",
    model="depth-anything/Depth-Anything-V2-Small-hf",
)

def estimate_depth(image):
    return pipe(image)["depth"]

demo = gr.Interface(
    fn=estimate_depth,
    inputs=gr.Image(type="pil", label="Input Image"),
    outputs=gr.Image(type="pil", label="Estimated Depth"),
    examples=[
        [
            "https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png"
        ]
    ],
    title="Depth Estimation",
)
if __name__ == "__main__":
    demo.launch(
        server_name="127.0.0.1",
        server_port=7870,
    )

Start Server

python app.py

Use via API

curl -X POST http://127.0.0.1:7870/call/predict -s -H "Content-Type: application/json" -d '{
  "data": [
    {"path":"https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png"}
]}' \
 | jq -r '.event_id' \
 | { read EVENT_ID; curl -s -N http://127.0.0.1:7870/call/estimate_depth/$EVENT_ID ;} \
 | sed -n 's/^data: //p' | jq -r '.[0].url'

Screenshot

No response

Logs

$ curl -X POST http://127.0.0.1:7870/call/predict -s -H "Content-Type: application/json" -d '{
  "data": [
    {"path":"https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png"}
]}' \
 | jq -r '.event_id' \
 | { read EVENT_ID; curl -s -N http://127.0.0.1:7870/call/estimate_depth/$EVENT_ID ;} \
 | sed -n 's/^data: //p' | jq -r '.[0].url'
http://127.0.0.1:7870/c/file=/tmp/gradio/10bbf611edef1afd4ab1b9ec96ee11a48e4a0755/image.webp

※Correct path is "http://127.0.0.1:7870/file=/tmp/gradio/10bbf611edef1afd4ab1b9ec96ee11a48e4a0755/image.webp"

System Info

Windows 11 Pro WSL2 Ubuntu22.04

$ gradio environment
Gradio Environment Information:
------------------------------
Operating System: Linux
gradio version: 4.40.0
gradio_client version: 1.2.0

$ python -V
Python 3.11.7

Severity

Blocking usage of gradio

abidlabs commented 1 month ago

Interesting, so just to confirm, there's an extra "/c" in the returned path?

lilacs2039 commented 1 month ago

there's an extra "/c" in the returned path?

It depends on the case. In this case there was a "/c", but in other cases it could have been "/call/est". (i.e., http://127.0.0.1:7869/call/est/file=/tmp/gradio/10.... .55/image.webp)

rrg92 commented 3 weeks ago

Found problem here too.

This space show a example using curl or PowerShell https://huggingface.co/spaces/rrg92/GradioApiBug