cr8 commited on
Commit
1a55b9b
·
verified ·
1 Parent(s): e73c8b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -1,16 +1,17 @@
1
  import gradio as gr
2
  from PIL import Image, ImageChops, ImageFilter
3
  import rembg
 
4
  import tempfile
5
  import os
6
  import zipfile
7
 
8
  def remove_background(image):
9
- """Remove background using rembg"""
10
- with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as temp:
11
- image.save(temp.name)
12
- result = rembg.remove(temp.name)
13
- return Image.open(result).convert("RGBA")
14
 
15
  def add_outline(image, outline_width=2, outline_color=(255, 255, 255)):
16
  """Add white outline to transparent image"""
 
1
  import gradio as gr
2
  from PIL import Image, ImageChops, ImageFilter
3
  import rembg
4
+ import io
5
  import tempfile
6
  import os
7
  import zipfile
8
 
9
  def remove_background(image):
10
+ """Remove background using rembg (fixed bytes handling)"""
11
+ img_byte_arr = io.BytesIO()
12
+ image.save(img_byte_arr, format='PNG')
13
+ result_bytes = rembg.remove(img_byte_arr.getvalue()) # Process bytes directly
14
+ return Image.open(io.BytesIO(result_bytes)).convert("RGBA")
15
 
16
  def add_outline(image, outline_width=2, outline_color=(255, 255, 255)):
17
  """Add white outline to transparent image"""