uyen22 commited on
Commit
9c62be5
·
verified ·
1 Parent(s): 975036e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -14,6 +14,15 @@ headers = {
14
  "Authorization": f"Bearer {OCTOAI_TOKEN}"
15
  }
16
 
 
 
 
 
 
 
 
 
 
17
  # Function to send request to the API for background removal
18
  def remove_bg(image, background_choice, bg_color, bg_image):
19
  # Convert PIL image to base64
@@ -40,7 +49,9 @@ def remove_bg(image, background_choice, bg_color, bg_image):
40
 
41
  # Apply background based on user's choice
42
  if background_choice == "Solid Color":
43
- background = Image.new("RGBA", removed_bg_image.size, bg_color + (255,))
 
 
44
  elif background_choice == "Image" and bg_image is not None:
45
  background = bg_image.resize(removed_bg_image.size).convert("RGBA")
46
  else:
 
14
  "Authorization": f"Bearer {OCTOAI_TOKEN}"
15
  }
16
 
17
+ # Function to send request to the API for background removal
18
+ from PIL import ImageColor
19
+
20
+ def hex_to_rgba(hex_color):
21
+ """
22
+ Convert a hex color string (e.g., "#ffcccb") to an RGBA tuple.
23
+ """
24
+ return ImageColor.getcolor(hex_color, "RGBA")
25
+
26
  # Function to send request to the API for background removal
27
  def remove_bg(image, background_choice, bg_color, bg_image):
28
  # Convert PIL image to base64
 
49
 
50
  # Apply background based on user's choice
51
  if background_choice == "Solid Color":
52
+ # Convert the hex color to an RGBA tuple
53
+ rgba_color = hex_to_rgba(bg_color)
54
+ background = Image.new("RGBA", removed_bg_image.size, rgba_color)
55
  elif background_choice == "Image" and bg_image is not None:
56
  background = bg_image.resize(removed_bg_image.size).convert("RGBA")
57
  else: