Shrey-Patel commited on
Commit
1c31397
1 Parent(s): 73aadcb

add: background removal

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import time
3
+ from rembg import remove
4
+ from PIL import Image
5
+
6
+ st.title("Background Remover")
7
+
8
+ # Create a file uploader
9
+ uploaded_file = st.file_uploader("Choose an image file", type=["jpg", "jpeg", "png"])
10
+
11
+ if uploaded_file is not None:
12
+ # Retrieve the path of the uploaded file
13
+ input_path = uploaded_file.name
14
+
15
+ # Store path of the output image in the variable output_path
16
+ output_path = 'output.png'
17
+
18
+ # Start timer
19
+ start_time = time.time()
20
+
21
+ # Processing the image
22
+ with Image.open(uploaded_file) as input:
23
+ # Removing the background from the given Image
24
+ output = remove(input)
25
+
26
+ # Saving the image in the given path
27
+ output.save(output_path)
28
+
29
+ # End timer and calculate elapsed time
30
+ elapsed_time = time.time() - start_time
31
+
32
+ st.success(f"Image processing completed in {elapsed_time:.2f} seconds.")
33
+
34
+ # Display the output image
35
+ st.image(output_path)