cog
cog copied to clipboard
Array as inputs and outputs using Input method
Hello,
Is it possible to add the type array
as an input, in addition to images or files?
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
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.
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
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
Related / dupe of https://github.com/replicate/cog/issues/608
hi, I'd like to be able to upload multiple pictures for a single argument. This would be very useful for that
Hi @zeke 👋 Dust3r ( https://replicate.com/camenduru/dust3r ) needs multiple images as input.
@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
Raised it with the team. We're working on it!
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)
use simple 'str' type and split value later.
Can you provide an example? How would that work for files?
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.
right, looking into it.
@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
@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!
@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?
it will be supported by api. format should be the same as in list[str] case, except str is uri str now..