kor-eng / app.py
blockenters's picture
add
0ab3218
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()