Oskar van der Wal commited on
Commit
d60cab6
1 Parent(s): 1b5febc

Load the Hungarian to English MT model at startup

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -8,6 +8,9 @@ if torch.cuda.is_available():
8
  else:
9
  DEVICE = "cpu"
10
 
 
 
 
11
  def swap_pronoun(sentence):
12
  if "He" in sentence:
13
  return sentence.replace("He", "She")
@@ -19,13 +22,11 @@ def swap_pronoun(sentence):
19
  def run_counterfactual(occupation):
20
  occupation = occupation.split(" (")[0]
21
 
22
- model_name = f"Helsinki-NLP/opus-mt-hu-en"
23
-
24
  # "egy" means something like "a", but is used less frequently than in English.
25
  #source = f"Ő egy {occupation}."
26
  source = f"Ő {occupation}."
27
 
28
- model = inseq.load_model(model_name, "integrated_gradients")
29
  model.device = DEVICE
30
  target = model.generate(source)[0]
31
  #target_modified = swap_pronoun(target)
 
8
  else:
9
  DEVICE = "cpu"
10
 
11
+ # Start downloading the Hu-En model
12
+ model_hu_en = inseq.load_model("Helsinki-NLP/opus-mt-hu-en", "integrated_gradients")
13
+
14
  def swap_pronoun(sentence):
15
  if "He" in sentence:
16
  return sentence.replace("He", "She")
 
22
  def run_counterfactual(occupation):
23
  occupation = occupation.split(" (")[0]
24
 
 
 
25
  # "egy" means something like "a", but is used less frequently than in English.
26
  #source = f"Ő egy {occupation}."
27
  source = f"Ő {occupation}."
28
 
29
+ model = model_hu_en
30
  model.device = DEVICE
31
  target = model.generate(source)[0]
32
  #target_modified = swap_pronoun(target)