|
import streamlit as st |
|
from rembg import remove |
|
from PIL import Image |
|
import io |
|
|
|
|
|
st.title("Background Remover App") |
|
|
|
|
|
uploaded_file = st.file_uploader("Upload an Image", type=["jpg", "png", "jpeg"]) |
|
|
|
|
|
if uploaded_file is not None: |
|
|
|
image = Image.open(uploaded_file) |
|
|
|
|
|
st.image(image, caption="Uploaded Image", use_column_width=True) |
|
|
|
|
|
img_byte_arr = io.BytesIO() |
|
image.save(img_byte_arr, format="PNG") |
|
img_byte_arr = img_byte_arr.getvalue() |
|
|
|
output = remove(img_byte_arr) |
|
|
|
|
|
output_image = Image.open(io.BytesIO(output)) |
|
|
|
|
|
st.image(output_image, caption="Image with Background Removed", use_column_width=True) |
|
|
|
|
|
st.download_button( |
|
label="Download Image", |
|
data=output, |
|
file_name="output.png", |
|
mime="image/png" |
|
) |
|
|