Spaces:
Sleeping
Sleeping
Commit
·
9aabe06
1
Parent(s):
c251571
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,18 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
3 |
|
|
|
|
|
|
|
4 |
|
5 |
-
translation_pipeline = pipeline("translation_en_to_fr")
|
6 |
|
7 |
def translate_gradio(input):
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
10 |
|
11 |
translate_interface = gr.Interface(fn = translate_gradio,
|
12 |
inputs="text",
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
4 |
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-ar")
|
6 |
+
model = torch.load("helsinki_fineTuned.pt")
|
7 |
+
translation_pipeline = pipeline(model)
|
8 |
|
|
|
9 |
|
10 |
def translate_gradio(input):
|
11 |
+
encode = translation_pipeline.generate(**tokenizer.prepare_seq2seq_batch(input,return_tensors='pt').to('cuda'))
|
12 |
+
text_ar = tokenizer.batch_decode(encode,skip_special_tokens=True)[0]
|
13 |
+
return text_ar
|
14 |
+
|
15 |
+
|
16 |
|
17 |
translate_interface = gr.Interface(fn = translate_gradio,
|
18 |
inputs="text",
|