Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add AI Background Remover project
  • Loading branch information
Sakshi146-eng authored Oct 26, 2025
commit 35429ffdc88a1324b177ee9e523356e740ca566b
Binary file added AI Background Remover/assets/bgremover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AI Background Remover/assets/output2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AI Background Remover/assets/sample1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AI Background Remover/assets/sample2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions AI Background Remover/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Requirements for AI Background Remover
# Core packages
rembg>=2.0.0
streamlit>=1.0
Pillow>=9.0

# Recommended runtime for performance (optional)
onnxruntime>=1.15.0 # replace with onnxruntime-gpu for GPU support

# Notes:
# - On Windows you may need Microsoft Visual C++ Build Tools for some packages.
# - If you want GPU acceleration, install `onnxruntime-gpu` instead of `onnxruntime`.
16 changes: 16 additions & 0 deletions AI Background Remover/src/cli_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import argparse
from rembg import remove

def remove_background(input_image, output_image="output.png"):
with open(input_image, "rb") as i:
with open(output_image, "wb") as o:
o.write(remove(i.read()))
Comment on lines +4 to +7
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error handling for file operations. If the input file doesn't exist or isn't readable, or if the output path is invalid, the function will crash with an unhelpful error. Consider adding try-except blocks to catch FileNotFoundError and PermissionError, providing clear error messages to users.

Copilot uses AI. Check for mistakes.
print(f"✅ Background removed! Saved as {output_image}")

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="AI Background Remover CLI Tool")
parser.add_argument("input", help="Input image path")
parser.add_argument("-o", "--output", default="output.png", help="Output image path")
args = parser.parse_args()

remove_background(args.input, args.output)
41 changes: 41 additions & 0 deletions AI Background Remover/src/streamlit_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import streamlit as st
from rembg import remove
from PIL import Image
import io

st.set_page_config(page_title="AI Background Remover", page_icon="🖼️", layout="centered")
st.title("🖼️ AI Background Remover")

uploaded_file = st.file_uploader("Upload an image (PNG/JPG)", type=["png", "jpg", "jpeg"])

if uploaded_file:

# Display original image
img = Image.open(uploaded_file)
st.subheader("Original Image")
st.image(img, use_container_width=True)

if st.button("Remove Background"):
with st.spinner("Processing... Please wait"):

uploaded_file.seek(0) # ✅ Reset pointer before second read
input_image = uploaded_file.read()

output = remove(input_image)
result_image = Image.open(io.BytesIO(output))

st.success("✅ Background Removed Successfully!")
st.subheader("Output Image")
st.image(result_image, use_container_width=True)

# Download button
buf = io.BytesIO()
result_image.save(buf, format="PNG")
byte_data = buf.getvalue()

st.download_button(
label="📥 Download Output",
data=byte_data,
file_name="removed_bg.png",
mime="image/png"
)