dk-davidekim commited on
Commit
4c192ae
โ€ข
1 Parent(s): 9e55db6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -3,6 +3,7 @@ import streamlit as st
3
  from streamlit_lottie import st_lottie
4
  import torch
5
  from transformers import AutoTokenizer, AutoModelForCausalLM
 
6
 
7
  # Page Config
8
  st.set_page_config(
@@ -164,7 +165,7 @@ row1_spacer1, row1_1, row1_spacer2 = st.columns((0.01, 0.01, 0.01))
164
 
165
  with row1_1:
166
  st.markdown("### nํ–‰์‹œ ๊ฐ€์ด๋“œ๋ผ์ธ")
167
- st.markdown("1. ํ•˜๋‹จ์— ์žˆ๋Š” ํ…์ŠคํŠธ๋ฐ”์— 5์ž ์ดํ•˜ ๋‹จ์–ด๋ฅผ ๋„ฃ์–ด์ฃผ์„ธ์š”")
168
  st.markdown("2. 'nํ–‰์‹œ ์ œ์ž‘ํ•˜๊ธฐ' ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ด์ฃผ์„ธ์š”")
169
 
170
  st.write('---')
@@ -175,15 +176,20 @@ row2_spacer1, row2_1, row2_spacer2= st.columns((0.01, 0.01, 0.01))
175
  # Word Input
176
  with row2_1:
177
  word_input = st.text_input(
178
- "nํ–‰์‹œ์— ์‚ฌ์šฉํ•  ๋‹จ์–ด๋ฅผ ์ ๊ณ  ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์ฃผ์„ธ์š”.(์ตœ๋Œ€ 5์ž) ๐Ÿ‘‡",
179
  placeholder='ํ•œ๊ธ€ ๋‹จ์–ด๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”',
180
  max_chars=5
181
  )
 
182
 
183
  if st.button('nํ–‰์‹œ ์ œ์ž‘ํ•˜๊ธฐ'):
184
- st.write("nํ–‰์‹œ ๋‹จ์–ด : ", word_input)
185
- with st.spinner('์ž ์‹œ ๊ธฐ๋‹ค๋ ค์ฃผ์„ธ์š”...'):
186
- result = n_line_poem(word_input)
187
- st.success('์™„๋ฃŒ๋์Šต๋‹ˆ๋‹ค!')
188
- for r in result:
189
- st.write(f'{r} : {result[r]}')
 
 
 
 
 
3
  from streamlit_lottie import st_lottie
4
  import torch
5
  from transformers import AutoTokenizer, AutoModelForCausalLM
6
+ import re
7
 
8
  # Page Config
9
  st.set_page_config(
 
165
 
166
  with row1_1:
167
  st.markdown("### nํ–‰์‹œ ๊ฐ€์ด๋“œ๋ผ์ธ")
168
+ st.markdown("1. ํ•˜๋‹จ์— ์žˆ๋Š” ํ…์ŠคํŠธ๋ฐ”์— 5์ž ์ดํ•˜ ํ•œ๊ธ€ ๋‹จ์–ด๋ฅผ ๋„ฃ์–ด์ฃผ์„ธ์š”")
169
  st.markdown("2. 'nํ–‰์‹œ ์ œ์ž‘ํ•˜๊ธฐ' ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ด์ฃผ์„ธ์š”")
170
 
171
  st.write('---')
 
176
  # Word Input
177
  with row2_1:
178
  word_input = st.text_input(
179
+ "nํ–‰์‹œ์— ์‚ฌ์šฉํ•  ํ•œ๊ธ€ ๋‹จ์–ด๋ฅผ ์ ๊ณ  ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์ฃผ์„ธ์š”.(์ตœ๋Œ€ 5์ž) ๐Ÿ‘‡",
180
  placeholder='ํ•œ๊ธ€ ๋‹จ์–ด๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”',
181
  max_chars=5
182
  )
183
+ word_input = re.sub("[^๊ฐ€-ํžฃ]", "", word_input)
184
 
185
  if st.button('nํ–‰์‹œ ์ œ์ž‘ํ•˜๊ธฐ'):
186
+ if word_input == "":
187
+ st.error("์˜จ์ „ํ•œ ํ•œ๊ธ€ ๋‹จ์–ด๋ฅผ ์‚ฌ์šฉํ•ด์ฃผ์„ธ์š”!")
188
+
189
+ else:
190
+ st.write("nํ–‰์‹œ ๋‹จ์–ด : ", word_input)
191
+ with st.spinner('์ž ์‹œ ๊ธฐ๋‹ค๋ ค์ฃผ์„ธ์š”...'):
192
+ result = n_line_poem(word_input)
193
+ st.success('์™„๋ฃŒ๋์Šต๋‹ˆ๋‹ค!')
194
+ for r in result:
195
+ st.write(f'{r} : {result[r]}')