muhammadayman commited on
Commit
6332492
·
1 Parent(s): ca48067

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py CHANGED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ import gradio as gr
3
+ from transformers import AutoTokenizer
4
+ import torch
5
+
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-ar")
8
+ model = torch.load("helsinki_fineTuned.pt", map_location=torch.device('cpu'))
9
+ model.eval()
10
+
11
+
12
+ def translate_gradio(input):
13
+ tokenized_text = tokenizer.prepare_seq2seq_batch([input], return_tensors='pt')
14
+ encode = model.generate(**tokenized_text)
15
+ text_ar = tokenizer.batch_decode(encode,skip_special_tokens=True)[0]
16
+ return text_ar
17
+ translate_interface = gr.Interface(fn = translate_gradio,
18
+ allow_flagging = True,
19
+ flagging_dir = 'flagged/logs',
20
+ title = 'Translating "English Data Science" content into Arabic',
21
+ inputs=gr.inputs.Textbox(lines = 7, label = 'english content'),
22
+ outputs="text",
23
+ examples = [['In the last few years the RNN-based architectures have shown the best performance in machine translation problems, but still they have some problems that had to be solved. First, they have a difficulty to cope with long-range dependencies (also LSTM when it has to deal with really long sentences). Secondly, each hidden state depends on the previous one which impossible to parallelize and makes it inefficient on GPUs.']]
24
+ )
25
+ translate_interface.launch(inline = False)