tenet commited on
Commit
df71871
·
verified ·
1 Parent(s): 6cb5e61

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -30,21 +30,23 @@ def transcribe(audio):
30
  def segment_image(image: Image.Image):
31
  results = segmentation_pipeline(image)
32
 
33
- # Generate a random color for each object
34
  overlay = np.array(image).copy()
35
  annotations = []
 
36
  for r in results:
37
- mask = np.array(r["mask"]) # mask is a PIL image
38
  label = r["label"]
39
 
40
- # Random color per mask
41
  color = [random.randint(0, 255) for _ in range(3)]
 
42
 
43
- # Apply semi-transparent overlay
44
- overlay[mask > 0] = (0.6 * overlay[mask > 0] + 0.4 * np.array(color)).astype(np.uint8)
45
 
46
- # Store mask + label for Gradio
47
- annotations.append((r["mask"], label))
48
 
49
  overlay_img = Image.fromarray(overlay)
50
  return (overlay_img, annotations)
 
30
  def segment_image(image: Image.Image):
31
  results = segmentation_pipeline(image)
32
 
33
+ # Make a copy for overlay
34
  overlay = np.array(image).copy()
35
  annotations = []
36
+
37
  for r in results:
38
+ mask = np.array(r["mask"]) > 0 # ensure binary mask
39
  label = r["label"]
40
 
41
+ # Random color for each object
42
  color = [random.randint(0, 255) for _ in range(3)]
43
+ overlay[mask] = (0.6 * overlay[mask] + 0.4 * np.array(color)).astype(np.uint8)
44
 
45
+ # Append as (mask, label) where mask is np.ndarray
46
+ annotations.append((mask, label))
47
 
48
+ overlay_img = Image.fromarray(overlay)
49
+ return (overlay_img, annotations)
50
 
51
  overlay_img = Image.fromarray(overlay)
52
  return (overlay_img, annotations)