Update app.py
Browse filesdigit to letter amharic and tigrigna library
app.py
CHANGED
@@ -1,162 +1,136 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
if
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
)
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
)
|
138 |
-
)
|
139 |
-
|
140 |
-
return plt
|
141 |
-
|
142 |
-
|
143 |
-
ui.include_css(app_dir / "styles.css")
|
144 |
-
|
145 |
-
# --------------------------------------------------------
|
146 |
-
# Reactive calculations and effects
|
147 |
-
# --------------------------------------------------------
|
148 |
-
|
149 |
-
|
150 |
-
@reactive.calc
|
151 |
-
def tips_data():
|
152 |
-
bill = input.total_bill()
|
153 |
-
idx1 = tips.total_bill.between(bill[0], bill[1])
|
154 |
-
idx2 = tips.time.isin(input.time())
|
155 |
-
return tips[idx1 & idx2]
|
156 |
-
|
157 |
-
|
158 |
-
@reactive.effect
|
159 |
-
@reactive.event(input.reset)
|
160 |
-
def _():
|
161 |
-
ui.update_slider("total_bill", value=bill_rng)
|
162 |
-
ui.update_checkbox_group("time", selected=["Lunch", "Dinner"])
|
|
|
1 |
+
def amharic_number_reader(number):
|
2 |
+
nums = []
|
3 |
+
val = list(number) # Convert the number string to a list of digits
|
4 |
+
readNums1 = ["አንድ", "ሁለት", "ሶስት", "አራት", "አምስት", "ስድስት", "ሰባት", "ስምንት", "ዘጠኝ", "ዜሮ"]
|
5 |
+
readNums2 = ["አስራ", "ሃያ", "ሰላሳ", "አርባ", "ሃምሳ", "ስልሳ", "ሰባ", "ሰማንያ", "ዘጠና"]
|
6 |
+
readNums3 = ["", "መቶ", "ሺ", "አስር ሺ", "መቶ ሺ", "ሚልዮን", "አስር ሚልዮን", "ቢልዮን", "አስር ቢልዮን", "ትሪልዮን"]
|
7 |
+
|
8 |
+
group_count = len(val)
|
9 |
+
|
10 |
+
for i, digit in enumerate(val):
|
11 |
+
digit = int(digit)
|
12 |
+
position = group_count - i - 1 # Position from the right
|
13 |
+
|
14 |
+
if position == 12: # Trillions
|
15 |
+
if digit != 0:
|
16 |
+
nums.append(readNums1[digit - 1])
|
17 |
+
nums.append(readNums3[9]) # 'ትሪልዮን'
|
18 |
+
elif position == 11: # Hundreds of trillions
|
19 |
+
if digit != 0:
|
20 |
+
nums.append(readNums1[digit - 1])
|
21 |
+
nums.append(readNums3[1]) # 'መቶ'
|
22 |
+
elif position == 10: # Tens of trillions
|
23 |
+
if digit != 0:
|
24 |
+
nums.append(readNums2[digit - 1])
|
25 |
+
elif position == 9: # Billions
|
26 |
+
if digit != 0:
|
27 |
+
nums.append(readNums1[digit - 1])
|
28 |
+
nums.append(readNums3[7]) # 'ቢልዮን'
|
29 |
+
elif position == 8: # Hundreds of billions
|
30 |
+
if digit != 0:
|
31 |
+
nums.append(readNums1[digit - 1])
|
32 |
+
nums.append(readNums3[1]) # 'መቶ'
|
33 |
+
elif position == 7: # Tens of billions
|
34 |
+
if digit != 0:
|
35 |
+
nums.append(readNums2[digit - 1])
|
36 |
+
elif position == 6: # Millions
|
37 |
+
if digit != 0:
|
38 |
+
nums.append(readNums1[digit - 1])
|
39 |
+
nums.append(readNums3[5]) # 'ሚልዮን'
|
40 |
+
elif position == 5: # Hundreds of thousands
|
41 |
+
if digit != 0:
|
42 |
+
nums.append(readNums1[digit - 1])
|
43 |
+
nums.append(readNums3[1]) # 'መቶ'
|
44 |
+
elif position == 4: # Tens of thousands
|
45 |
+
if digit != 0:
|
46 |
+
nums.append(readNums2[digit - 1])
|
47 |
+
elif position == 3: # Thousands
|
48 |
+
if digit != 0:
|
49 |
+
nums.append(readNums1[digit - 1])
|
50 |
+
nums.append(readNums3[2]) # 'ሺ'
|
51 |
+
elif position == 2: # Hundreds
|
52 |
+
if digit != 0:
|
53 |
+
nums.append(readNums1[digit - 1])
|
54 |
+
nums.append(readNums3[1]) # 'መቶ'
|
55 |
+
elif position == 1: # Tens
|
56 |
+
if digit != 0:
|
57 |
+
nums.append(readNums2[digit - 1])
|
58 |
+
elif position == 0: # Ones
|
59 |
+
if digit != 0:
|
60 |
+
nums.append(readNums1[digit - 1])
|
61 |
+
|
62 |
+
return " ".join(nums) # Return as a sentence
|
63 |
+
def tigrigna_number_reader(number):
|
64 |
+
nums = []
|
65 |
+
val = list(number) # Convert the number string to a list of digits
|
66 |
+
readNums1 = ["ሓደ", "ክልተ", "ሰለስተ", "ኣርባዕተ", "ሓሙሽተ", "ሽዱሽተ", "ሸዋዓተ", "ሸሞንተ", "ትሽዓተ", "ባዶ"]
|
67 |
+
readNums2 = ["ዓሰርተ", "ዕስራ", "ሰላሳ", "ዓርባዓ", "ሓምሳ", "ስልሳ", "ሰብዓ", "ሰማንያ", "ቴስዓ"]
|
68 |
+
readNums3 = ["", "ምእቲ", "ሽሕ", "ዓስርተ ሽሕ", "መቶ ሺሕ", "ሚልዮን", "ዓስርተ ሚልዮን", "ቢልዮን", "ዓስርተ ቢልዮን", "ትሪልዮን"]
|
69 |
+
|
70 |
+
group_count = len(val)
|
71 |
+
|
72 |
+
for i, digit in enumerate(val):
|
73 |
+
digit = int(digit)
|
74 |
+
position = group_count - i - 1 # Position from the right
|
75 |
+
|
76 |
+
if position == 12: # Trillions
|
77 |
+
if digit != 0:
|
78 |
+
nums.append(readNums1[digit - 1])
|
79 |
+
nums.append(readNums3[9]) # 'ትሪልዮን'
|
80 |
+
elif position == 11: # Hundreds of trillions
|
81 |
+
if digit != 0:
|
82 |
+
nums.append(readNums1[digit - 1])
|
83 |
+
nums.append(readNums3[1]) # 'መቶ'
|
84 |
+
elif position == 10: # Tens of trillions
|
85 |
+
if digit != 0:
|
86 |
+
nums.append(readNums2[digit - 1])
|
87 |
+
elif position == 9: # Billions
|
88 |
+
if digit != 0:
|
89 |
+
nums.append(readNums1[digit - 1])
|
90 |
+
nums.append(readNums3[7]) # 'ቢልዮን'
|
91 |
+
elif position == 8: # Hundreds of billions
|
92 |
+
if digit != 0:
|
93 |
+
nums.append(readNums1[digit - 1])
|
94 |
+
nums.append(readNums3[1]) # 'መቶ'
|
95 |
+
elif position == 7: # Tens of billions
|
96 |
+
if digit != 0:
|
97 |
+
nums.append(readNums2[digit - 1])
|
98 |
+
elif position == 6: # Millions
|
99 |
+
if digit != 0:
|
100 |
+
nums.append(readNums1[digit - 1])
|
101 |
+
nums.append(readNums3[5]) # 'ሚልዮን'
|
102 |
+
elif position == 5: # Hundreds of thousands
|
103 |
+
if digit != 0:
|
104 |
+
nums.append(readNums1[digit - 1])
|
105 |
+
nums.append(readNums3[1]) # 'መቶ'
|
106 |
+
elif position == 4: # Tens of thousands
|
107 |
+
if digit != 0:
|
108 |
+
nums.append(readNums2[digit - 1])
|
109 |
+
elif position == 3: # Thousands
|
110 |
+
if digit != 0:
|
111 |
+
nums.append(readNums1[digit - 1])
|
112 |
+
nums.append(readNums3[2]) # 'ሺ'
|
113 |
+
elif position == 2: # Hundreds
|
114 |
+
if digit != 0:
|
115 |
+
nums.append(readNums1[digit - 1])
|
116 |
+
nums.append(readNums3[1]) # 'መቶ'
|
117 |
+
elif position == 1: # Tens
|
118 |
+
if digit != 0:
|
119 |
+
nums.append(readNums2[digit - 1])
|
120 |
+
elif position == 0: # Ones
|
121 |
+
if digit != 0:
|
122 |
+
nums.append(readNums1[digit - 1])
|
123 |
+
|
124 |
+
return " ".join(nums) # Return as a sentence
|
125 |
+
|
126 |
+
|
127 |
+
# Example Outputs
|
128 |
+
print(tigrigna_number_reader("1221"))
|
129 |
+
#ሓደ ሽሕን ክልተ ምእቲን ዕስራን ሓደን
|
130 |
+
|
131 |
+
|
132 |
+
print(tigrigna_number_reader("221222345681"))
|
133 |
+
#ክልተ ምእቲ ዕስራ ሓደ ቢልዮንን ክልተ ምእቲ ዕስራ ክልተ ሚልዮንን ሰለስተ ምእቲ ዓርባዓ ሓሙሽተ ሽሕን ሽዱሽተ ምእቲን ሰማንያን ሓደን
|
134 |
+
|
135 |
+
print(tigrigna_number_reader("8221222345681"))
|
136 |
+
#ሸሞንተ ትሪልዮን ክልተ ምእቲ ዕስራ ሓደ ቢልዮን ክልተ ምእቲ ዕስራ ክልተ ሚልዮን ሰለስተ ምእቲ ዓርባዓ ሓሙሽተ ሽሕ ሽዱሽተ ምእቲ ሰማንያ ሓደ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|