Yudtkme commited on
Commit
9f0c3eb
·
verified ·
1 Parent(s): cf2e328

Update convert.py

Browse files
Files changed (1) hide show
  1. convert.py +79 -2
convert.py CHANGED
@@ -12,13 +12,90 @@ def convert_to_braille_unicode(str_input: str, path: str = "./braille_map.json")
12
  return str_output
13
 
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  def parse_xywh_and_class(boxes: torch.Tensor) -> list:
16
  """
17
  boxes input tensor
18
  boxes (torch.Tensor) or (numpy.ndarray): A tensor or numpy array containing the detection boxes,
19
  with shape (num_boxes, 6).
20
  orig_shape (torch.Tensor) or (numpy.ndarray): Original image size, in the format (height, width).
21
-
22
  Properties:
23
  xyxy (torch.Tensor) or (numpy.ndarray): The boxes in xyxy format.
24
  conf (torch.Tensor) or (numpy.ndarray): The confidence values of the boxes.
@@ -50,4 +127,4 @@ def parse_xywh_and_class(boxes: torch.Tensor) -> list:
50
  cluster = cluster[cluster[:, 0].argsort()]
51
  boxes_return.append(cluster)
52
 
53
- return boxes_return
 
12
  return str_output
13
 
14
 
15
+ def braille_to_text(braille_unicode: str) -> str:
16
+ """
17
+ Convert braille unicode characters to readable text
18
+ Based on standard English Braille Grade 1 alphabet
19
+ """
20
+ # Braille to text mapping for basic alphabet
21
+ braille_to_text_map = {
22
+ '⠁': 'a', '⠃': 'b', '⠉': 'c', '⠙': 'd', '⠑': 'e',
23
+ '⠋': 'f', '⠛': 'g', '⠓': 'h', '⠊': 'i', '⠚': 'j',
24
+ '⠅': 'k', '⠇': 'l', '⠍': 'm', '⠝': 'n', '⠕': 'o',
25
+ '⠏': 'p', '⠟': 'q', '⠗': 'r', '⠎': 's', '⠞': 't',
26
+ '⠥': 'u', '⠧': 'v', '⠺': 'w', '⠭': 'x', '⠽': 'y',
27
+ '⠵': 'z',
28
+
29
+ # Numbers (preceded by number sign ⠼)
30
+ '⠁': '1', '⠃': '2', '⠉': '3', '⠙': '4', '⠑': '5',
31
+ '⠋': '6', '⠛': '7', '⠓': '8', '⠊': '9', '⠚': '0',
32
+
33
+ # Common punctuation
34
+ '⠀': ' ', # space
35
+ '⠲': '.', '⠂': ',', '⠖': ';', '⠒': ':', '⠦': '?',
36
+ '⠖': '!', '⠄': "'", '⠤': '-', '⠌': '/', '⠐⠂': '"',
37
+ '⠣': '(', '⠜': ')',
38
+
39
+ # Special indicators
40
+ '⠼': '#', # number indicator
41
+ '⠠': '', # capital indicator (we'll handle this specially)
42
+ }
43
+
44
+ result = ""
45
+ i = 0
46
+ number_mode = False
47
+ capitalize_next = False
48
+
49
+ while i < len(braille_unicode):
50
+ char = braille_unicode[i]
51
+
52
+ # Handle number indicator
53
+ if char == '⠼':
54
+ number_mode = True
55
+ i += 1
56
+ continue
57
+
58
+ # Handle capital indicator
59
+ if char == '⠠':
60
+ capitalize_next = True
61
+ i += 1
62
+ continue
63
+
64
+ # Convert current character
65
+ if char in braille_to_text_map:
66
+ if number_mode and char in '⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚':
67
+ # Convert to numbers when in number mode
68
+ number_map = {
69
+ '⠁': '1', '⠃': '2', '⠉': '3', '⠙': '4', '⠑': '5',
70
+ '⠋': '6', '⠛': '7', '⠓': '8', '⠊': '9', '⠚': '0'
71
+ }
72
+ result += number_map[char]
73
+ else:
74
+ text_char = braille_to_text_map[char]
75
+ if capitalize_next and text_char.isalpha():
76
+ result += text_char.upper()
77
+ capitalize_next = False
78
+ else:
79
+ result += text_char
80
+
81
+ # Reset number mode after non-number character
82
+ if char == '⠀' or not char in '⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚':
83
+ number_mode = False
84
+ else:
85
+ # Unknown braille character, keep as is or use placeholder
86
+ result += char
87
+
88
+ i += 1
89
+
90
+ return result
91
+
92
+
93
  def parse_xywh_and_class(boxes: torch.Tensor) -> list:
94
  """
95
  boxes input tensor
96
  boxes (torch.Tensor) or (numpy.ndarray): A tensor or numpy array containing the detection boxes,
97
  with shape (num_boxes, 6).
98
  orig_shape (torch.Tensor) or (numpy.ndarray): Original image size, in the format (height, width).
 
99
  Properties:
100
  xyxy (torch.Tensor) or (numpy.ndarray): The boxes in xyxy format.
101
  conf (torch.Tensor) or (numpy.ndarray): The confidence values of the boxes.
 
127
  cluster = cluster[cluster[:, 0].argsort()]
128
  boxes_return.append(cluster)
129
 
130
+ return boxes_return