File size: 3,333 Bytes
af926f3
 
 
 
 
 
 
baae5a2
af926f3
 
 
 
 
 
 
 
f2c0e4b
af926f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
baae5a2
af926f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
baae5a2
6bc5840
af926f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
baae5a2
 
af926f3
baae5a2
 
 
af926f3
 
 
 
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
83
84
85
86
87
88
89
90
91
92
93
94
95
from libs import *
from utils_func import create_dir, main_processing



create_dir("tempDir")


def load_image(image_file):
	img = Image.open(image_file)
	return img


def streamlit_app():
    detection_model_path = "weight_files/clothes_detection_model.pt"
    background_model_path = "weight_files/model.h5"
    save_path = ""
    image_file = None
    st.title("""WELCOME TO MY APP""")
    st.subheader("""FOR BACKGROUND REMOVAL AND CHANGE!""")
    col1 = None
    col2 = None
    final_img = None
    with st.spinner("[UPLOAD] Image uploading"):
        try:
            image_file = st.file_uploader('[UPLOAD] Please upload your image:', type=["png", "jpg", "jpeg"])
            time.sleep(1)
        except:
            print("[ERROR] Sorry, something went wrong!")
            pass
    # print(type(image_file))

    if image_file is not None:
        st.success("Load image successfully!...")
        image = load_image(image_file)
        # print(type(image))
        col1, col2, col3 = st.columns(3)
        with col1:
            st.image(image, caption="Image before processing")
        save_path = "tempDir/"+ image_file.name
        image.save(save_path)


        image_path, details = save_path, image_file

        if details is not None:
            with col2:
                with st.spinner("[PROCESSING] Image processing"):
                    final_img_path = main_processing(col1, col2, col3, sport_bg_path=stadium_sport_bg_path, swim_bg_path=beach_swim_bg_path,
                                          office_bg_path=office_bg_path, img_path=image_path, name=details.name,
                                          detection_model_path=detection_model_path,
                                          background_model_path=background_model_path)
                    time.sleep(1)

            with col1:
                if final_img_path is not None:
                        final_img = load_image(final_img_path)
                        st.image(final_img, caption="Image after processing")
                        st.balloons()
                        with col2:
                            with open(final_img_path, "rb") as file:
                                st.write('\n')
                                st.write('\n')
                                st.write('\n')
                                st.write('\n')
                                st.write('\n')

                                file_name = save_path.split("/")[-1].split(".")[-2] +"_from_abc" + ".png"

                                if st.download_button(
                                    label="Download postprocessing image",
                                    data=file,
                                    file_name= file_name,
                                    mime="image/png"
                                ):
                                    st.success('[DOWNLOAD] Download sucessfully!')



if __name__ == '__main__':
    np.random.seed(42)
    tf.random.set_seed(42)

    bg_path = ""
    background_model_path = "weight_files/model.h5"
    detection_model_path = "weight_files/clothes_detection_model.pt"

    stadium_sport_bg_path = "backgrounds/camnou_stadium.jpg"
    beach_swim_bg_path = "backgrounds/beach.jpg"
    office_bg_path = "backgrounds/office-bg.jpg"

    image_path = None

    streamlit_app()