EngrNarmeen's picture
Update app.py
19daa99 verified
import streamlit as st
from rembg import remove
from PIL import Image
import io
# Streamlit App Title
st.title("HD Picture Background Remover")
st.write("Upload an HD image, and this tool will remove its background while retaining high quality.")
# File Uploader
uploaded_file = st.file_uploader("Upload an HD image (PNG or JPG):", type=["png", "jpg", "jpeg"])
if uploaded_file is not None:
# Display Original Image
original_image = Image.open(uploaded_file).convert("RGBA") # Ensure transparency support
st.subheader("Original Image")
st.image(original_image, use_column_width=True)
# Remove Background
with st.spinner("Removing background..."):
input_bytes = io.BytesIO()
original_image.save(input_bytes, format="PNG")
input_bytes = input_bytes.getvalue()
output_bytes = remove(input_bytes)
output_image = Image.open(io.BytesIO(output_bytes)).convert("RGBA")
# Display Image Without Background
st.subheader("Image Without Background (HD Quality)")
st.image(output_image, use_column_width=True)
# Download Button
output_buffer = io.BytesIO()
output_image.save(output_buffer, format="PNG")
output_buffer.seek(0)
st.download_button(
label="Download HD Image Without Background",
data=output_buffer,
file_name="output_hd.png",
mime="image/png",
)