MaroneAI commited on
Commit
a6b34c6
·
verified ·
1 Parent(s): d03072c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
+ import torch
4
+
5
+ # Charger le modèle et le tokenizer
6
+ model_name = "MaroneAI/Niani-nllb-Wolof-To-Frensh-615M"
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
9
+ device = "cuda" if torch.cuda.is_available() else "cpu"
10
+ model = model.to(device)
11
+
12
+ # Fonction de traduction
13
+ def translate_wolof_to_french(text):
14
+ if not text.strip():
15
+ return "Écris une phrase en Wolof."
16
+ inputs = tokenizer(text, return_tensors="pt").to(device)
17
+ with torch.no_grad():
18
+ outputs = model.generate(
19
+ **inputs,
20
+ max_length=128,
21
+ num_beams=4,
22
+ early_stopping=True
23
+ )
24
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
25
+
26
+ # Interface Gradio
27
+ iface = gr.Interface(
28
+ fn=translate_wolof_to_french,
29
+ inputs=gr.Textbox(lines=3, placeholder="Écris ici ta phrase en Wolof...", label="Texte en Wolof"),
30
+ outputs=gr.Textbox(label="Traduction en Français"),
31
+ title="Traduction Wolof → Français",
32
+ description="Modèle fine-tuné basé sur facebook/nllb-200-distilled-600M.",
33
+ examples=[
34
+ ["Naka nga def?"],
35
+ ["Jërëjëf ci sa jàmm."],
36
+ ["Ba beneen yoon."],
37
+ ["Kii mooy sama xarit."]
38
+ ]
39
+ )
40
+
41
+ iface.launch()