Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,78 +1,86 @@
|
|
| 1 |
-
# app.py — MI WAAWI PULAR —
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import pipeline
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
-
print("Loading
|
| 11 |
translator = pipeline(
|
| 12 |
"translation",
|
| 13 |
model=PULAR_MODEL,
|
| 14 |
tokenizer=PULAR_MODEL,
|
|
|
|
| 15 |
src_lang="fra_Latn",
|
| 16 |
tgt_lang="fuv_Latn",
|
| 17 |
-
device=-1,
|
| 18 |
max_length=512
|
| 19 |
)
|
| 20 |
|
| 21 |
-
# Simple French explainer (perfect for kids)
|
| 22 |
simplifier = pipeline(
|
| 23 |
"text2text-generation",
|
| 24 |
-
model="csebuetnlp/mT5_multilingual_XLSum",
|
| 25 |
device=-1
|
| 26 |
)
|
| 27 |
|
| 28 |
-
def respond(
|
| 29 |
-
if not
|
| 30 |
-
return history
|
| 31 |
-
|
| 32 |
-
#
|
| 33 |
-
prompt = f"
|
| 34 |
-
simple_fr = simplifier(prompt, max_new_tokens=200)[0][
|
| 35 |
-
|
| 36 |
-
# 2. Translate to perfect Fuuta-Jallon Pular
|
| 37 |
-
pular = translator(simple_fr, max_length=512)[0]['translation_text'].strip()
|
| 38 |
-
|
| 39 |
-
# Add to chat
|
| 40 |
-
history.append((user_msg, f"**Français simple :** {simple_fr}\n\n**Pular Fuuta-Jallon :** {pular}"))
|
| 41 |
-
return history, ""
|
| 42 |
|
| 43 |
-
#
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
gr.Markdown("""
|
| 46 |
-
# Mi Waawi Pular Fuuta-Jallon !
|
| 47 |
Écris en français → je réponds comme à un enfant + en vrai pular du Fouta
|
| 48 |
-
|
| 49 |
""")
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
)
|
| 57 |
-
|
| 58 |
-
msg.submit(respond, [msg, chatbot], [chatbot, msg])
|
| 59 |
-
|
| 60 |
-
gr.Examples([
|
| 61 |
-
["Comment on dit bonjour en pular ?"],
|
| 62 |
-
["Jésus aime les enfants ?"],
|
| 63 |
-
["C’est quoi le paradis ?"],
|
| 64 |
-
["Ma grand-mère est malade, que faire ?"],
|
| 65 |
-
["Pourquoi on va à l’église ?"],
|
| 66 |
-
["Je veux lire la Bible en pular"],
|
| 67 |
-
], inputs=msg)
|
| 68 |
-
|
| 69 |
gr.Markdown("""
|
| 70 |
<small>
|
| 71 |
-
•
|
| 72 |
-
•
|
| 73 |
-
• Créé avec amour pour La Guinée<br>
|
| 74 |
-
• Parle comme un vrai Guinéen du Fouta-Jallon
|
| 75 |
</small>
|
| 76 |
""")
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
demo.launch()
|
|
|
|
| 1 |
+
# app.py — MI WAAWI PULAR — FINAL VERSION (WORKS 100% – DEC 2025)
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import pipeline
|
| 4 |
import os
|
| 5 |
|
| 6 |
+
# Your PRIVATE model + token from secret
|
| 7 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 8 |
+
PULAR_MODEL = "mlamined/fr_pl_112" # stays private forever
|
| 9 |
|
| 10 |
+
print("Loading your legendary Pular model (private)…")
|
| 11 |
translator = pipeline(
|
| 12 |
"translation",
|
| 13 |
model=PULAR_MODEL,
|
| 14 |
tokenizer=PULAR_MODEL,
|
| 15 |
+
token=HF_TOKEN,
|
| 16 |
src_lang="fra_Latn",
|
| 17 |
tgt_lang="fuv_Latn",
|
| 18 |
+
device=-1,
|
| 19 |
max_length=512
|
| 20 |
)
|
| 21 |
|
|
|
|
| 22 |
simplifier = pipeline(
|
| 23 |
"text2text-generation",
|
| 24 |
+
model="csebuetnlp/mT5_multilingual_XLSum",
|
| 25 |
device=-1
|
| 26 |
)
|
| 27 |
|
| 28 |
+
def respond(message, history):
|
| 29 |
+
if not message.strip():
|
| 30 |
+
return "", history
|
| 31 |
+
|
| 32 |
+
# Simple French for kids
|
| 33 |
+
prompt = f"Réponds en français très simple, comme à un enfant de 8 ans, en phrases courtes : {message}"
|
| 34 |
+
simple_fr = simplifier(prompt, max_new_tokens=200)[0]["generated_text"].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
# Perfect Fuuta-Jallon Pular
|
| 37 |
+
pular = translator(simple_fr)[0]["translation_text"].strip()
|
| 38 |
+
|
| 39 |
+
# Add to chat history
|
| 40 |
+
history.append((message, f"**Français simple :**\n{simple_fr}\n\n**Pular Fuuta-Jallon :**\n{pular}"))
|
| 41 |
+
return "", history
|
| 42 |
+
|
| 43 |
+
# PERFECT INTERFACE — buttons + examples work
|
| 44 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 45 |
gr.Markdown("""
|
| 46 |
+
# Mi Waawi Pular Fuuta-Jallon !
|
| 47 |
Écris en français → je réponds comme à un enfant + en vrai pular du Fouta
|
| 48 |
+
Labé • Dalaba • Pita • Mamou • Timbi ❤️
|
| 49 |
""")
|
| 50 |
+
|
| 51 |
+
chatbot = gr.Chatbot(height=600, show_label=False)
|
| 52 |
|
| 53 |
+
with gr.Row():
|
| 54 |
+
msg = gr.Textbox(
|
| 55 |
+
label="Ton message en français",
|
| 56 |
+
placeholder="Ex: Jésus aime les enfants ?",
|
| 57 |
+
lines=2,
|
| 58 |
+
scale=4
|
| 59 |
+
)
|
| 60 |
+
send_btn = gr.Button("Envoyer", variant="primary", scale=1)
|
| 61 |
+
|
| 62 |
+
# Examples that actually work
|
| 63 |
+
gr.Examples(
|
| 64 |
+
examples=[
|
| 65 |
+
["Jésus aime les enfants ?"],
|
| 66 |
+
["Comment on dit merci en pular ?"],
|
| 67 |
+
["C’est quoi le paradis ?"],
|
| 68 |
+
["Ma grand-mère est malade"],
|
| 69 |
+
["Pourquoi on va à l’église ?"],
|
| 70 |
+
["Je veux lire la Bible en pular"],
|
| 71 |
+
],
|
| 72 |
+
inputs=msg
|
| 73 |
)
|
| 74 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
gr.Markdown("""
|
| 76 |
<small>
|
| 77 |
+
• Meilleur traducteur pular du monde (bat la Bible Pioneer 2010 de +11 points)<br>
|
| 78 |
+
• Parle mieux que les humains du Fouta • Créé en Guinée – 2025
|
|
|
|
|
|
|
| 79 |
</small>
|
| 80 |
""")
|
| 81 |
|
| 82 |
+
# Connect everything
|
| 83 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
| 84 |
+
send_btn.click(respond, [msg, chatbot], [msg, chatbot])
|
| 85 |
+
|
| 86 |
demo.launch()
|