Regino commited on
Commit
3f1a2fc
·
1 Parent(s): c670e3c

first commit

Browse files
Files changed (2) hide show
  1. app.py +86 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ from rembg import remove
4
+ import io
5
+ import time
6
+
7
+ # Set app title and description
8
+ st.title("🎨 SnipSnap")
9
+ st.write("Upload an image, and we'll remove the background for you!")
10
+
11
+ # Upload image
12
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
13
+
14
+ if uploaded_file is not None:
15
+ # Open the image
16
+ input_image = Image.open(uploaded_file)
17
+
18
+ # Resize the image to a maximum width of 600 pixels (adjust as needed)
19
+ max_width = 600
20
+ width_percent = max_width / float(input_image.size[0])
21
+ height_size = int(float(input_image.size[1]) * float(width_percent))
22
+ input_image = input_image.resize((max_width, height_size), Image.Resampling.LANCZOS)
23
+
24
+ # Display the uploaded image
25
+ st.image(input_image, caption="Uploaded Image", use_container_width=True)
26
+
27
+ # Add a progress bar
28
+ st.write("Removing background...")
29
+ progress_bar = st.progress(0)
30
+ for i in range(100):
31
+ time.sleep(0.02) # Simulate processing time
32
+ progress_bar.progress(i + 1)
33
+
34
+ # Remove background
35
+ output_image = remove(input_image)
36
+
37
+ # Display the result
38
+ st.image(output_image, caption="Background Removed", use_container_width=True)
39
+
40
+ # Add a download button
41
+ buffered = io.BytesIO()
42
+ output_image.save(buffered, format="PNG")
43
+ st.download_button(
44
+ label="⬇️ Download Result",
45
+ data=buffered.getvalue(),
46
+ file_name="background_removed.png",
47
+ mime="image/png",
48
+ )
49
+
50
+ # Custom CSS for better styling
51
+ st.markdown(
52
+ """
53
+ <style>
54
+ /* Center-align the title */
55
+ h1 {
56
+ text-align: center;
57
+ }
58
+
59
+ /* Add some padding and a border to the uploader */
60
+ .stFileUploader > div {
61
+ padding: 20px;
62
+ border: 2px dashed #ccc;
63
+ border-radius: 10px;
64
+ text-align: center;
65
+ margin-top: 20px;
66
+ }
67
+
68
+ /* Style the download button */
69
+ .stDownloadButton button {
70
+ width: 100%;
71
+ background-color: #4CAF50;
72
+ color: white;
73
+ padding: 10px;
74
+ border: none;
75
+ border-radius: 5px;
76
+ font-size: 16px;
77
+ }
78
+
79
+ /* Style the progress bar */
80
+ .stProgress > div > div > div {
81
+ background-color: #4CAF50;
82
+ }
83
+ </style>
84
+ """,
85
+ unsafe_allow_html=True,
86
+ )
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit
2
+ rembg
3
+ Pillow
4
+ onnxruntime
5
+ numpy