Spaces:
Sleeping
Sleeping
File size: 921 Bytes
5bcc945 9981df6 9aabe06 7a73074 9981df6 9aabe06 d0dc5fc c2483bf 9981df6 f725092 9aabe06 9981df6 36a2e00 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import sys
import subprocess
# implement pip as a subprocess:
subprocess.check_call([sys.executable, '-m', 'pip', 'install','--quiet','sentencepiece==0.1.95'])
import gradio as gr
from transformers import pipeline
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import torch
tokenizer = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-ar")
model = torch.load("helsinki_fineTuned.pt", map_location=torch.device('cpu'))
#translation_pipeline = pipeline(model)
def translate_gradio(input):
encode = model.generate(**tokenizer.prepare_seq2seq_batch(input,return_tensors='pt'))
text_ar = tokenizer.batch_decode(encode,skip_special_tokens=True)[0]
return text_ar
translate_interface = gr.Interface(fn = translate_gradio,
inputs="text",
outputs="text" )
translate_interface.launch(inline = False) |