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

panic: dataurl: invalid mediatype #2032

Open
jd7h opened this issue Oct 29, 2024 · 4 comments · May be fixed by #2041 or #2044
Open

panic: dataurl: invalid mediatype #2032

jd7h opened this issue Oct 29, 2024 · 4 comments · May be fixed by #2041 or #2044
Assignees

Comments

@jd7h
Copy link
Contributor

jd7h commented Oct 29, 2024

I'm trying to run a replicate image locally with cog 0.11.6:

$ cog predict r8.im/thomasmol/whisper-diarization@sha256:cbd15da9f839c5f932742f86ce7def3a03c22e2b4171d42823e83e314547003f \
   -i file=@mnot_short.mp3 \
   -i 'prompt="podcast"' \
   -i 'language="nl"' \
   -i 'translate=true' \
   -i 'num_speakers=1' \
   -i 'group_segments=true' \
   -i 'offset_seconds=0' \
   -i 'transcript_output_format="both"'

which runs into an error "panic: dataurl: invalid mediatype":

Starting Docker image r8.im/thomasmol/whisper-diarization@sha256:cbd15da9f839c5f932742f86ce7def3a03c22e2b4171d42823e83e314547003f and running setup()...
Running prediction...
panic: dataurl: invalid mediatype

goroutine 1 [running]:
github.com/vincent-petithory/dataurl.New({0xc00073a000, 0x7568a, 0x7568b}, {0x0?, 0xc0003df560?}, {0x0, 0x0, 0x110?})
	/home/runner/go/pkg/mod/github.com/vincent-petithory/[email protected]/dataurl.go:81 +0x28b
github.com/replicate/cog/pkg/predict.fileToDataURL({0x7ffd348dc470, 0xe})
	/home/runner/work/cog/cog/pkg/predict/input.go:106 +0x179
github.com/replicate/cog/pkg/predict.(*Inputs).toMap(0xc00030d7c0)
	/home/runner/work/cog/cog/pkg/predict/input.go:66 +0x106
github.com/replicate/cog/pkg/predict.(*Predictor).Predict(0xc00030d900, 0xc0003c4e70)
	/home/runner/work/cog/cog/pkg/predict/predictor.go:140 +0x5e
github.com/replicate/cog/pkg/cli.predictIndividualInputs({{{0x0, 0x0, 0x0}, {0xc000386540, 0x1, 0x1}, {0xa99fb1, 0x3}, {0x7ffd348dc3fb, 0x6b}, ...}, ...}, ...)
	/home/runner/work/cog/cog/pkg/cli/predict.go:210 +0x2da
github.com/replicate/cog/pkg/cli.cmdPredict(0xc000052d00?, {0xc00018bb00?, 0x4?, 0xa9a229?})
	/home/runner/work/cog/cog/pkg/cli/predict.go:173 +0xb2b
github.com/spf13/cobra.(*Command).execute(0xc0001ed508, {0xc00018b9e0, 0x11, 0x11})
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:985 +0xaaa
github.com/spf13/cobra.(*Command).ExecuteC(0xc0001ec608)
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1117 +0x3ff
github.com/spf13/cobra.(*Command).Execute(0xc00020bf40?)
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1041 +0x13
main.main()
	/home/runner/work/cog/cog/cmd/cog/cog.go:14 +0x66

I get the same results with .wav and .mkv files, and I've also tried other mp3 files to make sure it was not a bad audio file or ffmpeg conversion mistake. I've attached a zipped mp3 file for reproducing the issue.

To reproduce:

wget https://github.com/user-attachments/files/17557114/audio_file_for_testing.zip
unzip audio_file_for_testing.zip
cog predict r8.im/thomasmol/whisper-diarization@sha256:cbd15da9f839c5f932742f86ce7def3a03c22e2b4171d42823e83e314547003f \
   -i file=@mnot_short.mp3 \
   -i 'prompt="podcast"' \
   -i 'language="nl"' \
   -i 'translate=true' \
   -i 'num_speakers=1' \
   -i 'group_segments=true' \
   -i 'offset_seconds=0' \
   -i 'transcript_output_format="both"'

I'm also pretty sure the error is due to cog and not the underlying Python code. If I pull the image, do cog run bash and run the Python code manually from inside the docker container, everything works fine.

Also note this is different from #1264.

@jd7h
Copy link
Contributor Author

jd7h commented Oct 29, 2024

Here's a minimal predict.py I used for testing. Combine it with the cog.yaml from cog init and the mp3 file from my previous comment.

# 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("mnot_short.mp3").exists():
            raise ValueError("Example file mnot_short.mp3 does not exist")

    def predict(
        self,
        file: Path = Input(description="Provide an audio file", default=None)
    ) -> bool:
        """Run a single prediction on the model"""
        if file.exists():
            print(file)
            return True
        return False

@jd7h
Copy link
Contributor Author

jd7h commented Oct 29, 2024

I tried to figure out where this is going wrong.

Results:

  • I can build cog from git, build the minimal example cog-container (see above), and do a succesful prediction on my local machine (Arch Linux) with cog predict -i file=@mnot_short.mp3.
  • If I then copy the resulting cog binary to my remote machine (NixOS), cog predict -i file=@mnot_short.mp3 returns the error panic: dataurl: invalid mediatype.
  • If I build cog from git on my NixOS machine, cog predict -i file=@mnot_short.mp3 works fine on that same minimal example.
  • The global cog binary installed on my NixOS machine is just the binary (0.11.6 release) from Github. Here cog predict -i file=@mnot_short.mp3 also returns the error panic: dataurl: invalid mediatype.

This suggests that there's some kind of file or dependency missing from the cog binary.

@mrngm
Copy link

mrngm commented Oct 29, 2024

Cog doesn't account for the case that mime.TypeByExtension (documentation) may return an empty string, see here. The dependency github.com/vincent-petithory/dataurl expects a / in its mediaType argument for New (src), or panics otherwise.

One of the fixes is easy: account for the case that mime.TypeByExtension() returns the empty string, and return an error in fileDataToURL().

aron added a commit that referenced this issue Nov 4, 2024
This commit updates the import for the `mime` package to use the local
utility which handles the case where `mime.TypeByExtension` returns an
empty string.

Fixes #2032
@aron aron linked a pull request Nov 4, 2024 that will close this issue
@aron
Copy link
Contributor

aron commented Nov 4, 2024

Thanks for reporting this. We already had the code in the code-base to handle this case, it just wasn't being used. I've opened #2044 to fix it.

@aron aron self-assigned this Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants