Spaces:
Sleeping
Sleeping
import os | |
os.environ["NUMBA_DISABLE_CACHE"] = "1" | |
import streamlit as st | |
from rembg import remove | |
from PIL import Image | |
import io | |
# App Title | |
st.title("🧼 Background Remover App") | |
st.markdown("Upload an image, and we'll remove the background using [rembg](https://github.com/danielgatis/rembg).") | |
# File uploader | |
uploaded_file = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"]) | |
# Remove background button | |
if uploaded_file is not None: | |
image = Image.open(uploaded_file) | |
st.image(image, caption="Original Image", use_column_width=True) | |
if st.button("Remove Background"): | |
with st.spinner("Removing background..."): | |
# Remove background | |
result = remove(image) | |
# Display result | |
st.image(result, caption="Image Without Background", use_column_width=True) | |
# Convert result to bytes for download | |
buf = io.BytesIO() | |
result.save(buf, format="PNG") | |
byte_im = buf.getvalue() | |
st.download_button( | |
label="📥 Download Transparent Image", | |
data=byte_im, | |
file_name="output.png", | |
mime="image/png" | |
) | |