File size: 2,661 Bytes
85eb15f
86fc274
 
 
3a45642
86fc274
 
 
85eb15f
 
868a628
 
 
 
 
 
 
 
85eb15f
 
868a628
ece2403
3d9bc3d
ece2403
3d9bc3d
 
 
 
 
ece2403
 
3d9bc3d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ece2403
 
 
 
 
85eb15f
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
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
    gr.Markdown("""
    <div style="text-align: center;">
        <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>Oyo e za version ya komeka pe to zo talela bino pôna ko kolisa makoki ya modeli pôna nkota nà biso Lingala.</p>
    </div>
    """)

    # Création du formulaire centré dans un conteneur avec un contour
    with gr.Box(elem_id="form-container"):
        with gr.Row(variant="panel", align="center"):
            text_input = gr.Textbox(label="Entrez le texte à traduire", placeholder="Entrez le texte à traduire ici...", lines=3)

        with gr.Row(variant="panel", align="center"):
            source_lang = gr.Dropdown(choices=["fr", "li"], label="Langue Source")
            target_lang = gr.Dropdown(choices=["li", "fr"], label="Langue Cible")

        with gr.Row(variant="panel", align="center"):
            translate_button = gr.Button("Traduire")
        
        with gr.Row(variant="panel", align="center"):
            translation_output = gr.Textbox(label="Traduction", placeholder="Le texte traduit s'affichera ici...")

    # Lancer la traduction avec le bouton
    translate_button.click(
        translate_text, 
        inputs=[text_input, source_lang, target_lang], 
        outputs=translation_output
    )

# Personnalisation CSS pour la boîte et l'alignement
interface.css = """
    #form-container {
        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);
    }
    #form-container .row {
        margin-bottom: 15px;
    }
    #form-container .button {
        width: 100%;
    }
"""

# Lancer l'interface
interface.launch()