Spaces:
Runtime error
Runtime error
import streamlit as st | |
from PIL import Image | |
import rembg | |
import os | |
# Function to process the image | |
def process_image(input_img, background_img): | |
input_img = input_img.convert('RGBA') | |
background_img = background_img.convert('RGBA') | |
background_img = background_img.resize((input_img.width, input_img.height)) | |
# Remove background using rembg | |
output = rembg.remove(input_img) | |
combined_img = Image.alpha_composite(output, background_img) | |
return combined_img | |
# Streamlit app | |
def main(): | |
st.title("Background Removal and Compositing") | |
# Select background image | |
background_img_file = st.file_uploader("Select a background image", type=["jpg", "png"]) | |
if background_img_file is not None: | |
# Load input and background images | |
background_img = Image.open(background_img_file) | |
# Process the images | |
#combined_img = process_image(input_img, background_img) | |
# Display the combined image | |
st.image(background_img, caption="Combined Image", use_column_width=True) | |
if __name__ == "__main__": | |
main() |