edyrkaj commited on
Commit
026ac8f
·
verified ·
1 Parent(s): 70d54fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -8
app.py CHANGED
@@ -15,19 +15,12 @@ pipe = pipeline("image-to-text",
15
 
16
 
17
  def translate(input_text, source, target):
18
- source_readable = source
19
- if source == "Auto Detect" or source.startswith("Detected"):
20
- source, _ = auto_detect_language_code(input_text)
21
- if source in source_lang_dict.keys():
22
- source = source_lang_dict[source]
23
- target_lang_dict, _ = get_target_languages(source)
24
  try:
25
- target = target_lang_dict[target]
26
  # Helsinki-NLP/opus-mt-en-sq
27
  model = f"Helsinki-NLP/opus-mt-{source}-{target}"
28
  pipe = pipeline("translation", model=model)
29
  translation = pipe(input_text)
30
- return translation[0]['translation_text'], ""
31
  except KeyError:
32
  return "", f"Error: Translation direction {source_readable} to {target} is not supported by Helsinki Translation Models"
33
 
 
15
 
16
 
17
  def translate(input_text, source, target):
 
 
 
 
 
 
18
  try:
 
19
  # Helsinki-NLP/opus-mt-en-sq
20
  model = f"Helsinki-NLP/opus-mt-{source}-{target}"
21
  pipe = pipeline("translation", model=model)
22
  translation = pipe(input_text)
23
+ return translation[0]['translation_text'], input_text
24
  except KeyError:
25
  return "", f"Error: Translation direction {source_readable} to {target} is not supported by Helsinki Translation Models"
26