mrbui1990 commited on
Commit
447fb2b
Β·
verified Β·
1 Parent(s): 5071c25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -13
app.py CHANGED
@@ -40,20 +40,17 @@ from rembg import remove
40
  def processRemove(image_file: Image.Image) -> Image.Image:
41
  if image_file is None:
42
  return None
43
-
44
- # Read the image data
45
- if hasattr(image_file, 'read'):
46
- input_data = image_file.read()
47
- else:
48
- with open(image_file, 'rb') as f:
49
- input_data = f.read()
50
-
51
- # Remove background
52
  output_data = remove(input_data)
53
-
54
- # Convert to PIL Image
55
- output_image = Image.open(io.BytesIO(output_data))
56
- return output_image
57
 
58
  # --- Upscaling ---
59
  MAX_SEED = np.iinfo(np.int32).max
 
40
  def processRemove(image_file: Image.Image) -> Image.Image:
41
  if image_file is None:
42
  return None
43
+
44
+ # Chuyển αΊ£nh PIL thΓ nh bytes
45
+ with BytesIO() as buffer:
46
+ image_file.save(buffer, format="PNG")
47
+ input_data = buffer.getvalue()
48
+
49
+ # Xóa nền
 
 
50
  output_data = remove(input_data)
51
+
52
+ # TrαΊ£ về αΊ£nh PIL mα»›i
53
+ return Image.open(BytesIO(output_data)).convert("RGBA")
 
54
 
55
  # --- Upscaling ---
56
  MAX_SEED = np.iinfo(np.int32).max