ydshieh HF staff commited on
Commit
f25d378
1 Parent(s): 4933944

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -24
app.py CHANGED
@@ -10,36 +10,29 @@ from transformers import AutoProcessor, AutoModelForVision2Seq
10
  import cv2
11
 
12
  colors = [
13
- (255, 255, 0),
14
- (255, 0, 255),
15
- (0, 255, 255),
16
-
17
  (255, 0, 0),
18
  (0, 255, 0),
19
  (0, 0, 255),
20
 
21
- (255, 128, 0),
22
- (255, 0, 128),
23
- (0, 255, 128),
24
-
25
- (128, 255, 0),
26
- (128, 0, 255),
27
- (0, 128, 255),
28
-
29
- (255, 128, 128),
30
- (128, 255, 128),
31
- (128, 128, 255),
32
-
33
- (128, 255, 255),
34
- (255, 128, 255),
35
- (255, 255, 128),
36
-
37
- (255, 128, 64),
38
- (255, 64, 128),
39
- (64, 255, 128),
40
  ]
41
 
42
- color_map = {f"{color_id}": "red" for color_id, color in enumerate(colors)}
 
 
43
 
44
 
45
  def is_overlapping(rect1, rect2):
@@ -82,6 +75,9 @@ def draw_entity_boxes_on_image(image, entities, show=False, save_path=None):
82
  if len(entities) == 0:
83
  return image
84
 
 
 
 
85
  new_image = image.copy()
86
  previous_bboxes = []
87
  # size of text
 
10
  import cv2
11
 
12
  colors = [
 
 
 
 
13
  (255, 0, 0),
14
  (0, 255, 0),
15
  (0, 0, 255),
16
 
17
+ (255, 255, 0),
18
+ (255, 0, 255),
19
+ (0, 255, 255),
20
+
21
+ (114, 128, 250),
22
+ (0, 165, 255),
23
+ (0, 128, 0),
24
+ (144, 238, 144),
25
+ (238, 238, 175),
26
+ (255, 191, 0),
27
+ (0, 128, 0),
28
+ (226, 43, 138),
29
+ (255, 0, 255),
30
+ (0, 215, 255),
 
 
 
 
 
31
  ]
32
 
33
+ color_map = {
34
+ f"{color_id}": f"#{hex(color[2])[2:].zfill(2)}{hex(color[1])[2:].zfill(2)}{hex(color[0])[2:].zfill(2)}" for color_id, color in enumerate(colors)
35
+ }
36
 
37
 
38
  def is_overlapping(rect1, rect2):
 
75
  if len(entities) == 0:
76
  return image
77
 
78
+ # Not to show too many bboxes
79
+ entities = entities[:len(color_map)]
80
+
81
  new_image = image.copy()
82
  previous_bboxes = []
83
  # size of text