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

Array as inputs and outputs using Input method #527

Open
simonMoisselin opened this issue Apr 4, 2022 · 18 comments
Open

Array as inputs and outputs using Input method #527

simonMoisselin opened this issue Apr 4, 2022 · 18 comments
Labels
enhancement New feature or request

Comments

@simonMoisselin
Copy link

Hello,

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

@zeke
Copy link
Member

zeke commented Apr 11, 2022

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

@dashstander
Copy link
Contributor

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.

@anotherjesse
Copy link
Contributor

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

@jayaffine
Copy link

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

@bfirsh
Copy link
Member

bfirsh commented Jun 23, 2023

Related / dupe of #608

@alexblattner
Copy link

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

@zeke zeke added the enhancement New feature or request label Nov 6, 2023
@camenduru
Copy link

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

@yosun
Copy link

yosun commented Mar 4, 2024

@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
Copy link

yosun commented Mar 4, 2024

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

Image from Gyazo

@zeke
Copy link
Member

zeke commented Mar 5, 2024

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

@dkhokhlov
Copy link
Contributor

dkhokhlov commented Mar 5, 2024

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)

@zeke
Copy link
Member

zeke commented Mar 5, 2024

use simple 'str' type and split value later.

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

@yosun
Copy link

yosun commented Mar 5, 2024

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.

@dkhokhlov
Copy link
Contributor

right, looking into it.

@dkhokhlov
Copy link
Contributor

dkhokhlov commented Mar 7, 2024

@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

@simonMoisselin
Copy link
Author

@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
Copy link

yosun commented Mar 12, 2024

@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?

@dkhokhlov
Copy link
Contributor

dkhokhlov commented Mar 12, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

10 participants