sophicist commited on
Commit
e6d08d8
·
1 Parent(s): f9dc2c1
Files changed (2) hide show
  1. app.py +31 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import MBart50TokenizerFast, MBartForConditionalGeneration
3
+
4
+ # Load the model and tokenizer from Hugging Face Hub
5
+ model_name = "Aesopskenya/GikuyuToEnglishTranslator"
6
+ tokenizer = MBart50TokenizerFast.from_pretrained(model_name)
7
+ model = MBartForConditionalGeneration.from_pretrained(model_name)
8
+
9
+ def translate_gikuyu(sentence):
10
+ # Tokenize input
11
+ inputs = tokenizer(sentence, return_tensors="pt", truncation=True, padding=True, max_length=128)
12
+
13
+ # Generate translation
14
+ outputs = model.generate(inputs.input_ids, max_length=128)
15
+
16
+ # Decode output
17
+ translation = tokenizer.decode(outputs[0], skip_special_tokens=True)
18
+ return translation
19
+
20
+ # Define Gradio interface
21
+ iface = gr.Interface(
22
+ fn=translate_gikuyu,
23
+ inputs="text",
24
+ outputs="text",
25
+ title="Gikuyu-English Translator",
26
+ description="Enter a Gikuyu sentence, and the model will translate it into English."
27
+ )
28
+
29
+ # Launch the interface
30
+ if __name__ == "__main__":
31
+ iface.launch(server_name="0.0.0.0", server_port=7860)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers
2
+ gradio
3
+ torch
4
+ python-dotenv