Spaces:
Sleeping
Sleeping
interactive-pipe template
Browse files- app.py +59 -0
- requirements.txt +1 -0
- sample.jpg +0 -0
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from interactive_pipe import interactive_pipeline, interactive, Image
|
2 |
+
from typing import Tuple
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
|
6 |
+
# Processing blocks
|
7 |
+
# -----------------
|
8 |
+
def processing_block(
|
9 |
+
inp: np.ndarray,
|
10 |
+
amplify: float = 1.,
|
11 |
+
context: dict = {}
|
12 |
+
) -> np.ndarray:
|
13 |
+
context["amplify"] = amplify
|
14 |
+
return amplify*inp
|
15 |
+
|
16 |
+
|
17 |
+
# Pipeline definition
|
18 |
+
# -------------------
|
19 |
+
|
20 |
+
def pipe(inp: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:
|
21 |
+
out = processing_block(inp)
|
22 |
+
return inp, out
|
23 |
+
|
24 |
+
# Add interactivity to the processing blocks
|
25 |
+
# ------------------------------------------
|
26 |
+
|
27 |
+
|
28 |
+
def add_controls() -> None:
|
29 |
+
interactive(
|
30 |
+
amplify=(0.5, [0., 1.], "Amplify")
|
31 |
+
)(processing_block)
|
32 |
+
|
33 |
+
# Add interactivity to the processing blocks
|
34 |
+
# ------------------------------------------
|
35 |
+
|
36 |
+
|
37 |
+
def launch(img: np.ndarray, backend: str = "gradio"):
|
38 |
+
add_controls()
|
39 |
+
pipe_interactive = interactive_pipeline(
|
40 |
+
gui=backend,
|
41 |
+
markdown_description=markdown_description
|
42 |
+
)(pipe)
|
43 |
+
pipe_interactive(img)
|
44 |
+
|
45 |
+
|
46 |
+
if __name__ == "__main__":
|
47 |
+
import argparse
|
48 |
+
parser = argparse.ArgumentParser()
|
49 |
+
parser.add_argument("-b", "--backend", default="gradio",
|
50 |
+
choices=["gradio", "qt", "mpl"], type=str)
|
51 |
+
parser.add_argument(
|
52 |
+
"-d", "--debug", action="store_true",
|
53 |
+
help="Debug mode (to tune difficulty and tolerance)"
|
54 |
+
)
|
55 |
+
args = parser.parse_args()
|
56 |
+
markdown_description = "# Code to build this app on gradio \n\n"
|
57 |
+
markdown_description += "```python\n"+open(__file__, 'r').read()+"```"
|
58 |
+
img = Image.load_image("sample.jpg")
|
59 |
+
launch(img, backend=args.backend)
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
interactive-pipe>=0.8.3
|
sample.jpg
ADDED
![]() |