muhammadsalmanalfaridzi
commited on
Commit
β’
74c44d0
1
Parent(s):
67d8518
Update app.py
Browse files
app.py
CHANGED
@@ -44,11 +44,32 @@ def remove_background_bria(input_image):
|
|
44 |
|
45 |
# Get the segmentation output
|
46 |
segmentation_result = pipe(input_image)
|
47 |
-
|
48 |
-
#
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
# Fungsi untuk memproses gambar menggunakan prompt
|
54 |
def text_to_image(prompt):
|
|
|
44 |
|
45 |
# Get the segmentation output
|
46 |
segmentation_result = pipe(input_image)
|
47 |
+
|
48 |
+
# Check if the output contains a mask
|
49 |
+
if isinstance(segmentation_result, list) and len(segmentation_result) > 0:
|
50 |
+
# Adjust based on the actual output structure
|
51 |
+
mask = segmentation_result[0].get("mask")
|
52 |
+
|
53 |
+
if mask is not None:
|
54 |
+
# Create an output image based on the mask
|
55 |
+
output_image = Image.new("RGBA", input_image.size)
|
56 |
+
width, height = input_image.size
|
57 |
+
|
58 |
+
for y in range(height):
|
59 |
+
for x in range(width):
|
60 |
+
# Check if the mask value is valid (assuming it's binary or a single channel)
|
61 |
+
if mask[y][x] > 0: # Adjust based on actual mask values
|
62 |
+
output_image.putpixel((x, y), input_image.getpixel((x, y)))
|
63 |
+
else:
|
64 |
+
output_image.putpixel((x, y), (0, 0, 0, 0)) # Set to transparent
|
65 |
+
|
66 |
+
return output_image
|
67 |
+
else:
|
68 |
+
print("Mask is None in segmentation result.")
|
69 |
+
return input_image # Return original if mask is None
|
70 |
+
else:
|
71 |
+
print("No valid segmentation result received.")
|
72 |
+
return input_image # Return original if no valid result
|
73 |
|
74 |
# Fungsi untuk memproses gambar menggunakan prompt
|
75 |
def text_to_image(prompt):
|