File size: 1,347 Bytes
ed948a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9aebc37
ed948a9
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
import gradio as gr
from transformers import pipeline
import joblib
#importer la liste des langues
languages = joblib.load('languages.joblib')

# Fonction de traduction
def translate_text(text, model_choice, src_lang, tgt_lang):
    if model_choice == "NLLB-200 (facebook)":
        nllb_translator = pipeline("translation", model="facebook/nllb-200-distilled-600M", src_lang=src_lang, tgt_lang=tgt_lang)
        result = nllb_translator(text)[0]["translation_text"]
    elif model_choice == "Opus-MT-EN-FR (Helsinki-NLP)":
        en_fr_translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-fr")
        result = en_fr_translator(text)[0]["translation_text"]
    else:
        result = fr_en_translator(text)[0]["translation_text"]
    return result

# Interface Gradio
demo = gr.Interface(
    fn=translate_text,
    inputs=[
        gr.Textbox(label="Texte à traduire", placeholder="Entrez du texte en français ici..."),
        gr.Radio(["NLLB-200 (facebook)", "Opus-MT-EN-FR (Helsinki-NLP)", "Opus-MT-FR-EN (Helsinki-NLP)"], label="Choisissez le modèle"),
        gr.Dropdown(choices = languages, label = 'Tource Tanguage'),
        gr.Dropdown(choices = languages, label = 'Target Tanguage')],
    outputs=gr.Textbox(label="Texte traduit"),
    title="Traduction dans plusieurs langues",
    theme='shivi/calm_seafoam')