File size: 3,419 Bytes
85eb15f
86fc274
 
 
3a45642
86fc274
 
 
85eb15f
 
868a628
 
 
 
 
 
 
 
85eb15f
 
868a628
ece2403
0d0cc20
ece2403
0d0cc20
3d9bc3d
 
0d0cc20
3d9bc3d
ece2403
 
37dc90d
 
0d0cc20
 
 
 
 
3d9bc3d
0d0cc20
ece2403
 
 
 
 
85eb15f
0d0cc20
3d9bc3d
0d0cc20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37dc90d
0d0cc20
3d9bc3d
 
 
 
 
 
 
 
37dc90d
 
 
 
 
 
 
 
 
 
 
3d9bc3d
 
868a628
85eb15f
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import gradio as gr
from transformers import MarianMTModel, MarianTokenizer

# Charger le modèle et le tokenizer depuis Hugging Face
model_name = "MrFrijo/LiAPI"  # Nom du modèle sur Hugging Face

model = MarianMTModel.from_pretrained(model_name)
tokenizer = MarianTokenizer.from_pretrained(model_name)

def translate_text(text, src_lang, target_lang):
    # Préparer les entrées pour le modèle
    tokenized_text = tokenizer(text, return_tensors="pt")

    # Effectuer la traduction
    translated = model.generate(**tokenized_text)

    # Convertir et retourner le texte traduit
    translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
    return translated_text

# Créer l'interface Gradio
with gr.Blocks() as interface:
    # Titre et description avec du texte en italique et en gras en lingala
    gr.Markdown("""
    <div style="text-align: center; font-family: 'Lobster', sans-serif;">
        <h2>Traduction automatique Lingala-Français</h2>
        <p>Ceci est la version d'essai et nous comptons sur vous pour améliorer les performances du modèle pour notre langue Lingala.</p>
        <p><strong><em>Oyo e za version ya komeka pe to zo talela bino pôna ko kolisa makoki ya modeli pôna nkota nà biso Lingala.</em></strong></p>
    </div>
    """)

    # Créer une colonne sans l'argument `align` qui n'existe pas
    with gr.Column():
        text_input = gr.Textbox(label="Entrez le texte à traduire", placeholder="Entrez le texte à traduire ici...", lines=3)
        source_lang = gr.Dropdown(choices=["fr", "li"], label="Langue Source")
        target_lang = gr.Dropdown(choices=["li", "fr"], label="Langue Cible")
        translate_button = gr.Button("Traduire")
        translation_output = gr.Textbox(label="Traduction", placeholder="Le texte traduit s'affichera ici...")

    # Lier le bouton au processus de traduction
    translate_button.click(
        translate_text, 
        inputs=[text_input, source_lang, target_lang], 
        outputs=translation_output
    )

# Personnalisation CSS pour la boîte et les textes
interface.css = """
    /* Police personnalisée pour rendre l'interface plus attrayante */
    @import url('https://fonts.googleapis.com/css2?family=Lobster&display=swap');
    
    .gradio-container {
        font-family: 'Arial', sans-serif;
    }
    .gradio-button {
        background-color: #4CAF50;
        color: white;
        border-radius: 5px;
        border: none;
    }
    .gradio-button:hover {
        background-color: #45a049;
    }
    .gr-markdown {
        font-family: 'Lobster', sans-serif;
        font-size: 24px;
        font-weight: bold;
    }
    .gradio-row {
        margin-top: 10px;
    }
    /* Centrer la colonne et ajouter un style à la zone de texte */
    .gr-column {
        width: 50%;
        margin: auto;
        padding: 20px;
        border: 2px solid #ddd;
        border-radius: 10px;
        background-color: #f9f9f9;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    }
    /* Appliquer un style pour le texte d'entrée */
    .gr-textbox {
        font-size: 16px;
        padding: 10px;
    }
    /* Appliquer un style pour la sortie de traduction */
    .gr-textbox[placeholder='Le texte traduit s\'affichera ici...'] {
        font-size: 16px;
        font-weight: bold;
        color: #2E8B57; /* Couleur verte pour l'output */
    }
"""

# Lancer l'interface
interface.launch()