|
import streamlit as st |
|
from rembg import remove |
|
from PIL import Image |
|
import io |
|
|
|
|
|
st.title("HD Picture Background Remover") |
|
st.write("Upload an HD image, and this tool will remove its background while retaining high quality.") |
|
|
|
|
|
uploaded_file = st.file_uploader("Upload an HD image (PNG or JPG):", type=["png", "jpg", "jpeg"]) |
|
|
|
if uploaded_file is not None: |
|
|
|
original_image = Image.open(uploaded_file).convert("RGBA") |
|
st.subheader("Original Image") |
|
st.image(original_image, use_column_width=True) |
|
|
|
|
|
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") |
|
|
|
|
|
st.subheader("Image Without Background (HD Quality)") |
|
st.image(output_image, use_column_width=True) |
|
|
|
|
|
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", |
|
) |
|
|