Martin van Dijk
commited on
Commit
·
ddc258f
1
Parent(s):
bbad4ca
Initial commit
Browse files
app.py
CHANGED
@@ -1,13 +1,22 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
model = pipeline("translation", model="vonjack/opus-mt-mul-en-big")
|
4 |
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
def
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
|
|
11 |
|
12 |
-
|
|
|
13 |
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import MarianMTModel, MarianTokenizer
|
|
|
3 |
|
4 |
+
# Load the model and tokenizer
|
5 |
+
model_name = "Helsinki-NLP/opus-mt-nl-en"
|
6 |
+
tokenizer = MarianTokenizer.from_pretrained(model_name)
|
7 |
+
model = MarianMTModel.from_pretrained(model_name)
|
8 |
|
9 |
+
def translate(text):
|
10 |
+
# Tokenize input text
|
11 |
+
tokenized_text = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
|
12 |
+
# Perform translation
|
13 |
+
translated = model.generate(**tokenized_text)
|
14 |
+
# Decode translated text
|
15 |
+
return tokenizer.decode(translated[0], skip_special_tokens=True)
|
16 |
|
17 |
+
# Define Gradio interface
|
18 |
+
interface = gr.Interface(fn=translate, inputs="text", outputs="text", title="Dutch to English Translator", description="Translate Dutch text to English using Helsinki-NLP/opus-mt-nl-en.")
|
19 |
|
20 |
+
# Launch the interface
|
21 |
+
interface.launch()
|
22 |
|