replicate / cog

Containers for machine learning
https://cog.run
Apache License 2.0
7.45k stars 513 forks source link

Failed to decode dataurl: invalid media type #1264

Open Medoalmasry opened 10 months ago

Medoalmasry commented 10 months ago

Assuming I would like to return a file or a path for a file that isn't a valid media type. For instance

predict(self, 
                src_video: Path = Input(description="Video"),
        ) -> Path

        ### lot of processing

        mesh = trimesh.load_mesh(ply_path)
        output_path = Path(tempfile.mkdtemp()) / "output.glb"
        mesh.export(output_path, file_type="glb")

        return Path(output_path)

After building, the predict function cog predict -i src_video=@VID.mp4 gives me the following error ⅹ Failed to decode dataurl: invalid media type

jby1993 commented 9 months ago

Same problem. Does anyone know how to handle this?

peter65374 commented 8 months ago

Got same error when I managed to return numpy embedding file generated by ViT transformer. I am curious how to return a downloadable file on replicate deployment, e.g. COCO format RLE file, embedding file or pickle file.

tbergeron commented 6 months ago

Anyone?

xavriley commented 5 months ago

I was seeing the same thing when trying to encode a midi file. As a workaround, switching the output of predict.py to use an Object (as suggested here: https://github.com/replicate/cog/issues/1429#issuecomment-1854341958) fixed this for me.

Strangely it only happened when running cog locally. The same model (with List([Path, Path]) as output) seemed to work on replicate

jd7h commented 4 months ago

I have the same problem with cog version 0.9.4 (latest).

I've fixed it by zipping my output mesh with

from zipfile import ZipFile

output_zip_path = "mesh.zip"
with ZipFile(output_zip_path, 'w') as myzip:
    myzip.write('mymesh.glb')

and returning Path(output_zip_path)

jd7h commented 4 months ago

Minimal code for reproducing the error:

# Prediction interface for Cog ⚙️
# https://github.com/replicate/cog/blob/main/docs/python.md

from cog import BasePredictor, Input, Path

class Predictor(BasePredictor):
    def setup(self) -> None:
        """Load the model into memory to make running multiple predictions efficient"""
        if not Path("mesh.glb").exists():
            raise ValueError("Example file mesh.glb does not exist")

    def predict(
        self,
    ) -> Path:
        """Run a single prediction on the model"""
        return Path("mesh.glb")
yorickvP commented 4 months ago

Quick workaround: add this to your predict.py:

import mimetypes
mimetypes.add_type("application/octet-stream", ".glb")

See also: #1353

philz1337x commented 1 month ago

Quick workaround: add this to your predict.py:

import mimetypes
mimetypes.add_type("application/octet-stream", ".glb")

See also: #1353

Thanks, that fixed it for me