File size: 2,390 Bytes
62e05d1
 
de1c0ec
62e05d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de1c0ec
 
 
 
 
 
 
 
 
 
 
62e05d1
 
 
 
 
 
 
 
 
 
de1c0ec
 
 
 
 
 
 
 
 
 
62e05d1
de1c0ec
 
 
62e05d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import streamlit as st
from streamlit_image_select import image_select
from utils_streamlit import get_result
from PIL import Image
import numpy as np

# UI configurations
st.set_page_config(page_title="AIFR - Demo",
                   page_icon=":bridge_at_night:",
                   layout="wide")
st.markdown("# :rainbow[AIFR - Demo]")
# 3 columns
col1, col2, col3, col4 = st.columns(4)

with col1:
    st.header("User Image")

    user_image_holder = st.empty()
    # upload file
    user_image = st.file_uploader("Upload User Image")
    if user_image is not None:
        img = None
        user_image_holder.image(user_image, use_column_width=True)
    
    img1 = image_select(
        label="Examples",
        images=[
            "./user_example/ex1.jpg",
            "./user_example/ex2.jpg",
        ],
        use_container_width=False,
    )
    if img1 and user_image is None:
        user_image = img1
        user_image_holder.image(user_image, use_column_width=True)

with col2:
    st.header("Clothes Image")

    clothes_image_holder = st.empty()
    # upload file
    clothes_image = st.file_uploader("Upload Clothes Image")
    if clothes_image is not None:
        clothes_image_holder.image(clothes_image, use_column_width=True)

    img2 = image_select(
        label="Example",
        images=[
            "./garment_example/ex1.jpg",
            "./garment_example/ex2.jpg",
            "./garment_example/ex3.jpg",
            "./garment_example/ex4.jpg",
        ],
        use_container_width=False,
    )

    if img2 and clothes_image is None:
        clothes_image = img2
        clothes_image_holder.image(clothes_image, use_column_width=True)
body_part = st.selectbox(
    "Choose your body part",
    ("dresses", "upper_body", "lower_body"))
submitted = st.button("Get result", use_container_width=True, type="primary")
output_image = mask_image = None

if submitted:
    user_image = Image.open(user_image)
    clothes_image = Image.open(clothes_image)
    output_image, mask_image = get_result(user_image, clothes_image, body_part=body_part)

with col3:
    st.header("Masked Image output")
    if submitted:
        if mask_image is not None:
            st.image(mask_image, use_column_width=True)

with col4:
    st.header("Output")
    if submitted:
        if output_image is not None:
            st.image(output_image, use_column_width=True)