Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# β
Import libraries
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from rembg import remove
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import io
|
| 6 |
+
|
| 7 |
+
# β
Background remover function
|
| 8 |
+
def remove_background(image: Image.Image) -> Image.Image:
|
| 9 |
+
buffered = io.BytesIO()
|
| 10 |
+
image.save(buffered, format="PNG")
|
| 11 |
+
img_bytes = buffered.getvalue()
|
| 12 |
+
output_bytes = remove(img_bytes)
|
| 13 |
+
output_image = Image.open(io.BytesIO(output_bytes)).convert("RGBA")
|
| 14 |
+
return output_image
|
| 15 |
+
|
| 16 |
+
# β
Example Images (updated with working URLs)
|
| 17 |
+
examples = [
|
| 18 |
+
["https://upload.wikimedia.org/wikipedia/commons/thumb/1/15/Cat_August_2010-4.jpg/480px-Cat_August_2010-4.jpg"],
|
| 19 |
+
["https://upload.wikimedia.org/wikipedia/commons/thumb/4/4d/Cat_November_2010-1a.jpg/480px-Cat_November_2010-1a.jpg"]
|
| 20 |
+
]
|
| 21 |
+
|
| 22 |
+
# β
Social Media & Credits Markdown
|
| 23 |
+
socials = """
|
| 24 |
+
### π€ Special Thanks
|
| 25 |
+
- Built with π using [rembg](https://github.com/danielgatis/rembg) β the amazing open-source AI background remover.
|
| 26 |
+
|
| 27 |
+
### π¨βπ» Developer
|
| 28 |
+
- @Kaiiddo
|
| 29 |
+
|
| 30 |
+
### π Follow Me
|
| 31 |
+
- πΊ [YouTube](https://youtube.com/@kaiiddo)
|
| 32 |
+
- π¦ [Twitter / X](https://twitter.com/kaiiddo)
|
| 33 |
+
- ππ» [Telegram](https://telegram.me/kaiiddo)
|
| 34 |
+
- π [GitHub](https://github.com/prokaiiddo)
|
| 35 |
+
- π [BlueSky](https://bsky.app/profile/kaiiddo.bsky.social)
|
| 36 |
+
- πΌ [LinkedIn](https://www.linkedin.com/in/kaiiddo)
|
| 37 |
+
"""
|
| 38 |
+
|
| 39 |
+
# β
Gradio Interface
|
| 40 |
+
interface = gr.Interface(
|
| 41 |
+
fn=remove_background,
|
| 42 |
+
inputs=gr.Image(type="pil", label="πΌοΈ Upload Image"),
|
| 43 |
+
outputs=gr.Image(type="pil", label="π― Output (Transparent Background)"),
|
| 44 |
+
title="πΌοΈ AI ClearCut - Background Remover",
|
| 45 |
+
description="""
|
| 46 |
+
Welcome to AI ClearCut!
|
| 47 |
+
Remove image backgrounds instantly using AI. Upload any image and get a transparent version in seconds.
|
| 48 |
+
|
| 49 |
+
β
Fast
|
| 50 |
+
β
Free
|
| 51 |
+
β
No Login Needed
|
| 52 |
+
""",
|
| 53 |
+
examples=examples,
|
| 54 |
+
article=socials
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
# β
Launch it on Colab (shareable public link)
|
| 58 |
+
interface.launch(share=True)
|