Voice_App / app.py
Yasir646's picture
Create app.py
be265f7 verified
import streamlit as st
from rembg import remove
from PIL import Image
import io
# App title
st.title("Background Remover App")
# File upload section
uploaded_file = st.file_uploader("Upload an Image", type=["jpg", "png", "jpeg"])
# If the user uploads an image
if uploaded_file is not None:
# Read the uploaded image file
image = Image.open(uploaded_file)
# Show the uploaded image
st.image(image, caption="Uploaded Image", use_column_width=True)
# Remove the background using rembg
img_byte_arr = io.BytesIO()
image.save(img_byte_arr, format="PNG")
img_byte_arr = img_byte_arr.getvalue()
output = remove(img_byte_arr)
# Convert the output to an image
output_image = Image.open(io.BytesIO(output))
# Show the output image with removed background
st.image(output_image, caption="Image with Background Removed", use_column_width=True)
# Option to download the result
st.download_button(
label="Download Image",
data=output,
file_name="output.png",
mime="image/png"
)