ipvikas commited on
Commit
3837110
1 Parent(s): 567ccb7

Upload language_translation.py

Browse files
Files changed (1) hide show
  1. language_translation.py +28 -0
language_translation.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import MBartForConditionalGeneration, MBart50Tokenizer
3
+
4
+ def download_model():
5
+ model_name = "facebook/mbart-large-50-many-to-many-mmt"
6
+ model = MBartForConditionalGeneration.from_pretrained(model_name)
7
+ tokenizer = MBart50Tokenizer.from_pretrained(model_name)
8
+ return model, tokenizer
9
+
10
+ model, tokenizer = download_model()
11
+
12
+ def Translation_demo(input_text):
13
+ model_inputs = tokenizer(input_text, return_tensors="pt")
14
+ generated_tokens = model.generate(**model_inputs,forced_bos_token_id=tokenizer.lang_code_to_id["en_XX"])
15
+ translation = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
16
+ return translation
17
+
18
+ title ='Translate the sentences'
19
+ description = "Language Translation"
20
+ examples = [
21
+ ["I am proud of being an Indian"],
22
+ ["I am happy with the performance of Indian Hockey team"],
23
+ ["We are all born with a divine fire in us. Our efforts should be to give wings to this fire”. President Kalam’s inspiring autobiography has touched the hearts of people all over the world. The book talks about the his humble beginnings in a small village in Tamil Nadu and his ascent to one of the most powerful positions in the country."]
24
+ ]
25
+
26
+ translation_demo= gr.Interface(fn=Translation_demo, inputs = 'text', outputs='text', title = title, description = description ,examples = examples)
27
+
28
+ translation_demo.launch(inline = False)