|
import gradio as gr |
|
from transformers import MarianMTModel, MarianTokenizer |
|
|
|
|
|
model_name = 'Helsinki-NLP/opus-mt-en-fr' |
|
tokenizer = MarianTokenizer.from_pretrained(model_name) |
|
model = MarianMTModel.from_pretrained(model_name) |
|
|
|
|
|
def translate(text): |
|
|
|
model_inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True) |
|
|
|
|
|
gen = model.generate(**model_inputs) |
|
|
|
|
|
translation = tokenizer.batch_decode(gen, skip_special_tokens=True) |
|
return translation[0] |
|
|
|
|
|
iface = gr.Interface( |
|
fn=translate, |
|
inputs=gr.Textbox(lines=2, placeholder="Enter Text in English..."), |
|
outputs=gr.Textbox() |
|
) |
|
|
|
|
|
iface.launch(debug=True,inline=False) |
|
|