Update app.py
Browse files
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 |
-
#
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
| 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}")
|