Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from transformers import pipeline | |
| def translate_text(text): | |
| model = pipeline("translation", model='Helsinki-NLP/opus-mt-ko-en') | |
| result = model(text) | |
| return result[0]['translation_text'] | |
| def main(): | |
| # ํ์ด์ง ์ค์ | |
| st.set_page_config( | |
| page_title="ํ์ ๋ฒ์ญ๊ธฐ", | |
| page_icon="๐", | |
| layout="centered" | |
| ) | |
| # CSS ์คํ์ผ ์ ์ฉ | |
| st.markdown(""" | |
| <style> | |
| .main-header { | |
| font-size: 2.5rem; | |
| color: #1E88E5; | |
| text-align: center; | |
| padding: 1rem 0; | |
| font-weight: bold; | |
| } | |
| .stButton>button { | |
| width: 100%; | |
| background-color: #1E88E5; | |
| color: white; | |
| font-size: 1.2rem; | |
| padding: 0.5rem 0; | |
| } | |
| .result-box { | |
| padding: 1.5rem; | |
| border-radius: 10px; | |
| background-color: #f0f2f6; | |
| margin: 1rem 0; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| # ํค๋ | |
| st.markdown('<p class="main-header">๐ ํ๊ธ โ ์์ด ๋ฒ์ญ๊ธฐ</p>', unsafe_allow_html=True) | |
| # ์ค๋ช ํ ์คํธ | |
| st.markdown("#### ํ๊ตญ์ด๋ฅผ ์์ด๋ก ๋ฒ์ญํด๋๋ฆฝ๋๋ค! ์๋์ ๋ฒ์ญํ๊ณ ์ถ์ ํ ์คํธ๋ฅผ ์ ๋ ฅํด์ฃผ์ธ์. ๐") | |
| # ๊ตฌ๋ถ์ | |
| st.markdown("---") | |
| # ์ ๋ ฅ ์ปฌ๋ผ๊ณผ ๊ฒฐ๊ณผ ์ปฌ๋ผ ์์ฑ | |
| col1, col2 = st.columns([1, 1]) | |
| with col1: | |
| st.markdown("### ํ๊ตญ์ด ์ ๋ ฅ") | |
| user_input = st.text_area("", height=200, placeholder="๋ฒ์ญํ ํ๊ธ์ ์ ๋ ฅํ์ธ์...") | |
| with col2: | |
| st.markdown("### ์์ด ๋ฒ์ญ") | |
| if user_input: | |
| translation = translate_text(user_input) | |
| st.markdown('<div class="result-box">' + translation + '</div>', unsafe_allow_html=True) | |
| else: | |
| st.markdown('<div class="result-box">๋ฒ์ญ ๊ฒฐ๊ณผ๊ฐ ์ฌ๊ธฐ์ ํ์๋ฉ๋๋ค.</div>', unsafe_allow_html=True) | |
| # ๋ฒ์ญ ๋ฒํผ | |
| if st.button('๋ฒ์ญํ๊ธฐ ๐'): | |
| if user_input: | |
| translation = translate_text(user_input) | |
| st.success('๋ฒ์ญ์ด ์๋ฃ๋์์ต๋๋ค! โจ') | |
| else: | |
| st.warning('โ ๏ธ ํ ์คํธ๋ฅผ ์ ๋ ฅํด์ฃผ์ธ์.') | |
| # ํธํฐ | |
| st.markdown("---") | |
| st.markdown("##### Made with โค๏ธ using Streamlit") | |
| if __name__ == '__main__': | |
| main() | |