Bildad commited on
Commit
4729673
·
verified ·
1 Parent(s): 0d6652c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -13,6 +13,10 @@ class UnifiedTranslator:
13
  self.model = pipeline("translation", model=model_name)
14
  self.phrase_mapping = phrase_mapping
15
 
 
 
 
 
16
  def translate(self, text):
17
  # Normalize text to lowercase and strip extra spaces
18
  text_lower = text.lower().strip()
@@ -32,9 +36,14 @@ class UnifiedTranslator:
32
  match = pattern_regex.fullmatch(text_lower)
33
  if match:
34
  print(f"Match found: {match.group(0)}")
35
- # Replace the placeholder with the actual value if needed
36
  if '{name}' in pattern:
37
- return translation.format(name=match.group(1))
 
 
 
 
 
38
  else:
39
  return translation
40
  except re.error as e:
 
13
  self.model = pipeline("translation", model=model_name)
14
  self.phrase_mapping = phrase_mapping
15
 
16
+ def is_name(self, word):
17
+ # A simple heuristic: a word is considered a name if it starts with an uppercase letter
18
+ return word[0].isupper()
19
+
20
  def translate(self, text):
21
  # Normalize text to lowercase and strip extra spaces
22
  text_lower = text.lower().strip()
 
36
  match = pattern_regex.fullmatch(text_lower)
37
  if match:
38
  print(f"Match found: {match.group(0)}")
39
+ # Replace the placeholder with the actual value if it's a name
40
  if '{name}' in pattern:
41
+ name = match.group(1)
42
+ if self.is_name(name):
43
+ return translation.format(name=name)
44
+ else:
45
+ # If the matched word isn't a name, use it directly in the translation
46
+ return translation.replace('{name}', name)
47
  else:
48
  return translation
49
  except re.error as e: