qqwjq1981 commited on
Commit
a6cf7f8
·
verified ·
1 Parent(s): c7ac97c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -41,8 +41,11 @@ def translate_text(text, target_language):
41
  str: Translated text if successful, otherwise None.
42
  """
43
  try:
44
- # Instantiate the pipeline for the target language dynamically
45
- translator = pipeline("translation", model=f"Helsinki-NLP/opus-mt-en-{target_language}")
 
 
 
46
  translation = translator(text, max_length=1000)
47
  translated_text = translation[0]["translation_text"]
48
  logger.debug(f"Translation to {target_language}: {translated_text}")
 
41
  str: Translated text if successful, otherwise None.
42
  """
43
  try:
44
+ # Dynamically construct the model ID
45
+ model_id = f"Helsinki-NLP/opus-mt-en-{target_language}"
46
+
47
+ # Initialize the translation pipeline for the target language
48
+ translator = pipeline("translation", model=model_id)
49
  translation = translator(text, max_length=1000)
50
  translated_text = translation[0]["translation_text"]
51
  logger.debug(f"Translation to {target_language}: {translated_text}")