File size: 632 Bytes
0fdff2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
import gradio as grad

model_name = "Helsinki-NLP/opus-mt-ko-en"
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)

#opus_translator = pipeline("translation", model=model_name)

def translate(text):
  inputs = tokenizer(text, return_tensors="pt")
  translation_output = model.generate(**input)
  response = tokenizer.decode(translation_output[0], skip_special_tokens=True)

  #response = opus_translator(text)
  return response

# Web UI
grad.Interface(translate, inputs=["text"], outputs=["text"]).launch()