Spaces:
Sleeping
Sleeping
tutorial v0
Browse files- README.md +1 -1
- app.py +64 -0
- requirements.txt +1 -0
README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
---
|
| 2 |
title: Interactive Pipe Tutorial
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: indigo
|
| 6 |
sdk: gradio
|
|
|
|
| 1 |
---
|
| 2 |
title: Interactive Pipe Tutorial
|
| 3 |
+
emoji: 🎓
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: indigo
|
| 6 |
sdk: gradio
|
app.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from interactive_pipe import interactive_pipeline, interactive
|
| 2 |
+
from interactive_pipe import Curve, SingleCurve
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
@interactive(frequency=(80, [1, 100]), isotropy=(0.8, [0.1, 1.]))
|
| 7 |
+
def gen_color(frequency=0, isotropy=0.):
|
| 8 |
+
lin_coord = np.linspace(0, 1., 256)
|
| 9 |
+
X, Y = np.meshgrid(lin_coord, isotropy*lin_coord)
|
| 10 |
+
radius = 0.5+0.5*np.cos(frequency*np.sqrt(X**2 + Y**2))
|
| 11 |
+
return np.stack([np.abs(X), np.abs(Y), radius], axis=-1).clip(0, 1)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@interactive(effect=("flip", ["flip", "mirror", "flip+mirror", "identity"]))
|
| 15 |
+
def modify_geometry(img, effect="flip"):
|
| 16 |
+
img = img[::-1] if "flip" in effect else img
|
| 17 |
+
img = img[:, ::-1] if "mirror" in effect else img
|
| 18 |
+
return img
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
@interactive(bnw=(True, "Black and White"))
|
| 22 |
+
def change_color(img, bnw=True):
|
| 23 |
+
if bnw:
|
| 24 |
+
return np.mean(img, axis=-1, keepdims=True).repeat(3, axis=-1)
|
| 25 |
+
return img
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
@interactive(ratio=(0.5, [0., 1.], "Side by Side comparison"))
|
| 29 |
+
def split(img_1, img_2, ratio=0.5):
|
| 30 |
+
out = np.zeros_like(img_1)
|
| 31 |
+
split = int(ratio*img_1.shape[1])
|
| 32 |
+
out[:, :split] = img_2[:, :split]
|
| 33 |
+
out[:, split+5:] = img_1[:, split+5:]
|
| 34 |
+
return out
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def profile(img):
|
| 38 |
+
luma = img.mean(axis=-1)
|
| 39 |
+
h_profile = SingleCurve(y=luma[0, :], label="H profile")
|
| 40 |
+
v_profile = SingleCurve(y=luma[:, 0], label="V profile")
|
| 41 |
+
return Curve([h_profile, v_profile], xlabel="Position", ylabel="Luminance")
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
markdown_description = "# Code to build this app on gradio \n"
|
| 45 |
+
markdown_description += "```python\n"+open(__file__, 'r').read()+"```"
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
@ interactive_pipeline(
|
| 49 |
+
gui="gradio",
|
| 50 |
+
# gui="qt",
|
| 51 |
+
cache=True,
|
| 52 |
+
markdown_description=markdown_description
|
| 53 |
+
)
|
| 54 |
+
def simple_pipe():
|
| 55 |
+
inp = gen_color()
|
| 56 |
+
out_geometry = modify_geometry(inp)
|
| 57 |
+
out_bnw = change_color(inp)
|
| 58 |
+
out_image = split(out_geometry, out_bnw)
|
| 59 |
+
out_profile = profile(out_image)
|
| 60 |
+
return [inp, out_geometry, out_profile, out_image]
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
if __name__ == "__main__":
|
| 64 |
+
simple_pipe()
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
interactive-pipe>=0.7.4
|