Dougaya commited on
Commit
aca8383
·
verified ·
1 Parent(s): 7f5c763

Create app.py

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