Spaces:
Running
Running
File size: 1,122 Bytes
21d9796 |
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 |
import streamlit as st
from rembg import remove
from PIL import Image
import io
def remove_background(image):
return remove(image)
def main():
st.title("Background Removal App")
st.write("Upload an image to remove its background")
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
input_image = Image.open(uploaded_file)
st.image(input_image, caption='Uploaded Image', use_column_width=True)
if st.button('Remove Background'):
with st.spinner('Processing...'):
output_image = remove_background(input_image)
st.image(output_image, caption='Output Image', use_column_width=True)
buf = io.BytesIO()
output_image.save(buf, format='PNG')
byte_im = buf.getvalue()
st.download_button(
label="Download Image",
data=byte_im,
file_name="output_image.png",
mime="image/png"
)
if __name__ == "__main__":
main()
|