slimshadow commited on
Commit
21d9796
·
verified ·
1 Parent(s): 8e329a1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from rembg import remove
3
+ from PIL import Image
4
+ import io
5
+
6
+ def remove_background(image):
7
+ return remove(image)
8
+
9
+ def main():
10
+ st.title("Background Removal App")
11
+ st.write("Upload an image to remove its background")
12
+
13
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
14
+
15
+ if uploaded_file is not None:
16
+ input_image = Image.open(uploaded_file)
17
+ st.image(input_image, caption='Uploaded Image', use_column_width=True)
18
+
19
+ if st.button('Remove Background'):
20
+ with st.spinner('Processing...'):
21
+ output_image = remove_background(input_image)
22
+ st.image(output_image, caption='Output Image', use_column_width=True)
23
+ buf = io.BytesIO()
24
+ output_image.save(buf, format='PNG')
25
+ byte_im = buf.getvalue()
26
+
27
+ st.download_button(
28
+ label="Download Image",
29
+ data=byte_im,
30
+ file_name="output_image.png",
31
+ mime="image/png"
32
+ )
33
+
34
+ if __name__ == "__main__":
35
+ main()