Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,45 +2,36 @@ import gradio as gr
|
|
| 2 |
from transformers import pipeline
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
auth_token = os.environ.get("HF_TOKEN")
|
| 8 |
model_id = "arnoldramo/garifuna-nllb"
|
| 9 |
|
| 10 |
-
|
| 11 |
translator = pipeline(
|
| 12 |
"translation",
|
| 13 |
model=model_id,
|
| 14 |
-
token=
|
| 15 |
)
|
|
|
|
| 16 |
|
| 17 |
-
def
|
| 18 |
-
|
| 19 |
-
lang_map = {
|
| 20 |
-
"English": "eng_Latn",
|
| 21 |
-
"Spanish": "spa_Latn"
|
| 22 |
-
}
|
| 23 |
src_code = lang_map.get(source_lang, "eng_Latn")
|
| 24 |
|
| 25 |
-
# Run
|
| 26 |
-
|
| 27 |
-
return
|
| 28 |
|
| 29 |
-
#
|
| 30 |
demo = gr.ChatInterface(
|
| 31 |
-
fn=
|
| 32 |
-
title="Garifuna
|
| 33 |
-
description="
|
| 34 |
additional_inputs=[
|
| 35 |
-
gr.Dropdown(
|
| 36 |
-
|
| 37 |
-
choices=["English", "Spanish"],
|
| 38 |
-
value="English" # English is default
|
| 39 |
-
)
|
| 40 |
-
],
|
| 41 |
-
examples=[["Hello, how are you?", "English"], ["Buenos días", "Spanish"]],
|
| 42 |
-
theme=gr.themes.Soft()
|
| 43 |
)
|
| 44 |
|
| 45 |
if __name__ == "__main__":
|
|
|
|
| 46 |
demo.launch()
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# 1. Load token and model
|
| 6 |
+
hf_token = os.environ.get("HF_TOKEN")
|
|
|
|
| 7 |
model_id = "arnoldramo/garifuna-nllb"
|
| 8 |
|
| 9 |
+
print("Loading pipeline...")
|
| 10 |
translator = pipeline(
|
| 11 |
"translation",
|
| 12 |
model=model_id,
|
| 13 |
+
token=hf_token
|
| 14 |
)
|
| 15 |
+
print("Pipeline loaded successfully!")
|
| 16 |
|
| 17 |
+
def respond(message, history, source_lang):
|
| 18 |
+
lang_map = {"English": "eng_Latn", "Spanish": "spa_Latn"}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
src_code = lang_map.get(source_lang, "eng_Latn")
|
| 20 |
|
| 21 |
+
# Run translation
|
| 22 |
+
result = translator(message, src_lang=src_code, tgt_lang="cab_Latn")
|
| 23 |
+
return result[0]['translation_text']
|
| 24 |
|
| 25 |
+
# 2. Corrected Interface (Fixes the theme error)
|
| 26 |
demo = gr.ChatInterface(
|
| 27 |
+
fn=respond,
|
| 28 |
+
title="Garifuna Language Assistant",
|
| 29 |
+
description="Translate English or Spanish to Garifuna.",
|
| 30 |
additional_inputs=[
|
| 31 |
+
gr.Dropdown(label="Source Language", choices=["English", "Spanish"], value="English")
|
| 32 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
)
|
| 34 |
|
| 35 |
if __name__ == "__main__":
|
| 36 |
+
# We apply the theme here or leave it default to ensure it boots
|
| 37 |
demo.launch()
|