IliaLarchenko commited on
Commit
8cc587c
1 Parent(s): 597cce4

refactoring

Browse files
Files changed (1) hide show
  1. src/app.py +66 -60
src/app.py CHANGED
@@ -16,72 +16,78 @@ from visuals import (
16
  get_transormations_params,
17
  )
18
 
19
- # TODO: refactor all the new code
20
-
21
- # get CLI params: the path to images and image width
22
- path_to_images, width_original = get_arguments()
23
-
24
- if not os.path.isdir(path_to_images):
25
- st.title("There is no directory: " + path_to_images)
26
- else:
27
- # select interface type
28
- interface_type = st.sidebar.radio(
29
- "Select the interface mode", ["Simple", "Professional"]
30
- )
31
-
32
- # select image
33
- status, image = select_image(path_to_images, interface_type)
34
- if status == 1:
35
- st.title("Can't load image")
36
- if status == 2:
37
- st.title("Please, upload the image")
38
- else:
39
- # image was loaded successfully
40
- placeholder_params = get_placeholder_params(image)
41
 
42
- # load the config
43
- augmentations = load_augmentations_config(
44
- placeholder_params, "configs/augmentations.json"
 
 
 
 
 
 
 
45
  )
46
 
47
- # get list of transformations names
48
- transform_names = select_transformations(augmentations, interface_type)
49
-
50
- # get parameters for each transform
51
- transforms = get_transormations_params(transform_names, augmentations)
52
-
53
- try:
54
- # apply the transformation to the image
55
- data = A.ReplayCompose(transforms)(image=image)
56
- error = 0
57
- except ValueError:
58
- error = 1
59
- st.title(
60
- "The error has occurred. Most probably you have passed wrong set of parameters. \
61
- Check transforms that change the shape of image."
62
  )
63
 
64
- # proced only if everything is ok
65
- if error == 0:
66
- augmented_image = data["image"]
67
- # show title
68
- st.title("Demo of Albumentations")
69
 
70
- # show the images
71
- width_transformed = int(
72
- width_original / image.shape[1] * augmented_image.shape[1]
73
- )
74
 
75
- st.image(image, caption="Original image", width=width_original)
76
- st.image(
77
- augmented_image, caption="Transformed image", width=width_transformed
78
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
- # random values used to get transformations
81
- show_random_params(data, interface_type)
82
 
83
- # print additional info
84
- for transform in transforms:
85
- show_docstring(transform)
86
- st.code(str(transform))
87
- show_credentials()
 
16
  get_transormations_params,
17
  )
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
+ def main():
21
+ # get CLI params: the path to images and image width
22
+ path_to_images, width_original = get_arguments()
23
+
24
+ if not os.path.isdir(path_to_images):
25
+ st.title("There is no directory: " + path_to_images)
26
+ else:
27
+ # select interface type
28
+ interface_type = st.sidebar.radio(
29
+ "Select the interface mode", ["Simple", "Professional"]
30
  )
31
 
32
+ # select image
33
+ status, image = select_image(path_to_images, interface_type)
34
+ if status == 1:
35
+ st.title("Can't load image")
36
+ if status == 2:
37
+ st.title("Please, upload the image")
38
+ else:
39
+ # image was loaded successfully
40
+ placeholder_params = get_placeholder_params(image)
41
+
42
+ # load the config
43
+ augmentations = load_augmentations_config(
44
+ placeholder_params, "configs/augmentations.json"
 
 
45
  )
46
 
47
+ # get the list of transformations names
48
+ transform_names = select_transformations(augmentations, interface_type)
 
 
 
49
 
50
+ # get parameters for each transform
51
+ transforms = get_transormations_params(transform_names, augmentations)
 
 
52
 
53
+ try:
54
+ # apply the transformation to the image
55
+ data = A.ReplayCompose(transforms)(image=image)
56
+ error = 0
57
+ except ValueError:
58
+ error = 1
59
+ st.title(
60
+ "The error has occurred. Most probably you have passed wrong set of parameters. \
61
+ Check transforms that change the shape of image."
62
+ )
63
+
64
+ # proceed only if everything is ok
65
+ if error == 0:
66
+ augmented_image = data["image"]
67
+ # show title
68
+ st.title("Demo of Albumentations")
69
+
70
+ # show the images
71
+ width_transformed = int(
72
+ width_original / image.shape[1] * augmented_image.shape[1]
73
+ )
74
+
75
+ st.image(image, caption="Original image", width=width_original)
76
+ st.image(
77
+ augmented_image,
78
+ caption="Transformed image",
79
+ width=width_transformed,
80
+ )
81
+
82
+ # random values used to get transformations
83
+ show_random_params(data, interface_type)
84
+
85
+ # print additional info
86
+ for transform in transforms:
87
+ show_docstring(transform)
88
+ st.code(str(transform))
89
+ show_credentials()
90
 
 
 
91
 
92
+ if __name__ == "__main__":
93
+ main()