Update app.py
Browse files
app.py
CHANGED
@@ -12,24 +12,24 @@ from nltk import sent_tokenize
|
|
12 |
sp = spm.SentencePieceProcessor()
|
13 |
|
14 |
|
15 |
-
mbart_enmy_ct_model_path = "
|
16 |
-
mbart_enmy_sp_model_path = "
|
17 |
|
18 |
-
mbart_myen_ct_model_path = "
|
19 |
-
mbart_myen_sp_model_path = "
|
20 |
|
21 |
-
mt5_ct_model_path = "
|
22 |
-
mt5_sp_model_path = "
|
23 |
|
24 |
|
25 |
-
trans_sp_source_enmy_path = "
|
26 |
-
trans_sp_target_enmy_path = "
|
27 |
|
28 |
-
trans_sp_source_myen_path = "
|
29 |
-
trans_sp_target_myen_path = "
|
30 |
|
31 |
-
trans_enmy_ct_model_path = "
|
32 |
-
trans_myen_ct_model_path = "
|
33 |
|
34 |
#translator = ctranslate2.Translator(ct_model_path)
|
35 |
#sp_model = spm.SentencePieceProcessor(sp_model_path)
|
@@ -37,11 +37,11 @@ trans_myen_ct_model_path = "/content/drive/MyDrive/transformer/myen_ctranslate2/
|
|
37 |
#!/usr/bin/python
|
38 |
|
39 |
def segment_sentence(source):
|
40 |
-
input_file = "
|
41 |
-
output_file = "
|
42 |
with open(input_file, "w", encoding="utf-8") as file:
|
43 |
file.write(source)
|
44 |
-
os.system("python
|
45 |
|
46 |
|
47 |
|
@@ -58,12 +58,12 @@ def segment_sentence(source):
|
|
58 |
|
59 |
|
60 |
def write_to_file_myanmar(source):
|
61 |
-
input_file = "
|
62 |
-
output_file = "
|
63 |
with open(input_file, "w", encoding="utf-8") as file:
|
64 |
file.write(source)
|
65 |
|
66 |
-
os.system("python
|
67 |
|
68 |
|
69 |
|
@@ -78,8 +78,8 @@ def write_to_file_myanmar(source):
|
|
78 |
return source_sents
|
79 |
|
80 |
def write_to_file_english(source):
|
81 |
-
input_file = "
|
82 |
-
#output_file = "
|
83 |
with open(input_file, "w", encoding="utf-8") as file:
|
84 |
file.write(source)
|
85 |
|
@@ -100,14 +100,14 @@ def write_to_file_english(source):
|
|
100 |
|
101 |
def call_model_transformer(sources, direction_trans):
|
102 |
if direction_trans == "English to Myanmar":
|
103 |
-
ct_model_path = "
|
104 |
-
sp_source_model_path = "
|
105 |
-
sp_target_model_path = "
|
106 |
if sources == "" :
|
107 |
gr.Warning("Please Enter English Text")
|
108 |
else:
|
109 |
-
sp_source_model = sp.load("
|
110 |
-
sp_target_model = sp.load("
|
111 |
#translator = ctranslate2.Translator(ct_model_path)
|
112 |
sources_seg = write_to_file_english(sources)
|
113 |
# Subword the source sentences
|
@@ -127,9 +127,9 @@ def call_model_transformer(sources, direction_trans):
|
|
127 |
|
128 |
|
129 |
elif direction_trans == "Myanmar to English":
|
130 |
-
ct_model_path = "
|
131 |
-
sp_source_model_path = "
|
132 |
-
sp_target_model_path = "
|
133 |
if source == "" :
|
134 |
gr.Warning("Please Enter Myanmar Text")
|
135 |
else:
|
@@ -334,7 +334,7 @@ theme = 'gstaff/whiteboard'
|
|
334 |
|
335 |
demo = gr.Blocks(css=css, theme=gr.themes.Soft(), title="Machine Translation between Myanmar and English Translator")
|
336 |
|
337 |
-
with open("
|
338 |
encoded_string = base64.b64encode(image_file.read()).decode()
|
339 |
width, height = 80, 80
|
340 |
|
|
|
12 |
sp = spm.SentencePieceProcessor()
|
13 |
|
14 |
|
15 |
+
mbart_enmy_ct_model_path = "mbart25enmy_ct2/"
|
16 |
+
mbart_enmy_sp_model_path = "mbart25enmy_ct2/sentence.bpe.model"
|
17 |
|
18 |
+
mbart_myen_ct_model_path = "mbart25myen_ct2/"
|
19 |
+
mbart_myen_sp_model_path = "mbart25myen_ct2/sentence.bpe.model"
|
20 |
|
21 |
+
mt5_ct_model_path = "mt5/mt5-ct2/"
|
22 |
+
mt5_sp_model_path = "mt5/mt5-base/"
|
23 |
|
24 |
|
25 |
+
trans_sp_source_enmy_path = "enmy_ctranslate2/source.model"
|
26 |
+
trans_sp_target_enmy_path = "enmy_ctranslate2/target.model"
|
27 |
|
28 |
+
trans_sp_source_myen_path = "myen_ctranslate2/source.model"
|
29 |
+
trans_sp_target_myen_path = "myen_ctranslate2/target.model"
|
30 |
|
31 |
+
trans_enmy_ct_model_path = "enmy_ctranslate2/"
|
32 |
+
trans_myen_ct_model_path = "myen_ctranslate2/"
|
33 |
|
34 |
#translator = ctranslate2.Translator(ct_model_path)
|
35 |
#sp_model = spm.SentencePieceProcessor(sp_model_path)
|
|
|
37 |
#!/usr/bin/python
|
38 |
|
39 |
def segment_sentence(source):
|
40 |
+
input_file = "input.txt"
|
41 |
+
output_file = "output.txt"
|
42 |
with open(input_file, "w", encoding="utf-8") as file:
|
43 |
file.write(source)
|
44 |
+
os.system("python myseg.py < input.txt > output.txt")
|
45 |
|
46 |
|
47 |
|
|
|
58 |
|
59 |
|
60 |
def write_to_file_myanmar(source):
|
61 |
+
input_file = "write-input.txt"
|
62 |
+
output_file = "read-output.txt"
|
63 |
with open(input_file, "w", encoding="utf-8") as file:
|
64 |
file.write(source)
|
65 |
|
66 |
+
os.system("python myseg.py < write-input.txt > read-output.txt")
|
67 |
|
68 |
|
69 |
|
|
|
78 |
return source_sents
|
79 |
|
80 |
def write_to_file_english(source):
|
81 |
+
input_file = "write-input.txt"
|
82 |
+
#output_file = "read-output.txt"
|
83 |
with open(input_file, "w", encoding="utf-8") as file:
|
84 |
file.write(source)
|
85 |
|
|
|
100 |
|
101 |
def call_model_transformer(sources, direction_trans):
|
102 |
if direction_trans == "English to Myanmar":
|
103 |
+
ct_model_path = "enmy_ctranslate2/"
|
104 |
+
sp_source_model_path = "enmy_ctranslate2/source.model"
|
105 |
+
sp_target_model_path = "enmy_ctranslate2/target.model"
|
106 |
if sources == "" :
|
107 |
gr.Warning("Please Enter English Text")
|
108 |
else:
|
109 |
+
sp_source_model = sp.load("enmy_ctranslate2/source.model")
|
110 |
+
sp_target_model = sp.load("enmy_ctranslate2/target.model")
|
111 |
#translator = ctranslate2.Translator(ct_model_path)
|
112 |
sources_seg = write_to_file_english(sources)
|
113 |
# Subword the source sentences
|
|
|
127 |
|
128 |
|
129 |
elif direction_trans == "Myanmar to English":
|
130 |
+
ct_model_path = "myen_ctranslate2/"
|
131 |
+
sp_source_model_path = "myen_ctranslate2/source.model"
|
132 |
+
sp_target_model_path = "myen_ctranslate2/target.model"
|
133 |
if source == "" :
|
134 |
gr.Warning("Please Enter Myanmar Text")
|
135 |
else:
|
|
|
334 |
|
335 |
demo = gr.Blocks(css=css, theme=gr.themes.Soft(), title="Machine Translation between Myanmar and English Translator")
|
336 |
|
337 |
+
with open("logo.png", "rb") as image_file:
|
338 |
encoded_string = base64.b64encode(image_file.read()).decode()
|
339 |
width, height = 80, 80
|
340 |
|