cog
cog copied to clipboard
Failed to decode dataurl: invalid media type
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
Same problem. Does anyone know how to handle this?
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.
Anyone?
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
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)
Minimal code for reproducing the error:
-
mesh.glb
from this zip: mesh.zip -
cog.yaml
fromcog 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")
Quick workaround: add this to your predict.py:
import mimetypes
mimetypes.add_type("application/octet-stream", ".glb")
See also: #1353
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