balthou commited on
Commit
5776691
·
1 Parent(s): 9d70fc6

sample pipe draft

Browse files
Files changed (2) hide show
  1. app.py +41 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from interactive_pipe import interactive_pipeline, interactive
2
+ import numpy as np
3
+
4
+
5
+ @interactive()
6
+ def exposure(img, coeff=(1., [0.5, 2.], "exposure"), bias=(0., [-0.2, 0.2])):
7
+ '''Applies a multiplication by coeff & adds a constant bias to the image'''
8
+ # In the GUI, the coeff will be labelled as "exposure".
9
+ # As the default tuple provided to bias does not end up with a string,
10
+ # the widget label will be "bias", simply named after the keyword arg.
11
+ return img*coeff + bias
12
+
13
+
14
+ @interactive()
15
+ def black_and_white(img, bnw=(True, "black and white")):
16
+ '''Averages the 3 color channels (Black & White) if bnw=True
17
+ '''
18
+ # Special mention for booleans: using a tuple like (True,) allows creating the tick box.
19
+ return np.repeat(np.expand_dims(np.average(img, axis=-1), -1), img.shape[-1], axis=-1) if bnw else img
20
+
21
+
22
+ @interactive()
23
+ def blend(img0, img1, blend_coeff=([0., 1.])):
24
+ '''Blends between two image.
25
+ - when blend_coeff=0 -> image 0 [slider to the left ]
26
+ - when blend_coeff=1 -> image 1 [slider to the right]
27
+ '''
28
+ return (1-blend_coeff)*img0 + blend_coeff*img1
29
+
30
+
31
+ @interactive_pipeline(gui="gradio", size="maximum")
32
+ def sample_pipeline(input_image):
33
+ exposed = exposure(input_image)
34
+ bnw_image = black_and_white(input_image)
35
+ blended = blend(exposed, bnw_image)
36
+ return exposed, blended, bnw_image
37
+
38
+
39
+ if __name__ == '__main__':
40
+ input_image = np.array([0., 0.5, 0.8])*np.ones((256, 512, 3))
41
+ sample_pipeline(input_image)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ interactive-pipe