Spaces:
Running
Running
from transformers import MarianMTModel, MarianTokenizer | |
# 1) MarianMT ๋ชจ๋ธ๊ณผ ํ ํฌ๋์ด์ ๋ถ๋ฌ์ค๊ธฐ | |
model_name = "Helsinki-NLP/opus-mt-ko-en" | |
tokenizer = MarianTokenizer.from_pretrained(model_name) | |
model = MarianMTModel.from_pretrained(model_name) | |
# 2) ๋ฒ์ญ ํจ์ ์์ | |
def translate_ko_to_en(text: str) -> str: | |
# ์ ๋ ฅ ๋ฌธ์ฅ์ ํ ํฐํ | |
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True) | |
# ๋ชจ๋ธ๋ก ์ถ๋ก | |
translated = model.generate(**inputs) | |
# ํ ํฐ์ ๋ค์ ๋ฌธ์ฅ์ผ๋ก ๋์ฝ๋ฉ | |
translation = tokenizer.batch_decode(translated, skip_special_tokens=True) | |
return translation[0] |