|
import os |
|
import streamlit as st |
|
import albumentations as A |
|
|
|
from utils import ( |
|
load_augmentations_config, |
|
get_arguments, |
|
get_placeholder_params, |
|
select_transformations, |
|
show_random_params, |
|
) |
|
from visuals import ( |
|
select_image, |
|
show_credentials, |
|
show_docstring, |
|
get_transormations_params, |
|
) |
|
|
|
|
|
def main(): |
|
|
|
path_to_images, width_original = get_arguments() |
|
|
|
if not os.path.isdir(path_to_images): |
|
st.title("There is no directory: " + path_to_images) |
|
else: |
|
|
|
interface_type = st.sidebar.radio( |
|
"Select the interface mode", ["Simple", "Professional"] |
|
) |
|
|
|
|
|
status, image = select_image(path_to_images, interface_type) |
|
if status == 1: |
|
st.title("Can't load image") |
|
if status == 2: |
|
st.title("Please, upload the image") |
|
else: |
|
|
|
placeholder_params = get_placeholder_params(image) |
|
|
|
|
|
augmentations = load_augmentations_config( |
|
placeholder_params, "configs/augmentations.json" |
|
) |
|
|
|
|
|
transform_names = select_transformations(augmentations, interface_type) |
|
|
|
|
|
transforms = get_transormations_params(transform_names, augmentations) |
|
|
|
try: |
|
|
|
data = A.ReplayCompose(transforms)(image=image) |
|
error = 0 |
|
except ValueError: |
|
error = 1 |
|
st.title( |
|
"The error has occurred. Most probably you have passed wrong set of parameters. \ |
|
Check transforms that change the shape of image." |
|
) |
|
|
|
|
|
if error == 0: |
|
augmented_image = data["image"] |
|
|
|
st.title("Demo of Albumentations") |
|
|
|
|
|
width_transformed = int( |
|
width_original / image.shape[1] * augmented_image.shape[1] |
|
) |
|
|
|
st.image(image, caption="Original image", width=width_original) |
|
st.image( |
|
augmented_image, |
|
caption="Transformed image", |
|
width=width_transformed, |
|
) |
|
|
|
|
|
st.write("*Press 'R' to refresh*") |
|
|
|
|
|
show_random_params(data, interface_type) |
|
|
|
|
|
for transform in transforms: |
|
show_docstring(transform) |
|
st.code(str(transform)) |
|
show_credentials() |
|
|
|
|
|
|
|
if "GA" in os.environ: |
|
st.image(os.environ["GA"]) |
|
st.markdown( |
|
( |
|
"[Privacy policy]" |
|
+ ( |
|
"(https://htmlpreview.github.io/?" |
|
+ "https://github.com/IliaLarchenko/" |
|
+ "albumentations-demo/blob/deploy/docs/privacy.html)" |
|
) |
|
) |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
main() |
|
|