Skip to content

Instantly share code, notes, and snippets.

@zeke
Created May 12, 2022 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeke/5583ff3fa738c76312f69df6ef704fcc to your computer and use it in GitHub Desktop.
Save zeke/5583ff3fa738c76312f69df6ef704fcc to your computer and use it in GitHub Desktop.
A contrived example of a Cog predictor that produces multiple outputs
# https://github.com/replicate/cog/blob/main/docs/python.md#output
from cog import BasePredictor, BaseModel, File
class Output(BaseModel):
image: File
coords: str
class Predictor(BasePredictor):
def predict(self, source_image: Path = Input(description="Image in which to detect objects")) -> Path:
raw_coords = my_detector(source_image)
coords = json.dumps(raw_coords, indent=2)
image = Path(tempfile.mkdtemp()) / "demo.png"
return Output(coords=coords, image=image)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment