AItool commited on
Commit
44f7997
·
verified ·
1 Parent(s): 5773990

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -14
app.py CHANGED
@@ -67,24 +67,20 @@ def input_changed(source_language_dropdown, input_text=""):
67
  def translate(input_text, source, target):
68
  source_readable = source
69
 
70
- # Detect source if needed
71
  if source == "Detect" or source.startswith("Detected"):
72
- source, _ = auto_detect_language_code(input_text)
73
-
74
- # Map from human-readable name to code if needed
75
- if source in source_lang_dict:
76
- source = source_lang_dict[source]
77
- if target in target_lang_dict:
78
- target = target_lang_dict[target]
79
 
80
  try:
81
- target = target_lang_dict[target]
82
- model = f"Helsinki-NLP/opus-mt-{source}-{target}"
83
- pipe = pipeline("translation", model=model)
84
- translation = pipe(input_text)
85
- return translation[0]['translation_text']
86
  except KeyError:
87
- return f"Error: Translation from {source_readable} to {target} is not supported"
88
 
89
  with st.container():
90
  st.header("Basque (EU) Euskera Multilingual Translator (Basque as the Starting Point)")
 
67
  def translate(input_text, source, target):
68
  source_readable = source
69
 
 
70
  if source == "Detect" or source.startswith("Detected"):
71
+ source, _ = auto_detect_language_code(input_text)
72
+ if source in source_lang_dict.keys():
73
+ source = source_lang_dict[source]
74
+ target_lang_dict, _ = get_target_languages(source)
 
 
 
75
 
76
  try:
77
+ target = target_lang_dict[target]
78
+ model = f"Helsinki-NLP/opus-mt-{source}-{target}"
79
+ pipe = pipeline("translation", model=model)
80
+ translation = pipe(input_text)
81
+ return translation[0]['translation_text']
82
  except KeyError:
83
+ return f"Error: Translation from {source_readable} to {target} is not supported by Translation Models"
84
 
85
  with st.container():
86
  st.header("Basque (EU) Euskera Multilingual Translator (Basque as the Starting Point)")