File size: 834 Bytes
16e5d56 a2c58f1 16e5d56 a2c58f1 |
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 |
import gradio as gr
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
# ์์ด-ํ๊ตญ์ด ๋ฒ์ญ ๋ชจ๋ธ ๋ก๋
model_name = "t5-base"
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
def translate_text(input_text):
# ์
๋ ฅ ํ
์คํธ ํ ํฐํ
input_ids = tokenizer.encode(input_text, return_tensors="pt")
# ๋ฒ์ญ ๋ชจ๋ธ ์คํ
output = model.generate(input_ids, max_length=50)
# ์ถ๋ ฅ ํ
์คํธ ์์ฑ
output_text = tokenizer.decode(output[0], skip_special_tokens=True)
return output_text
# Gradio ์ ํ๋ฆฌ์ผ์ด์
๊ตฌ์ถ
iface = gr.Interface(
fn=translate_text,
inputs="text",
outputs="text",
title="English-Korean Translator",
description="Enter English text to translate to Korean."
)
iface.launch()
|