Sample code
Browse files- app.py +44 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from interactive_pipe import interactive_pipeline, interactive
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
@interactive(angle=(45., [0., 360.]))
|
| 6 |
+
def gen_color(angle=45.):
|
| 7 |
+
lin_coord = np.linspace(-1, 1, 256)
|
| 8 |
+
X, Y = np.meshgrid(lin_coord, lin_coord)
|
| 9 |
+
ang = np.deg2rad(angle)
|
| 10 |
+
im = np.cos(ang) * X + np.sin(ang) * Y
|
| 11 |
+
im = np.clip(1+im, 0, 1)
|
| 12 |
+
im = np.stack(
|
| 13 |
+
[im, im[::-1], im[:, ::-1]],
|
| 14 |
+
axis=-1
|
| 15 |
+
)
|
| 16 |
+
return im
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
@interactive(
|
| 20 |
+
flip=(True, "Flip Image"),
|
| 21 |
+
mirror=(True, "Mirror Image")
|
| 22 |
+
)
|
| 23 |
+
def flip_image(img, flip=True, mirror=True):
|
| 24 |
+
img = img[::-1] if flip else img
|
| 25 |
+
img = img[:, ::-1] if mirror else img
|
| 26 |
+
return img
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
markdown_description = "# Code to build this app on gradio \n"
|
| 30 |
+
markdown_description += "```"+open(__file__, 'r').read()+"```"
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
@interactive_pipeline(
|
| 34 |
+
gui="gradio",
|
| 35 |
+
markdown_description=markdown_description
|
| 36 |
+
)
|
| 37 |
+
def simple_pipe():
|
| 38 |
+
inp = gen_color()
|
| 39 |
+
out = flip_image(inp)
|
| 40 |
+
return [inp, out]
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
if __name__ == "__main__":
|
| 44 |
+
simple_pipe()
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
interactive-pipe>=0.7.3
|