Skip to content

Commit

Permalink
Update models for new Cog
Browse files Browse the repository at this point in the history
  • Loading branch information
bfirsh committed Jul 30, 2021
1 parent d9a54fd commit 34b4f22
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 43 deletions.
22 changes: 6 additions & 16 deletions blur/cog.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
model: cog_predict.py:Model
examples:
- input:
image: "@examples/lena.png"
blur: 0
output: "@examples/lena.png"
- input:
image: "@examples/lena.png"
blur: 2.0
output: "@examples/lena-blur.png"
environment:
build:
python_version: "3.8"
python_packages:
- pillow==8.2.0
- "pillow==8.2.0"
system_packages:
- libpng-dev
- libjpeg-dev
architectures:
- cpu
- "libpng-dev"
- "libjpeg-dev"
predict: "predict.py:Predictor"
12 changes: 6 additions & 6 deletions blur/cog_predict.py → blur/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import cog


class Model(cog.Model):
class Predictor(cog.Predictor):
def setup(self):
pass

@cog.input("image", type=Path, help="Input image")
@cog.input("blur", type=float, help="Blur radius")
def predict(self, image, blur):
@cog.input("input", type=Path, help="Input image")
@cog.input("blur", type=float, help="Blur radius", default=5)
def predict(self, input, blur):
if blur == 0:
return image
im = Image.open(str(image))
return input
im = Image.open(str(input))
im = im.filter(ImageFilter.BoxBlur(blur))
out_path = Path(tempfile.mkdtemp()) / "out.png"
im.save(str(out_path))
Expand Down
14 changes: 3 additions & 11 deletions hello-world/cog.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
model: cog_predict.py:Model
examples:
- input:
text: "foo"
output: "hello foo"
- input:
text: "bar"
output: "hello bar"
environment:
architectures:
- cpu
build:
python_version: "3.8"
predict: "predict.py:Predictor"
10 changes: 0 additions & 10 deletions hello-world/cog_predict.py

This file was deleted.

10 changes: 10 additions & 0 deletions hello-world/predict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import cog


class Predictor(cog.Predictor):
def setup(self):
self.prefix = "hello"

@cog.input("input", type=str, help="Text that will get prefixed by 'hello '")
def predict(self, input):
return self.prefix + " " + input

0 comments on commit 34b4f22

Please sign in to comment.