haydpw commited on
Commit
36d80a3
1 Parent(s): d0c641b

ga tau nama commit apa

Browse files
Files changed (2) hide show
  1. main.py +2 -1
  2. utils/helpers.py +2 -1
main.py CHANGED
@@ -62,6 +62,7 @@ async def predict_image(file: UploadFile = File(...)):
62
  # change the mask to base64 and calculate the score
63
  for i in range(len(results)):
64
  mask_area = calculate_mask_area(results[i]["mask"])
 
65
  processed_image = process_image(results[i]["mask"])
66
  results[i]["mask"] = image_to_base64(processed_image, "PNG")
67
  if results[i]["label"] == "background":
@@ -90,4 +91,4 @@ async def predict_image(file: UploadFile = File(...)):
90
  except Exception as e:
91
  # Mendapatkan stack trace
92
  error_traceback = traceback.format_exc()
93
- raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
 
62
  # change the mask to base64 and calculate the score
63
  for i in range(len(results)):
64
  mask_area = calculate_mask_area(results[i]["mask"])
65
+ print(results[i]["mask"].size)
66
  processed_image = process_image(results[i]["mask"])
67
  results[i]["mask"] = image_to_base64(processed_image, "PNG")
68
  if results[i]["label"] == "background":
 
91
  except Exception as e:
92
  # Mendapatkan stack trace
93
  error_traceback = traceback.format_exc()
94
+ raise HTTPException(status_code=500, detail=f"An error occurred: {error_traceback}")
utils/helpers.py CHANGED
@@ -38,5 +38,6 @@ def combine_images(original_image: Image.Image, masks: list) -> Image.Image:
38
  mask_image = Image.open(io.BytesIO(base64.b64decode(mask['mask'])))
39
  mask_image = mask_image.convert("L") # Convert mask to grayscale
40
  mask_image = ImageEnhance.Brightness(mask_image).enhance(0.5) # Adjust the brightness to make it more visible
41
- combined = ImageChops.add(combined, mask_image)
 
42
  return combined
 
38
  mask_image = Image.open(io.BytesIO(base64.b64decode(mask['mask'])))
39
  mask_image = mask_image.convert("L") # Convert mask to grayscale
40
  mask_image = ImageEnhance.Brightness(mask_image).enhance(0.5) # Adjust the brightness to make it more visible
41
+ color_mask = Image.new("RGBA", original_image.size, (255, 0, 0, 128)) # Red color with transparency
42
+ combined.paste(color_mask, (0, 0), mask_image)
43
  return combined