Download app.py from Geek7/i2ibg: direct link, hf CLI and curl.
- Browser
- Download file 856 Bytes
-
https://huggingface.co/spaces/Geek7/i2ibg/resolve/main/app.py
- Command line
-
hf download hf://spaces/Geek7/i2ibg/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Geek7/i2ibg/resolve/main/app.py
856 Bytes
| import gradio as gr | |
| from rembg import remove | |
| from PIL import Image | |
| import io | |
| def remove_background(input_image): | |
| # Convert the image to bytes | |
| img_byte_arr = io.BytesIO() | |
| input_image.save(img_byte_arr, format="PNG") | |
| img_byte_arr = img_byte_arr.getvalue() | |
| # Apply background removal using rembg | |
| output_bytes = remove(img_byte_arr) | |
| # Convert the output (bytes) back into a PIL image | |
| output_image = Image.open(io.BytesIO(output_bytes)) | |
| return output_image | |
| # Create the Gradio interface | |
| demo = gr.Interface( | |
| fn=remove_background, | |
| inputs=gr.Image(type="pil", label="Upload an image or Use Camera",sources="upload"), | |
| outputs=gr.Image(label="Processed Image",show_share_button=False, show_fullscreen_button=False), | |
| css="footer {visibility: hidden}" # Hide the footer | |
| ) | |
| # Launch the Gradio app | |
| demo.launch() |