-
Notifications
You must be signed in to change notification settings - Fork 145
Closes issue #261 #311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Closes issue #261 #311
Changes from all commits
35429ff
b5a444b
27ccdc6
74a63e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | | ||
| | ----------------------------------- | | ||
| | <img width="200" height="1024" alt="bgremover" src="https://github.com/user-attachments/assets/5b93d1ae-e3cc-424c-a5e6-c5a3bbc75e69" /> | ||
| | After | | ||
| <img width="200" height="1024" alt="output2" src="https://github.com/user-attachments/assets/7087cf33-b6eb-444d-81b2-187a498d4a1d" />| | ||
|
|
||
| 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`. |
| 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
|
||
| 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) | ||
| 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" | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The markdown table structure is malformed. Line 92 has an extra pipe character at the start, and line 94's image tag is outside the table cell structure. This will render incorrectly. The table should have consistent pipe placement:
| Before | <img...> |and| After | <img...> |