diff --git a/AI Background Remover/README.md b/AI Background Remover/README.md new file mode 100644 index 0000000..9d27384 --- /dev/null +++ b/AI Background Remover/README.md @@ -0,0 +1,95 @@ +# šŸ–¼ļø AI Background Remover + +An AI-powered desktop tool that automatically removes image backgrounds and saves the subject as a transparent PNG — perfect for designers, students, and automation scripts. + +āœ… Built with Python +āœ… Uses `rembg` + U²-Net AI model +āœ… Works with JPG & PNG images +āœ… GUI + Command Line Interface +āœ… Hacktoberfest friendly šŸŽ‰ + +--- + +## šŸš€ Features + +| Feature | Description | +| ------------------------ | ----------------------------------------- | +| āœ‚ļø AI Background Removal | Removes background using machine learning | +| šŸ–„ļø Streamlit GUI | Upload → Preview → Remove BG → Download | +| šŸ’» CLI Tool | Command-line support for automation | +| šŸ“¦ Output | Saves transparent PNG | +| šŸ”° Beginner Friendly | Simple folder structure + clean code | + +--- + +## šŸ“Œ Project Structure + +``` +AI-Background-Remover/ +│ +ā”œā”€ā”€ src/ +│ ā”œā”€ā”€ streamlit_app.py # Streamlit UI version +│ ā”œā”€ā”€ cli_app.py # Command-line background remover +│ +ā”œā”€ā”€ assets/ +│ ā”œā”€ā”€ sample1.png +│ ā”œā”€ā”€ sample2.png +│ +ā”œā”€ā”€ requirements.txt +└── README.md +``` + +--- + +## šŸ“„ Installation + +### 1ļøāƒ£ Clone the Repository + +```bash +git clone https://github.com/RK1905101/Mini_Python_Projects/AI-Background-Remover +cd AI-Background-Remover +``` + +### 2ļøāƒ£ Install Dependencies + +> Recommended: Use a virtual environment āœ… + +```bash +pip install -r requirements.txt +``` + +If `onnxruntime` or `rembg` fails on your system: + +```bash +pip install rembg onnxruntime +``` + +--- + +## šŸ–¼ļø Streamlit GUI Usage + +Run the application: + +```bash +streamlit run src/streamlit_app.py +``` + +Then open the browser link shown in the terminal āœ… +Upload your image → Click **Remove Background** → Download PNG + +--- + +## šŸ’» CLI Tool Usage + +```bash +python src/cli_app.py input.jpg -o output.png +``` + +## šŸ“ø Screenshots + +| Before | +| ----------------------------------- | +| bgremover +| After | +output2| + diff --git a/AI Background Remover/assets/bgremover.png b/AI Background Remover/assets/bgremover.png new file mode 100644 index 0000000..1b8e0e7 Binary files /dev/null and b/AI Background Remover/assets/bgremover.png differ diff --git a/AI Background Remover/assets/output2.png b/AI Background Remover/assets/output2.png new file mode 100644 index 0000000..8dfc1ec Binary files /dev/null and b/AI Background Remover/assets/output2.png differ diff --git a/AI Background Remover/assets/sample1.png b/AI Background Remover/assets/sample1.png new file mode 100644 index 0000000..65fe38b Binary files /dev/null and b/AI Background Remover/assets/sample1.png differ diff --git a/AI Background Remover/assets/sample2.png b/AI Background Remover/assets/sample2.png new file mode 100644 index 0000000..4541b09 Binary files /dev/null and b/AI Background Remover/assets/sample2.png differ diff --git a/AI Background Remover/requirements.txt b/AI Background Remover/requirements.txt new file mode 100644 index 0000000..6ba8084 --- /dev/null +++ b/AI Background Remover/requirements.txt @@ -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`. diff --git a/AI Background Remover/src/cli_app.py b/AI Background Remover/src/cli_app.py new file mode 100644 index 0000000..c09d168 --- /dev/null +++ b/AI Background Remover/src/cli_app.py @@ -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())) + 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) diff --git a/AI Background Remover/src/streamlit_app.py b/AI Background Remover/src/streamlit_app.py new file mode 100644 index 0000000..938dcee --- /dev/null +++ b/AI Background Remover/src/streamlit_app.py @@ -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" + )