Spaces:
Sleeping
Sleeping
# -*- coding: utf-8 -*- | |
"""demo_gradio_huggingface_spaces.ipynb | |
Automatically generated by Colaboratory. | |
Original file is located at | |
https://colab.research.google.com/drive/1vy72Qs-scdzH68lhYbGN11fLzcE9Md1O | |
""" | |
#!pip install transformers gradio sentencepiece | |
#!pip install transformers[sentencepiece] | |
#!pip install sacremoses | |
# gradio ๊ทธ๋ผ๋์ค ๊ทธ๋ ์ด๋์ค | |
# !๋ ์ฝ๋ฉ์๊ฒ ํ๋ ์์คํ ๋ช ๋ น์ด | |
# ์์คํ ๋ช ๋ น์ด?๊ฐ ๋ญ์ฃ : ํค์๋ -> ์ ๋์ค ์ ์คํฌ๋ฆฝํธ ๋ช ๋ น์ด | |
# ! ์์ด๋ ๊ทธ๋ฅ ์ผ๋ฐ ํ์ด์ฌ ๋ช ๋ น์ด | |
# sklearn/pandas/plotly๋ ์ค์น ์ ํ๋๋ฐ? | |
# ์ฝ๋ฉ ๋จธ์ ์ ๊ธฐ๋ณธ์ ์ผ๋ก ์ค์น๋์ด์๋๋ฐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค์ด ์์ | |
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() | |
# [email protected] |