Spaces:
Sleeping
Sleeping
Commit
·
432cf37
1
Parent(s):
3db4873
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,35 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast,MBartTokenizerFast,MBart50Tokenizer
|
3 |
|
|
|
4 |
|
5 |
-
|
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
|
10 |
-
|
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(
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
+
from transformers import pipeline
|
4 |
|
5 |
+
pipe = pipeline("translation", model="t5-base")
|
|
|
|
|
6 |
|
7 |
+
def predict(text):
|
8 |
+
return pipe(text)[0]["translation_text"]
|
|
|
|
|
|
|
9 |
|
10 |
+
iface = gr.Interface(
|
11 |
+
fn=predict,
|
12 |
+
inputs=[gr.inputs.Textbox(label="text", lines=3)],
|
13 |
+
outputs='text',
|
14 |
+
examples=[["Hello! My name is Rajesh"], ["How are you?"]]
|
15 |
+
)
|
16 |
|
17 |
+
iface.launch()
|
18 |
+
|
19 |
+
# import gradio as gr
|
20 |
+
# from transformers import MBartForConditionalGeneration, MBart50TokenizerFast,MBartTokenizerFast,MBart50Tokenizer
|
21 |
+
|
22 |
+
|
23 |
+
# from transformers import MBartTokenizer,MBartForConditionalGeneration, MBartConfig
|
24 |
+
# model = MBartForConditionalGeneration.from_pretrained("facebook/mbart-large-50-one-to-many-mmt")
|
25 |
+
# tokenizer = MBart50TokenizerFast.from_pretrained("facebook/mbart-large-50-one-to-many-mmt",src_lang="en_XX")
|
26 |
+
|
27 |
+
# def get_input(text):
|
28 |
+
# models_input = tokenizer(text,return_tensors="pt")
|
29 |
+
# generated_tokens = model.generate(**models_input,forced_bos_token_id=tokenizer.lang_code_to_id["ml_IN"])
|
30 |
+
# translation = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
|
31 |
+
# return translation
|
32 |
+
|
33 |
+
# iface = gr.Interface(fn=get_input,inputs="text",outputs="text", title = "English to Malayalam Translator",description="Get Malayalam translation for your text in English")
|
34 |
+
|
35 |
+
# iface.launch()
|