File size: 880 Bytes
97d390e 47e7ef9 97d390e 47e7ef9 97d390e 699409b 97d390e 699409b 97d390e 699409b 97d390e 699409b 97d390e 47e7ef9 97d390e 47e7ef9 |
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 30 |
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)
|