Spaces:
Runtime error
Runtime error
File size: 1,034 Bytes
9483a74 7704506 dc0bfb9 7704506 dc0bfb9 7704506 dc0bfb9 7704506 9483a74 7704506 |
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 28 29 |
import gradio as gr
from transformers import MarianMTModel, MarianTokenizer
# ๋ชจ๋ธ๊ณผ ํ ํฌ๋์ด์ ๋ก๋
model_name = "Helsinki-NLP/opus-mt-ko-it"
tokenizer = MarianTokenizer.from_pretrained(model_name)
model = MarianMTModel.from_pretrained(model_name)
# ๋ฒ์ญ ํจ์
def translate_korean_to_italian(text):
if not text.strip():
return "โ ๏ธ ๋ฒ์ญํ ๋ฌธ์ฅ์ ์
๋ ฅํ์ธ์."
inputs = tokenizer(text, return_tensors="pt", padding=True)
translated = model.generate(**inputs)
result = tokenizer.decode(translated[0], skip_special_tokens=True)
return result
# Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ
interface = gr.Interface(
fn=translate_korean_to_italian,
inputs=gr.Textbox(lines=2, label="ํ๊ตญ์ด ์
๋ ฅ"),
outputs=gr.Textbox(label="์ดํ๋ฆฌ์์ด ๋ฒ์ญ"),
title="ํ๊ตญ์ด โ ์ดํ๋ฆฌ์์ด ๋ฒ์ญ๊ธฐ",
description="ํ๊ตญ์ด ๋ฌธ์ฅ์ ์
๋ ฅํ๋ฉด ์ดํ๋ฆฌ์์ด๋ก ๋ฒ์ญํฉ๋๋ค. ๋ชจ๋ธ: Helsinki-NLP/opus-mt-ko-it"
)
if __name__ == "__main__":
interface.launch()
|