-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for list in inputs (#1561)
- added support for list[File] and list[Path]; - only in cog, still need to add list support in web UI; - updated docs/python.md;
- Loading branch information
Showing
21 changed files
with
174 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 7 additions & 4 deletions
11
test-integration/test_integration/fixtures/file-input-project/predict.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
from cog import BasePredictor, Path | ||
from cog import BasePredictor, File | ||
|
||
|
||
class Predictor(BasePredictor): | ||
def predict(self, path: Path) -> str: | ||
with open(path) as f: | ||
return f.read() | ||
def predict(self, file: File) -> str: | ||
content = file.read() | ||
if isinstance(content, bytes): | ||
# Decode bytes to str assuming UTF-8 encoding; adjust if needed | ||
content = content.decode('utf-8') | ||
return content |
1 change: 1 addition & 0 deletions
1
test-integration/test_integration/fixtures/file-input-project/test.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
text |
3 changes: 3 additions & 0 deletions
3
test-integration/test_integration/fixtures/file-list-input-project/cog.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
build: | ||
python_version: "3.11" | ||
predict: "predict.py:Predictor" |
14 changes: 14 additions & 0 deletions
14
test-integration/test_integration/fixtures/file-list-input-project/predict.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from cog import BasePredictor, File | ||
|
||
|
||
class Predictor(BasePredictor): | ||
def predict(self, files: list[File]) -> str: | ||
output_parts = [] # Use a list to collect file contents | ||
for f in files: | ||
# Assuming file content is in bytes, decode to str before appending | ||
content = f.read() | ||
if isinstance(content, bytes): | ||
# Decode bytes to str assuming UTF-8 encoding; adjust if needed | ||
content = content.decode('utf-8') | ||
output_parts.append(content) | ||
return "\n\n".join(output_parts) |
File renamed without changes.
7 changes: 7 additions & 0 deletions
7
test-integration/test_integration/fixtures/path-input-project/predict.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from cog import BasePredictor, Path | ||
|
||
|
||
class Predictor(BasePredictor): | ||
def predict(self, path: Path) -> str: | ||
with open(path) as f: | ||
return f.read() |
3 changes: 3 additions & 0 deletions
3
test-integration/test_integration/fixtures/path-list-input-project/cog.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
build: | ||
python_version: "3.11" | ||
predict: "predict.py:Predictor" |
9 changes: 9 additions & 0 deletions
9
test-integration/test_integration/fixtures/path-list-input-project/predict.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
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) |
3 changes: 3 additions & 0 deletions
3
test-integration/test_integration/fixtures/path-list-output-project/cog.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
build: | ||
python_version: "3.8" | ||
predict: "predict.py:Predictor" |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters