Skip to content

Commit

Permalink
test for file list input
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitri Khokhlov <dkhokhlov@gmail.com>
  • Loading branch information
dkhokhlov committed Mar 7, 2024
1 parent a679639 commit 13e39ca
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
text
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build:
python_version: "3.11"
predict: "predict.py:Predictor"
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)

0 comments on commit 13e39ca

Please sign in to comment.