cog icon indicating copy to clipboard operation
cog copied to clipboard

Array as inputs and outputs using Input method

Open simonMoisselin opened this issue 2 years ago • 18 comments

Hello,

Is it possible to add the type array as an input, in addition to images or files?

simonMoisselin avatar Apr 04 '22 06:04 simonMoisselin

Hi @simonMoisselin 👋🏼

Arrays/lists as inputs and outputs are not currently supported in Cog, but this seems to me like a reasonable thing to support. Can you share a little about your intended use case?

For a list of types that are currently supported, see the docs on Input and output types.

See also this open issue about supporting multiple file outputs: https://github.com/replicate/cog/issues/411

zeke avatar Apr 11 '22 17:04 zeke

I think this is a great idea. I don't know necessarily if this would work the best (in particular it might be somewhat extraneous to using models from replicate.com), but would be awesome to support Arrow for serializing and de-serializing array data.

dashstander avatar May 02 '22 23:05 dashstander

This is still the case - we do not yet support lists/arrays of input:

TypeError: Unsupported input type typing.List[float] for parameter `nums`. Supported input types are: str, int, float, bool, cog.File, cog.Path.
ⅹ Failed to get container status: exit status 1

anotherjesse avatar Feb 23 '23 18:02 anotherjesse

This would be a great idea to support different formats. I wanted to host some derivatives of Segment Anything Model where the results are in dict format. So the results will have numpy arrays, boolean arrays, etc. It would be great if I can pass these dict files as results.

Hi @simonMoisselin 👋🏼

Arrays/lists as inputs and outputs are not currently supported in Cog, but this seems to me like a reasonable thing to support. Can you share a little about your intended use case?

For a list of types that are currently supported, see the docs on Input and output types.

See also this open issue about supporting multiple file outputs: #411

jayaffine avatar May 10 '23 05:05 jayaffine

Related / dupe of https://github.com/replicate/cog/issues/608

bfirsh avatar Jun 23 '23 14:06 bfirsh

hi, I'd like to be able to upload multiple pictures for a single argument. This would be very useful for that

alexblattner avatar Nov 06 '23 10:11 alexblattner

Hi @zeke 👋 Dust3r ( https://replicate.com/camenduru/dust3r ) needs multiple images as input.

camenduru avatar Mar 03 '24 00:03 camenduru

@zeke this is a bug not an enhancement! i am afraid to upload pictures of corgi.cam but, if you want to know, currently, with only 2 photos, this issue is killing pugs: https://replicate.com/p/llpqfprbx6oo3hmnggl4nbvqku

yosun avatar Mar 04 '24 21:03 yosun

This atrocity can be fixed if we can input more than 2 images!

Image from Gyazo

yosun avatar Mar 04 '24 22:03 yosun

Raised it with the team. We're working on it!

zeke avatar Mar 05 '24 16:03 zeke

the issue with List[str] type is confirmed. temp workaround - use simple 'str' type and split value later. looking into it.

$ cog --version cog version 0.9.4 (built 2024-01-24T22:16:49Z)

dkhokhlov avatar Mar 05 '24 16:03 dkhokhlov

use simple 'str' type and split value later.

Can you provide an example? How would that work for files?

zeke avatar Mar 05 '24 17:03 zeke

the issue with List[str] type is confirmed. temp workaround - use simple 'str' type and split value later. looking into it.

$ cog --version cog version 0.9.4 (built 2024-01-24T22:16:49Z)

okay so basically we can just concatenate as many input URLs as we want and then parse split it?

this does not seem secure. kind of like injection attack looming to happen.

yosun avatar Mar 05 '24 22:03 yosun

right, looking into it.

dkhokhlov avatar Mar 06 '24 02:03 dkhokhlov

@yosun

cog on "support_for_list_in_input" PR branch supports list[Path] input. For local runs only, not supported in Web UI yet, in progress. Example:

$ echo test1 > 1.txt
$ echo test2 > 2.txt
$ cat predict.py
from cog import BasePredictor, Path

class Predictor(BasePredictor):
   def predict(self, paths: list[Path]) -> str:
       output_parts = []  # Use a list to collect file contents
       for path in paths:
           with open(path) as f:
             output_parts.append(f.read())
       return "".join(output_parts)

$ cog predict -i 'paths=["@1.txt", "@1.txt"]'

Running prediction...
test1

test2

dkhokhlov avatar Mar 07 '24 19:03 dkhokhlov

@yosun

cog on "support_for_list_in_input" PR branch supports list[Path] input. For local runs only, not supported in Web UI yet, in progress. Example:

$ echo test1 > 1.txt
$ echo test2 > 2.txt
$ cat predict.py
from cog import BasePredictor, Path

class Predictor(BasePredictor):
   def predict(self, paths: list[Path]) -> str:
       output_parts = []  # Use a list to collect file contents
       for path in paths:
           with open(path) as f:
             output_parts.append(f.read())
       return "".join(output_parts)

$ cog predict -i 'paths=["@1.txt", "@1.txt"]'

Running prediction...
test1

test2

Thanks a lot @dkhokhlov!

simonMoisselin avatar Mar 11 '24 18:03 simonMoisselin

@yosun

cog on "support_for_list_in_input" PR branch supports list[Path] input. For local runs only, not supported in Web UI yet, in progress. Example:

$ echo test1 > 1.txt
$ echo test2 > 2.txt
$ cat predict.py
from cog import BasePredictor, Path

class Predictor(BasePredictor):
   def predict(self, paths: list[Path]) -> str:
       output_parts = []  # Use a list to collect file contents
       for path in paths:
           with open(path) as f:
             output_parts.append(f.read())
       return "".join(output_parts)

$ cog predict -i 'paths=["@1.txt", "@1.txt"]'

Running prediction...
test1

test2

is this also supported via API, if so what's the brief format?

yosun avatar Mar 12 '24 01:03 yosun

it will be supported by api. format should be the same as in list[str] case, except str is uri str now..

dkhokhlov avatar Mar 12 '24 15:03 dkhokhlov