arnoldramo commited on
Commit
099a699
·
verified ·
1 Parent(s): 8c8dd41

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 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()