KyuDan1
chatgpt
47e7ef9
raw
history blame
880 Bytes
import gradio as gr
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
# ๋ชจ๋ธ๊ณผ ํ† ํฌ๋‚˜์ด์ €๋Š” ํ•œ ๋ฒˆ๋งŒ ๋กœ๋“œ๋˜๋„๋ก ํ•จ์ˆ˜ ์™ธ๋ถ€์— ์„ ์–ธ
model = AutoModelForSeq2SeqLM.from_pretrained("Kyudan/opus-mt-en-ro-finetuned-en-to-ro")
tokenizer = AutoTokenizer.from_pretrained("Kyudan/opus-mt-en-ro-finetuned-en-to-ro")
def respond(text):
# ์ž…๋ ฅ ํ…์ŠคํŠธ๋ฅผ ํ† ํฐํ™”
inputs = tokenizer.encode(text, return_tensors="pt")
# ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฒˆ์—ญ
outputs = model.generate(inputs)
# ๋ฒˆ์—ญ๋œ ํ…์ŠคํŠธ๋ฅผ ๋””์ฝ”๋”ฉ
translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
return translated_text
# Gradio ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ •
demo = gr.Interface(
fn=respond,
inputs="text",
outputs="text",
title="Translate English to Romanian"
)
if __name__ == "__main__":
demo.launch(share=True)