sourceoftruthdata
commited on
Commit
•
6f77134
1
Parent(s):
b95df8b
update app
Browse files- .gitignore +2 -0
- app.py +43 -2
.gitignore
CHANGED
@@ -30,3 +30,5 @@ tiktok_user_images/
|
|
30 |
|
31 |
#output files
|
32 |
data/
|
|
|
|
|
|
30 |
|
31 |
#output files
|
32 |
data/
|
33 |
+
|
34 |
+
|
app.py
CHANGED
@@ -3,6 +3,47 @@
|
|
3 |
##################################
|
4 |
|
5 |
import streamlit as st
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
##################################
|
4 |
|
5 |
import streamlit as st
|
6 |
+
from rembg import remove
|
7 |
+
from PIL import Image
|
8 |
+
from io import BytesIO
|
9 |
+
import base64
|
10 |
|
11 |
+
st.set_page_config(layout="wide", page_title="Image Background Remover")
|
12 |
+
|
13 |
+
st.write("## Remove background from your image")
|
14 |
+
st.write(
|
15 |
+
":dog: Try uploading an image to watch the background magically removed. Full quality images can be downloaded from the sidebar. This code is open source and available [here](https://github.com/tyler-simons/BackgroundRemoval) on GitHub. Special thanks to the [rembg library](https://github.com/danielgatis/rembg) :grin:"
|
16 |
+
)
|
17 |
+
st.sidebar.write("## Upload and download :gear:")
|
18 |
+
|
19 |
+
MAX_FILE_SIZE = 5 * 1024 * 1024 # 5MB
|
20 |
+
|
21 |
+
# Download the fixed image
|
22 |
+
def convert_image(img):
|
23 |
+
buf = BytesIO()
|
24 |
+
img.save(buf, format="PNG")
|
25 |
+
byte_im = buf.getvalue()
|
26 |
+
return byte_im
|
27 |
+
|
28 |
+
def fix_image(upload):
|
29 |
+
image = Image.open(upload)
|
30 |
+
col1.write("Original Image :camera:")
|
31 |
+
col1.image(image)
|
32 |
+
|
33 |
+
fixed = remove(image)
|
34 |
+
col2.write("Fixed Image :wrench:")
|
35 |
+
col2.image(fixed)
|
36 |
+
st.sidebar.markdown("\n")
|
37 |
+
st.sidebar.download_button("Download fixed image", convert_image(fixed), "fixed.png", "image/png")
|
38 |
+
|
39 |
+
|
40 |
+
col1, col2 = st.columns(2)
|
41 |
+
my_upload = st.sidebar.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
|
42 |
+
|
43 |
+
if my_upload is not None:
|
44 |
+
if my_upload.size > MAX_FILE_SIZE:
|
45 |
+
st.error("The uploaded file is too large. Please upload an image smaller than 5MB.")
|
46 |
+
else:
|
47 |
+
fix_image(upload=my_upload)
|
48 |
+
# else:
|
49 |
+
# fix_image("./zebra.jpg")
|