ntam0001 commited on
Commit
f64ea65
1 Parent(s): 9095e52

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # KINYARWANDA TO ENGLISH
2
+ import gradio as gr
3
+ from transformers import MarianMTModel, MarianTokenizer
4
+
5
+ # Suppose you found a model 'Helsinki-NLP/opus-mt-rw-en' that translates from Kinyarwanda to English
6
+ model_name = 'Helsinki-NLP/opus-mt-rw-en'
7
+ tokenizer = MarianTokenizer.from_pretrained(model_name)
8
+ model = MarianMTModel.from_pretrained(model_name)
9
+
10
+ # Function to translate text from Kinyarwanda to English
11
+ def translate(text):
12
+ # Tokenize the text using the __call__ method
13
+ model_inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
14
+
15
+ # Perform the translation
16
+ gen = model.generate(**model_inputs)
17
+
18
+ # Decode the generated tokens to string
19
+ translation = tokenizer.batch_decode(gen, skip_special_tokens=True)
20
+ return translation[0]
21
+
22
+ # Create a Gradio interface
23
+ iface = gr.Interface(
24
+ fn=translate,
25
+ inputs=gr.Textbox(lines=2, placeholder="Enter Text in Kinyarwanda..."),
26
+ outputs=gr.Textbox()
27
+ )
28
+
29
+ # Launch the interface
30
+ iface.launch(debug=True,inline=False)