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)