Waflon commited on
Commit
39ec6b5
·
verified ·
1 Parent(s): 340c951

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from io import BytesIO
2
+
3
+ import streamlit as st
4
+ from PIL import Image
5
+ from rembg import remove
6
+
7
+ st.title("Hello Upload!")
8
+
9
+ # Upload the file
10
+ image_upload = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
11
+
12
+ # Convert the image to BytesIO so we can download it!
13
+ def convert_image(img):
14
+ buf = BytesIO()
15
+ img.save(buf, format="PNG")
16
+ byte_im = buf.getvalue()
17
+ return byte_im
18
+
19
+ # If we've uploaded an image, open it and remove the background!
20
+ if image_upload:
21
+ # SHOW the uploaded image!
22
+ st.image(image_upload)
23
+ image = Image.open(image_upload)
24
+ fixed = remove(image)
25
+ downloadable_image = convert_image(fixed)
26
+ # SHOW the improved image!
27
+ st.image(downloadable_image)
28
+ st.download_button(
29
+ "Download fixed image", downloadable_image, "fixed.png", "image/png"
30
+ )