mbarnig commited on
Commit
bdc8f4b
1 Parent(s): 51b4b18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -27
app.py CHANGED
@@ -3,10 +3,10 @@ import torch
3
  from huggingface_hub import hf_hub_download
4
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
5
 
6
- REPO_ID_NLLB = "facebook/nllb-200-distilled-600M"
7
- REPO_ID_MARIANNMT_en = "mbarnig/MarianNMT-tatoeba-en-lb"
8
- REPO_ID_MARIANNMT_lb = "mbarnig/MarianNMT-tatoeba-lb-en"
9
- REPO_ID_T5MT5 = "mbarnig/T5-mt5-tatoeba-en-lb"
10
 
11
  my_title = "🇬🇧 Mir iwwersetzen vun an op Lëtzebuergesch ! 🇫🇷"
12
  my_description = "English-Luxembourgish machine translation (MT) demo based on 3 open-source transformer models: Facebook-NLLB, Microsoft-MarianNMT & Google-T5/mt5."
@@ -16,7 +16,7 @@ default_input = "The North Wind and the Sun were disputing which was the stronge
16
  TRANSLATION_MODELS = [
17
  "NLLB",
18
  "MarianNMT",
19
- "T5/mt5"
20
  ]
21
 
22
  TRANSLATION_DIRECTION = [
@@ -34,36 +34,20 @@ my_inputs = [
34
 
35
  my_output = gr.Textbox(lines=5, label="Translation")
36
 
37
- def customization(myModel, direc):
38
- if myModel == "NLLB":
39
- translator = pipeline("translation", model=REPO_ID_NLLB)
40
- elif myModel == "MarianNMT":
41
- if direc == "en -> lb":
42
- translator = pipeline("translation", model=REPO_ID_MARIANNMT_en)
43
- elif direc == "lb -> en":
44
- translator = pipeline("translation", model=REPO_ID_MARIANNMT_lb)
45
- else:
46
- print("Please select a Translation Direction !")
47
- elif myModel == "T5/mt5":
48
- translator = pipeline("translation", model=REPO_ID_T5MT5)
49
- # tokenizer = AutoTokenizer.from_pretrained("mbarnig/T5-mt5-taboeta-en-lb")
50
- # model = AutoModelForSeq2SeqLM.from_pretrained("mbarnig/T5-mt5-taboeta-en-lb")
51
- else:
52
- print("Please select a Translation Model !")
53
- return myModel
54
-
55
  def iwwersetz(source_text, model, direc):
56
- translator = customization(model, direc)
57
  if model == "NLLB":
58
  if direc == "en -> lb":
59
  # translation = translator("en", "lb", source_text)
60
  translation = source_text
61
  else:
62
  # translation = translator("lb", "en", source_text)
63
- translation = source_text
 
 
 
 
64
  else:
65
- # translation = translator(source_text)
66
- translation = source_text
67
  return translation
68
 
69
  demo=gr.Interface(
 
3
  from huggingface_hub import hf_hub_download
4
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
5
 
6
+ translator-nllb = pipeline("translation", model="facebook/nllb-200-distilled-600M")
7
+ translator-marion-en = pipeline("translation", model="mbarnig/MarianNMT-tatoeba-en-lb"
8
+ translator-marion-lb = pipeline("translation", model="mbarnig/MarianNMT-tatoeba-lb-en"
9
+ translate-t5-mt5 = pipeline("translation", model="mbarnig/T5-mt5-tatoeba-en-lb"
10
 
11
  my_title = "🇬🇧 Mir iwwersetzen vun an op Lëtzebuergesch ! 🇫🇷"
12
  my_description = "English-Luxembourgish machine translation (MT) demo based on 3 open-source transformer models: Facebook-NLLB, Microsoft-MarianNMT & Google-T5/mt5."
 
16
  TRANSLATION_MODELS = [
17
  "NLLB",
18
  "MarianNMT",
19
+ "T5-mt5"
20
  ]
21
 
22
  TRANSLATION_DIRECTION = [
 
34
 
35
  my_output = gr.Textbox(lines=5, label="Translation")
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  def iwwersetz(source_text, model, direc):
 
38
  if model == "NLLB":
39
  if direc == "en -> lb":
40
  # translation = translator("en", "lb", source_text)
41
  translation = source_text
42
  else:
43
  # translation = translator("lb", "en", source_text)
44
+ translation = source_text
45
+ elif model == "MarianNMT":
46
+ translation = source_text
47
+ elif model == "T5-mt5":
48
+ translation = source_text
49
  else:
50
+ translation = "Please select a Translation Model !"
 
51
  return translation
52
 
53
  demo=gr.Interface(