ZubairAhmed777 commited on
Commit
5e22169
·
verified ·
1 Parent(s): 57ac983

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +27 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import MBartForConditionalGeneration, MBart50TokenizerFast
2
+ import gradio as gr
3
+
4
+ # Load the tokenizer and model
5
+ model_checkpoint = "aryaumesh/english-to-telugu"
6
+ tokenizer = MBart50TokenizerFast.from_pretrained(model_checkpoint)
7
+ model = MBartForConditionalGeneration.from_pretrained(model_checkpoint)
8
+
9
+ # Function to translate text
10
+ def translate_to_telugu(text):
11
+ inputs = tokenizer(text, return_tensors="pt")
12
+ outputs = model.generate(**inputs)
13
+ translation = tokenizer.decode(outputs[0], skip_special_tokens=True)
14
+ return translation
15
+
16
+ # Create a Gradio interface
17
+ iface = gr.Interface(
18
+ fn=translate_to_telugu,
19
+ inputs=gr.Textbox(lines=2, placeholder="Enter text in English..."), # Text input
20
+ outputs=gr.Textbox(label="Translation to Telugu"), # Text output
21
+ title="English to Telugu Translator",
22
+ description="Translate text from English to Telugu using an MBart model."
23
+ )
24
+
25
+ # Launch the Gradio interface
26
+ iface.launch()
27
+
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ transformers
2
+ gradio