cog icon indicating copy to clipboard operation
cog copied to clipboard

Failed to decode dataurl: invalid media type

Open Medoalmasry opened this issue 1 year ago • 8 comments

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 [email protected] gives me the following error ⅹ Failed to decode dataurl: invalid media type

Medoalmasry avatar Aug 20 '23 14:08 Medoalmasry

Same problem. Does anyone know how to handle this?

jby1993 avatar Sep 14 '23 09:09 jby1993

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.

peter65374 avatar Oct 17 '23 03:10 peter65374

Anyone?

tbergeron avatar Dec 28 '23 12:12 tbergeron

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

xavriley avatar Jan 30 '24 11:01 xavriley

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 avatar Feb 13 '24 13:02 jd7h

Minimal code for reproducing the error:

  • mesh.glb from this zip: mesh.zip
  • cog.yaml from cog init.
  • predict.py:
# 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")

jd7h avatar Feb 13 '24 13:02 jd7h

Quick workaround: add this to your predict.py:

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

See also: #1353

yorickvP avatar Feb 13 '24 14:02 yorickvP

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

philz1337x avatar May 16 '24 07:05 philz1337x