File size: 1,210 Bytes
2809aad
 
 
ba82dc2
23352e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
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
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"
            )