File size: 1,183 Bytes
0dca4ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from PIL import Image
import os

import sys
print(sys.executable)
from src.remover import BackgroundRemover

st.set_page_config(
    page_title="Background Remover",
    page_icon="👋",
)

if __name__ == "__main__":

    obj = BackgroundRemover()

    st.title("DEMO")
    st.write("Upload an image")

    uploaded_file = st.file_uploader("Choose a file",type=["jpg", "png", "jpeg"])
    IMAGE_DIR = "./output"

    if uploaded_file is not None:
        # To read file as bytes:
        bytes_data = uploaded_file.getvalue()

        IMAGE_PATH = os.path.join(IMAGE_DIR,uploaded_file.name)
        OUT_PATH =  os.path.join(IMAGE_DIR,"results.png")
        BACKGROUND_PATH = os.path.join(os.getcwd(),"static/background/2.png")
        with open(IMAGE_PATH,"wb") as f:
            f.write(uploaded_file.getbuffer())

        col1, col2 = st.columns(2)
        with col1:
            st.image(IMAGE_PATH, caption="Original Image",use_column_width=True)

        result = obj.process(IMAGE_PATH,BACKGROUND_PATH,OUT_PATH,True)
        with col2:
            image=Image.open(OUT_PATH)
            st.image(result, caption="Result", use_column_width=True)