Spaces:
Build error
Build error
Update app_dialogue.py
Browse files- app_dialogue.py +12 -9
app_dialogue.py
CHANGED
@@ -71,18 +71,21 @@ import tempfile
|
|
71 |
def convert_to_rgb_pil(image):
|
72 |
print(f"***** convert_to_rgb_pil ******")
|
73 |
print(f"params: image is - {image}")
|
74 |
-
if image.mode == "RGB":
|
75 |
-
|
76 |
-
|
77 |
-
image_rgba = image.convert("RGBA")
|
78 |
-
background = Image.new("RGBA", image_rgba.size, (255, 255, 255))
|
79 |
-
alpha_composite = Image.alpha_composite(background, image_rgba)
|
80 |
-
alpha_composite = alpha_composite.convert("RGB")
|
81 |
-
|
82 |
# Save the converted image to a temporary file
|
83 |
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".jpg")
|
84 |
temp_file_path = temp_file.name
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
temp_file.close()
|
87 |
print(f"# Return the path to the saved image as - {temp_file_path}")
|
88 |
return temp_file_path # Return the path to the saved image
|
|
|
71 |
def convert_to_rgb_pil(image):
|
72 |
print(f"***** convert_to_rgb_pil ******")
|
73 |
print(f"params: image is - {image}")
|
74 |
+
#if image.mode == "RGB":
|
75 |
+
# return image
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
# Save the converted image to a temporary file
|
77 |
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".jpg")
|
78 |
temp_file_path = temp_file.name
|
79 |
+
|
80 |
+
if image.mode != "RGB":
|
81 |
+
image_rgba = image.convert("RGBA")
|
82 |
+
background = Image.new("RGBA", image_rgba.size, (255, 255, 255))
|
83 |
+
alpha_composite = Image.alpha_composite(background, image_rgba)
|
84 |
+
alpha_composite = alpha_composite.convert("RGB")
|
85 |
+
alpha_composite.save(temp_file_path)
|
86 |
+
else:
|
87 |
+
image.save(temp_file_path)
|
88 |
+
|
89 |
temp_file.close()
|
90 |
print(f"# Return the path to the saved image as - {temp_file_path}")
|
91 |
return temp_file_path # Return the path to the saved image
|