TallManager267 commited on
Commit
3542a05
·
verified ·
1 Parent(s): c2ccc93

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -3
app.py CHANGED
@@ -40,8 +40,10 @@ def load_model(weights_path):
40
 
41
  predictor, metadata = load_model(weights_path)
42
 
 
 
43
  def predict(pil_img):
44
- # Convert to RGB and ensure dtype is uint8
45
  img = np.array(pil_img.convert("RGB"), dtype=np.uint8)
46
 
47
  outputs = predictor(img)
@@ -52,9 +54,23 @@ def predict(pil_img):
52
  metadata=metadata,
53
  scale=1.0
54
  )
55
- out = v.draw_instance_predictions(instances)
56
- out_img = out.get_image()[:, :, ::-1]
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  return Image.fromarray(out_img)
59
 
60
  gr.Interface(
 
40
 
41
  predictor, metadata = load_model(weights_path)
42
 
43
+ import random
44
+
45
  def predict(pil_img):
46
+ # Convert to RGB uint8
47
  img = np.array(pil_img.convert("RGB"), dtype=np.uint8)
48
 
49
  outputs = predictor(img)
 
54
  metadata=metadata,
55
  scale=1.0
56
  )
 
 
57
 
58
+ # Draw ONLY masks with random colors
59
+ if instances.has("pred_masks"):
60
+ for mask in instances.pred_masks:
61
+ random_color = (
62
+ random.random(), # R
63
+ random.random(), # G
64
+ random.random() # B
65
+ )
66
+
67
+ v.draw_binary_mask(
68
+ mask.numpy(),
69
+ color=random_color,
70
+ alpha=0.6
71
+ )
72
+
73
+ out_img = v.get_image()[:, :, ::-1]
74
  return Image.fromarray(out_img)
75
 
76
  gr.Interface(