Spaces:
Runtime error
Runtime error
CallmeKaito
commited on
Commit
•
9846483
1
Parent(s):
1c08271
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,37 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
import rembg
|
4 |
+
import os
|
5 |
|
6 |
+
# Function to process the image
|
7 |
+
def process_image(input_img, background_img):
|
8 |
+
input_img = input_img.convert('RGBA')
|
9 |
+
background_img = background_img.convert('RGBA')
|
10 |
+
background_img = background_img.resize((input_img.width, input_img.height))
|
11 |
+
|
12 |
+
# Remove background using rembg
|
13 |
+
output = rembg.remove(input_img)
|
14 |
+
|
15 |
+
combined_img = Image.alpha_composite(output, background_img)
|
16 |
+
|
17 |
+
return combined_img
|
18 |
+
|
19 |
+
# Streamlit app
|
20 |
+
def main():
|
21 |
+
st.title("Background Removal and Compositing")
|
22 |
+
|
23 |
+
# Select background image
|
24 |
+
background_img_file = st.file_uploader("Select a background image", type=["jpg", "png"])
|
25 |
+
|
26 |
+
if input_img_file is not None and background_img_file is not None:
|
27 |
+
# Load input and background images
|
28 |
+
background_img = Image.open(background_img_file)
|
29 |
+
|
30 |
+
# Process the images
|
31 |
+
#combined_img = process_image(input_img, background_img)
|
32 |
+
|
33 |
+
# Display the combined image
|
34 |
+
st.image(background_img, caption="Combined Image", use_column_width=True)
|
35 |
+
|
36 |
+
if __name__ == "__main__":
|
37 |
+
main()
|