Thanusha/Image_processing
0
1import streamlit as st2from PIL import Image3from remover import process_image # Import the processing function from remover.py4import io5 6# Streamlit app interface7st.title ("Image Background Removal and Resizing")8 9# File upload widget10uploaded_file = st.file_uploader("Choose and image file", type=["jpg", "jpeg", "png"])11 12 13if uploaded_file:14 """Read the images from the uploaded file"""15 image = Image.open(uploaded_file).convert("RGBA")16 17 # Parameters for the processing18 new_width = st.slider("Canvas Width", min_value=100, max_value=3000, value=1024, step=10)19 new_height = st.slider("Canvas Height", min_value=100, max_value=3000, value=1024, step=10)20 fixed_margin = st.slider("Margin (pixels)", min_value=0, max_value=200, value=20, step=1)21 22 # Process the image23 processed_image = process_image(image, new_height, new_width, fixed_margin)24 25 if processed_image:26 # Display the processed image27 st.image(processed_image, caption="Processed Image", use_column_width=True)28 29 # Provide download link for the processed image30 buffered = io.BytesIO()31 processed_image.save(buffered, format="PNG")32 st.download_button(33 label="Download Processed Image",34 data=buffered.getvalue(),35 file_name="processed_image.png",36 mime="image/png"37 )38 else:39 st.error("Failed to process the image. Please try again")