NgalNgal commited on
Commit
0e5ca43
1 Parent(s): 0cec976

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -20
app.py CHANGED
@@ -128,26 +128,26 @@ def call_model_transformer(sources, direction_trans):
128
  ct_model_path = "myen_ctranslate2/"
129
  sp_source_model_path = "myen_ctranslate2/source.model"
130
  sp_target_model_path = "myen_ctranslate2/target.model"
131
- if sources == "" :
132
- gr.Warning("Please Enter Myanmar Text")
133
- else:
134
- sp_source_model = sp.load(sp_source_model_path)
135
- sp_target_model = sp.load(sp_target_model_path)
136
- #translator = ctranslate2.Translator(ct_model_path)
137
- sources_seg = write_to_file_myanmar(sources)
138
- #Subword the source sentences
139
- source_sents_subworded = sp.encode_as_pieces([sources_seg])
140
-
141
- # Translate the source sentences
142
- translator = ctranslate2.Translator(ct_model_path, device="cpu") # or "cuda" for GPU
143
- translations = translator.translate_batch(source_sents_subworded, batch_type="tokens", max_batch_size=4096)
144
- translations = [translation.hypotheses[0] for translation in translations]
145
-
146
- # Load the target SentecePiece model
147
- sp.load(sp_target_model_path)
148
-
149
- # Desubword the target sentences
150
- translations_desubword = sp.decode(translations)
151
 
152
  else: gr.Warning("Please Select Language Direction")
153
 
 
128
  ct_model_path = "myen_ctranslate2/"
129
  sp_source_model_path = "myen_ctranslate2/source.model"
130
  sp_target_model_path = "myen_ctranslate2/target.model"
131
+ if sources == "" :
132
+ gr.Warning("Please Enter Myanmar Text")
133
+ else:
134
+ sp_source_model = sp.load(sp_source_model_path)
135
+ sp_target_model = sp.load(sp_target_model_path)
136
+ #translator = ctranslate2.Translator(ct_model_path)
137
+ sources_seg = write_to_file_myanmar(sources)
138
+ #Subword the source sentences
139
+ source_sents_subworded = sp.encode_as_pieces([sources_seg])
140
+
141
+ # Translate the source sentences
142
+ translator = ctranslate2.Translator(ct_model_path, device="cpu") # or "cuda" for GPU
143
+ translations = translator.translate_batch(source_sents_subworded, batch_type="tokens", max_batch_size=4096)
144
+ translations = [translation.hypotheses[0] for translation in translations]
145
+
146
+ # Load the target SentecePiece model
147
+ sp.load(sp_target_model_path)
148
+
149
+ # Desubword the target sentences
150
+ translations_desubword = sp.decode(translations)
151
 
152
  else: gr.Warning("Please Select Language Direction")
153