arnoldramo commited on
Commit
78670f4
·
verified ·
1 Parent(s): 099a699

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -26
app.py CHANGED
@@ -2,45 +2,36 @@ import gradio as gr
2
  from transformers import pipeline
3
  import os
4
 
5
- # Connects to your specific model
6
- # If you make your model PRIVATE, ensure you add HF_TOKEN to Space Secrets!
7
- auth_token = os.environ.get("HF_TOKEN")
8
  model_id = "arnoldramo/garifuna-nllb"
9
 
10
- # Initialize translation pipeline
11
  translator = pipeline(
12
  "translation",
13
  model=model_id,
14
- token=auth_token
15
  )
 
16
 
17
- def translate_to_garifuna(message, history, source_lang):
18
- # Mapping selection to NLLB language codes
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 the model
26
- output = translator(message, src_lang=src_code, tgt_lang="cab_Latn")
27
- return output[0]['translation_text']
28
 
29
- # Create the Chat Interface
30
  demo = gr.ChatInterface(
31
- fn=translate_to_garifuna,
32
- title="Garifuna Translator",
33
- description="Type in English or Spanish to see the Garifuna translation.",
34
  additional_inputs=[
35
- gr.Dropdown(
36
- label="Source Language",
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()