-
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
Open
Sakshi146-eng
wants to merge
4
commits into
RK1905101:master
Choose a base branch
from
Sakshi146-eng:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Closes issue #261 #311
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
35429ff
Add AI Background Remover project
Sakshi146-eng b5a444b
Add README.md for AI Background Remover project
Sakshi146-eng 27ccdc6
Update README.md for AI Background Remover
Sakshi146-eng 74a63e9
Revise README for clarity and additional details
Sakshi146-eng File filter
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
commit 35429ffdc88a1324b177ee9e523356e740ca566b
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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())) | ||
| 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) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| ) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.