replicate / cog

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

cog predict does not download a file when I return its Path specifying its extension #207

Open ericguizzo opened 3 years ago

ericguizzo commented 3 years ago

cog predict does not download a file if I explicitly write the extension in the name of the output Path (I am under Mac OS).

Example:

    Inside predict function:
    output_path = Path(tempfile.mkdtemp()) / "output.txt"
    with open(str(output_path), "w") as f:
        f.write("hello")
    return output_path 

This only prints the file's content on the terminal and does not download it. But if I remove the ".txt" from the filename the download works, but the file is a .bin and it does not contain the text.

bfirsh commented 3 years ago

Ah thank you -- yes Cog does some fuzzy matching to try and figure out what file types. We've been thinking about how to have a more robust type system: #205

In this case, one way to get this as a file would be to use the -o option, or to pipe to a file. For example:

cog predict -i ... -o output.txt
cog predict -i ... > output.txt
zeke commented 2 years ago

@allcontributors please add @ericguizzo for bugs 🪲

allcontributors[bot] commented 2 years ago

@zeke

I've put up a pull request to add @ericguizzo! :tada: