File size: 876 Bytes
19d9370
 
 
 
 
 
 
 
 
 
 
 
 
acf7fb1
03a3b02
19d9370
 
 
 
 
03a3b02
 
 
 
19d9370
 
03a3b02
19d9370
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import gradio as gr

from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline

modelcard = "amurienne/gallek-m2m100"

model = AutoModelForSeq2SeqLM.from_pretrained(modelcard)
tokenizer = AutoTokenizer.from_pretrained(modelcard)

def translate(text):
    """
    Translate the text from source lang fr to target lang br
    """
    translation_pipeline = pipeline("translation", model=model, tokenizer=tokenizer, src_lang='fr', tgt_lang='br', max_length=400, device="cpu")
    result = translation_pipeline("traduis de français en breton: " + text)
    return result[0]['translation_text']

demo = gr.Interface(
    fn=translate,
    inputs=[
        gr.components.Textbox(label="French"),
    ],
    outputs=[
        gr.components.Textbox(label="Breton")
    ],
    cache_examples=False,
    title="Gallek French -> Breton Translation Demo",
)

demo.launch()