Translator / app.py
Mamom's picture
Update app.py
debef99
raw
history blame
971 Bytes
pip install transformers gradio sentencepiece
pip install transformers[sentencepiece]
pip install sacremoses
import gradio as gr # gradio๋ฅผ ๊ฐ€์ ธ์™€์„œ ์“ฐ๋Š”๋ฐ, ๋งค๋ฒˆ gradio ์—ฌ์„ฏ์ž ์น˜๋Š”๊ฒŒ ๊ท€์ฐฎ์œผ๋ฉด
# as gr์ด๋ผ๊ณ  ์ถ”๊ฐ€ํ•ด์„œ ์ด ์ดํ›„๋กœ๋Š” gr์ด๋ผ๊ณ ๋งŒ ์จ๋„ ๋จ
# gradio๊ฐ€ ์›น ์ƒ์—์„œ์˜ ๋ฐ๋ชจ๋ฅผ ๋งŒ๋“ค์–ด์คŒ (UI ํฌํ•จ!)
import transformers # ํŠธ๋žœ์Šคํฌ๋จธ(์‹ ๊ฒฝ๋ง์˜ ์ผ์ข…)
from transformers import pipeline # ํŒŒ์ดํ”„๋ผ์ธ์€ ๋จธ์‹ ๋Ÿฌ๋‹ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ
# ์—ฌ๋Ÿฌ ๊ตฌ์„ฑ ์š”์†Œ๋ฅผ ๋ฌถ์–ด์คŒ -> ๊ตฌ์„ฑ ์š”์†Œ๋ž€? ์˜ˆ) ๋ฌธ์ œ์˜ ์ข…๋ฅ˜, ๋ชจ๋ธ์˜ ์ข…๋ฅ˜ ๋“ฑ
pipe = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
# ๋ฌธ์ œ์˜ ์ข…๋ฅ˜๋Š” ๋ฒˆ์—ญ์ด๊ณ , ์šฐ๋ฆฌ๊ฐ€ ์“ธ ๋ชจ๋ธ์€ Hel.... en์ด๋ผ ๋ถˆ๋ฆฌ๋Š” ๋ชจ๋ธ
demo = gr.Interface.from_pipeline(pipe)
# gradio๋ผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์— ์ •์˜๋˜์–ด์žˆ๋Š” Interface๋ฅผ ๋งŒ๋“ค์ž
# ๋ญ๋กœ๋ถ€ํ„ฐ ๋งŒ๋“œ๋ƒ๋ฉด pipe๋กœ๋ถ€ํ„ฐ
# UI -> User Interface
demo.launch()