Spaces:
Runtime error
Runtime error
Create app.py
Browse files
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 |
+
|
| 7 |
+
# Fonction de traduction
|
| 8 |
+
def translate_text(text, model_choice, src_lang, tgt_lang):
|
| 9 |
+
if model_choice == "NLLB-200 (facebook)":
|
| 10 |
+
nllb_translator = pipeline("translation", model="facebook/nllb-200-distilled-600M", src_lang=src_lang, tgt_lang=tgt_lang)
|
| 11 |
+
result = nllb_translator(text)[0]["translation_text"]
|
| 12 |
+
elif model_choice == "Opus-MT-EN-FR (Helsinki-NLP)":
|
| 13 |
+
en_fr_translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-fr")
|
| 14 |
+
result = en_fr_translator(text)[0]["translation_text"]
|
| 15 |
+
else:
|
| 16 |
+
result = fr_en_translator(text)[0]["translation_text"]
|
| 17 |
+
return result
|
| 18 |
+
|
| 19 |
+
# Interface Gradio
|
| 20 |
+
demo = gr.Interface(
|
| 21 |
+
fn=translate_text,
|
| 22 |
+
inputs=[
|
| 23 |
+
gr.Textbox(label="Texte à traduire", placeholder="Entrez du texte en français ici..."),
|
| 24 |
+
gr.Radio(["NLLB-200 (facebook)", "Opus-MT-EN-FR (Helsinki-NLP)", "Opus-MT-FR-EN (Helsinki-NLP)"], label="Choisissez le modèle"),
|
| 25 |
+
gr.Dropdown(choices = languages, label = 'Tource Tanguage'),
|
| 26 |
+
gr.Dropdown(choices = languages, label = 'Target Tanguage')],
|
| 27 |
+
outputs=gr.Textbox(label="Texte traduit"),
|
| 28 |
+
title="Traduction dans plusieurs langues",
|
| 29 |
+
theme='shivi/calm_seafoam'
|
| 30 |
+
|