cr8 commited on
Commit
19c458f
·
verified ·
1 Parent(s): f5c101d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -4,16 +4,17 @@ import rembg
4
  import io
5
 
6
  def remove_background(image):
7
- # Process image to bytes
8
  img_byte_arr = io.BytesIO()
9
  image.save(img_byte_arr, format='PNG')
10
  processed_bytes = rembg.remove(img_byte_arr.getvalue())
11
 
12
- # Create PIL image for preview
13
  processed_img = Image.open(io.BytesIO(processed_bytes))
 
 
14
 
15
- # Return (preview image, (filename, bytes)) for download
16
- return processed_img, ("no_background.png", processed_bytes)
17
 
18
  # Gradio Interface
19
  image_upload = gr.Image(label="Upload Image", type="pil")
 
4
  import io
5
 
6
  def remove_background(image):
7
+ # Convert image to bytes
8
  img_byte_arr = io.BytesIO()
9
  image.save(img_byte_arr, format='PNG')
10
  processed_bytes = rembg.remove(img_byte_arr.getvalue())
11
 
12
+ # Prepare outputs
13
  processed_img = Image.open(io.BytesIO(processed_bytes))
14
+ file_obj = io.BytesIO(processed_bytes)
15
+ file_obj.name = "no_background.png" # Required for Gradio
16
 
17
+ return processed_img, file_obj
 
18
 
19
  # Gradio Interface
20
  image_upload = gr.Image(label="Upload Image", type="pil")