Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
from huggingface_hub import hf_hub_download
|
| 4 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
| 5 |
|
|
@@ -8,8 +8,6 @@ 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 |
-
translator = pipeline("translation", model=REPO_ID_NLLB)
|
| 12 |
-
|
| 13 |
my_title = "🇬🇧 Mir iwwersetzen vun an op Lëtzebuergesch ! 🇫🇷"
|
| 14 |
my_description = "English-Luxembourgish machine translation (MT) demo based on 3 open-source transformer models: Facebook-NLLB, Microsoft-MarianNMT & Google-T5/mt5."
|
| 15 |
my_article = "<h3>User guide</h3><p>1. Press the submit button to translate an english text with the default values. 2. Compare the result with the luxembourgish example. 3. Select a model and a translation direction and enter your own text. Have fun !</p><p>Go to <a href='https://www.web3.lu/'>Internet with a Brain</a> to read my french publication <a href='https://www.web3.lu/'>Das Küsschen und die Sonne stritten sich ...</a> about the history of machine translation in Luxembourg from 1975 until today.</p>"
|
|
@@ -36,8 +34,31 @@ my_inputs = [
|
|
| 36 |
|
| 37 |
my_output = gr.Textbox(lines=5, label="Translation")
|
| 38 |
|
| 39 |
-
def
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
return translation
|
| 42 |
|
| 43 |
demo=gr.Interface(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
from huggingface_hub import hf_hub_download
|
| 4 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
| 5 |
|
|
|
|
| 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."
|
| 13 |
my_article = "<h3>User guide</h3><p>1. Press the submit button to translate an english text with the default values. 2. Compare the result with the luxembourgish example. 3. Select a model and a translation direction and enter your own text. Have fun !</p><p>Go to <a href='https://www.web3.lu/'>Internet with a Brain</a> to read my french publication <a href='https://www.web3.lu/'>Das Küsschen und die Sonne stritten sich ...</a> about the history of machine translation in Luxembourg from 1975 until today.</p>"
|
|
|
|
| 34 |
|
| 35 |
my_output = gr.Textbox(lines=5, label="Translation")
|
| 36 |
|
| 37 |
+
def customization(model, direc):
|
| 38 |
+
if model == "NLLB":
|
| 39 |
+
translator = pipeline("translation", model=REPO_ID_NLLB)
|
| 40 |
+
elif model == "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 model == "T5/mt5":
|
| 48 |
+
translator = pipeline("translation", model=REPO_ID_T5MT5)
|
| 49 |
+
else:
|
| 50 |
+
print("Please select a Translation Model !")
|
| 51 |
+
return translator
|
| 52 |
+
|
| 53 |
+
def iwwersetz(source_text, model, direc):
|
| 54 |
+
translator = customization(model, direc)
|
| 55 |
+
if model == "NLLB":
|
| 56 |
+
if direc == "en -> lb":
|
| 57 |
+
translation = translator("en", "lb", source_text)
|
| 58 |
+
else:
|
| 59 |
+
translation = translator("lb", "en", source_text)
|
| 60 |
+
else:
|
| 61 |
+
translation = translator(source_text)
|
| 62 |
return translation
|
| 63 |
|
| 64 |
demo=gr.Interface(
|