Adracamara94 commited on
Commit
f3d941a
·
verified ·
1 Parent(s): 25ba6bf

Create app-py

Browse files
Files changed (1) hide show
  1. app-py +33 -0
app-py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Chargement des pipelines
5
+ fr_en_nllb_translator = pipeline("translation", model="facebook/nllb-200-distilled-600M", src_lang="fra_Latn", tgt_lang="eng_Latn")
6
+ en_fr_nllb_translator = pipeline("translation", model="facebook/nllb-200-distilled-600M", src_lang="eng_Latn", tgt_lang="fra_Latn")
7
+ en_fr_translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-fr")
8
+ fr_en_translator = pipeline("translation", model="Helsinki-NLP/opus-mt-fr-en")
9
+ # Fonction de traduction
10
+ def translate_text(text, model_choice):
11
+ if model_choice == "NLLB-200-FR-EN (facebook)":
12
+ result = fr_en_nllb_translator(text.strip())[0]["translation_text"]
13
+ elif model_choice == "NLLB-200-EN-FR (facebook)":
14
+ result = en_fr_nllb_translator(text.strip())[0]["translation_text"]
15
+ elif model_choice == "Opus-MT-EN-FR (Helsinki-NLP)":
16
+ result = en_fr_translator(text.strip())[0]["translation_text"]
17
+ else:
18
+ result = fr_en_translator(text.strip())[0]["translation_text"]
19
+ return result
20
+
21
+ # Interface Gradio
22
+ demo = gr.Interface(
23
+ fn=translate_text,
24
+ inputs=[
25
+ gr.Textbox(label="Texte à traduire", placeholder="Entrez du texte en français ici..."),
26
+ gr.Radio(["NLLB-200-FR-EN (facebook)", "NLLB-200-EN-FR (facebook)",
27
+ "Opus-MT-FR-EN (Helsinki-NLP)","Opus-MT-EN-FR (Helsinki-NLP)"], label="Choisissez le modèle")
28
+ ],
29
+ outputs=gr.Textbox(label="Texte traduit"),
30
+ title="Traduction FR-EN & EN-FR"
31
+ )
32
+
33
+ demo.launch()