Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +35 -39
src/streamlit_app.py
CHANGED
@@ -1,40 +1,36 @@
|
|
1 |
-
import altair as alt
|
2 |
-
import numpy as np
|
3 |
-
import pandas as pd
|
4 |
import streamlit as st
|
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 |
-
))
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from rembg import remove
|
3 |
+
from PIL import Image
|
4 |
+
import io
|
5 |
+
|
6 |
+
# App Title
|
7 |
+
st.title("🧼 Background Remover App")
|
8 |
+
st.markdown("Upload an image, and we'll remove the background using [rembg](https://github.com/danielgatis/rembg).")
|
9 |
+
|
10 |
+
# File uploader
|
11 |
+
uploaded_file = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
|
12 |
+
|
13 |
+
# Remove background button
|
14 |
+
if uploaded_file is not None:
|
15 |
+
image = Image.open(uploaded_file)
|
16 |
+
st.image(image, caption="Original Image", use_column_width=True)
|
17 |
+
|
18 |
+
if st.button("Remove Background"):
|
19 |
+
with st.spinner("Removing background..."):
|
20 |
+
# Remove background
|
21 |
+
result = remove(image)
|
22 |
+
|
23 |
+
# Display result
|
24 |
+
st.image(result, caption="Image Without Background", use_column_width=True)
|
25 |
+
|
26 |
+
# Convert result to bytes for download
|
27 |
+
buf = io.BytesIO()
|
28 |
+
result.save(buf, format="PNG")
|
29 |
+
byte_im = buf.getvalue()
|
30 |
+
|
31 |
+
st.download_button(
|
32 |
+
label="📥 Download Transparent Image",
|
33 |
+
data=byte_im,
|
34 |
+
file_name="output.png",
|
35 |
+
mime="image/png"
|
36 |
+
)
|
|