2seriescs commited on
Commit
8cdcb52
1 Parent(s): f550738

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -5,7 +5,7 @@ import torch
5
  # Use a pipeline as a high-level helper
6
  from transformers import pipeline
7
 
8
- pipe = pipeline(
9
  "translation",
10
  model="facebook/nllb-200-distilled-600M",
11
  torch_dtype=torch.bfloat16)
@@ -22,11 +22,11 @@ def get_FLORES_code_from_language(language):
22
 
23
 
24
  def translate_text(text, destination_language):
25
- # text = "Hello Friends, How are you?"
26
- dest_code= get_FLORES_code_from_language(destination_language)
27
- translation = text_translator(text,
28
- src_lang="eng_Latn",
29
- tgt_lang=dest_code)
30
  return translation[0]["translation_text"]
31
 
32
  gr.close_all()
 
5
  # Use a pipeline as a high-level helper
6
  from transformers import pipeline
7
 
8
+ text_translator = pipeline(
9
  "translation",
10
  model="facebook/nllb-200-distilled-600M",
11
  torch_dtype=torch.bfloat16)
 
22
 
23
 
24
  def translate_text(text, destination_language):
25
+ dest_code = get_FLORES_code_from_language(destination_language)
26
+ if dest_code is None:
27
+ return "Invalid destination language."
28
+
29
+ translation = text_translator(text, src_lang="eng_Latn", tgt_lang=dest_code)
30
  return translation[0]["translation_text"]
31
 
32
  gr.close_all()