import streamlit as st from PIL import Image from rembg import remove import io import time # Set app title and description st.title("🎨 SnipSnap") st.write("Upload an image, and we'll remove the background for you!") # Upload image uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"]) if uploaded_file is not None: # Open the image input_image = Image.open(uploaded_file) # Resize the image to a maximum width of 600 pixels (adjust as needed) max_width = 600 width_percent = max_width / float(input_image.size[0]) height_size = int(float(input_image.size[1]) * float(width_percent)) input_image = input_image.resize((max_width, height_size), Image.Resampling.LANCZOS) # Display the uploaded image st.image(input_image, caption="Uploaded Image", use_container_width=True) # Add a progress bar st.write("Removing background...") progress_bar = st.progress(0) for i in range(100): time.sleep(0.02) # Simulate processing time progress_bar.progress(i + 1) # Remove background output_image = remove(input_image) # Display the result st.image(output_image, caption="Background Removed", use_container_width=True) # Add a download button buffered = io.BytesIO() output_image.save(buffered, format="PNG") st.download_button( label="⬇️ Download Result", data=buffered.getvalue(), file_name="background_removed.png", mime="image/png", ) # Custom CSS for better styling st.markdown( """ """, unsafe_allow_html=True, )