Spaces:
Sleeping
Sleeping
Commit
·
a3a6ba7
1
Parent(s):
409361e
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast,MBartTokenizerFast,MBart50Tokenizer
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
from transformers import MBartTokenizer,MBartForConditionalGeneration, MBartConfig
|
| 6 |
+
model = MBartForConditionalGeneration.from_pretrained("facebook/mbart-large-50-one-to-many-mmt")
|
| 7 |
+
tokenizer = MBart50TokenizerFast.from_pretrained("facebook/mbart-large-50-one-to-many-mmt",src_lang="en_XX")
|
| 8 |
+
|
| 9 |
+
def get_input(text):
|
| 10 |
+
models_input = tokenizer(text,return_tensors="pt")
|
| 11 |
+
generated_tokens = model.generate(**models_input,forced_bos_token_id=tokenizer.lang_code_to_id["ml_IN"])
|
| 12 |
+
translation = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
|
| 13 |
+
return translation
|
| 14 |
+
|
| 15 |
+
iface = gr.Interface(fn=get_input,inputs="text",outputs="text", title = "English to Tamil Translator",description="Get Tamil translation for your text in English")
|
| 16 |
+
|
| 17 |
+
iface.launch(
|