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

How to access output temp file? #2136

Open
yigithanyucedag opened this issue Feb 7, 2025 · 1 comment
Open

How to access output temp file? #2136

yigithanyucedag opened this issue Feb 7, 2025 · 1 comment

Comments

@yigithanyucedag
Copy link

Hello, I’m making a POST request to the "predictions" endpoint with the Prefer: respond-async header and the webhook URL in the body. The webhook is working, and I’m receiving all events without any issues. However, I’m unable to figure out how to access the output path URL from the "succeeded" event via an HTTP server. When I try to access that URL, I get a 404 error with the message {"detail":"Not Found"}.

Here is the webhook "succeeded" request output:

{
  "input": {
    "gender": "boy",
    "type": "baby",
    "mom_image": "https://img.freepik.com/free-photo/young-beautiful-woman-pink-warm-sweater-natural-look-smiling-portrait-isolated-long-hair_285396-896.jpg",
    "dad_image": "https://img.freepik.com/free-photo/young-bearded-man-with-striped-shirt_273609-5677.jpg"
  },
  "output": "/tmp/tmpe6a8ilg8/output.webp",
  "id": null,
  "created_at": null,
  "started_at": "2025-02-07T12:23:05.831729+00:00",
  "completed_at": "2025-02-07T12:23:28.310495+00:00",
  "logs": "...",
  "status": "succeeded",
  "metrics": {
    "predict_time": 22.478766
  }
}

Here’s the related code block in predict.py:

final_output_path = Path(tempfile.mkdtemp()) / "output.webp"
cwebp(input_image=raw_output_path, output_image=final_output_path, option="-q 90", logging="-v")

return Path(final_output_path)

Could someone help me understand how to access the output URL via an HTTP server?

@aron
Copy link
Contributor

aron commented Feb 19, 2025

Hi @yigithanyucedag thanks for reporting this issue. This looks like a bug in the cog webhook implementation which is returning you a path to the file on disk rather than a URL.

Can you share a little more about how you are running the cog server?

There are currently two ways for cog to handle files.

  1. Cog defaults to returning base64 encoded data URLs for file outputs. This works in sync mode but as you've seen there's a bug in async-mode.
  2. Cog supports an --upload-url flag which when provided to the web server on start will make a PUT request to that endpoint with the file content. It then expects that the server return a 2xx response with a Location header containing the destination of the file. This will then be included in the prediction body.

Hopefully the latter approach will unblock you for the moment while we look into the bug. Generally we've found that data URLs are good for experimenting but get unwieldy pretty quickly.

The --upload-url would look something like:

docker run -d -p 5000:5000 cog-hello-image python -m cog.server.http --upload-url=http://my-endpoint/uploads

The request made by cog will look like:

PUT /uploads/{filename}
Content-Type: {mime}

{data}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants