Spaces:
Runtime error
Runtime error
dk-davidekim
commited on
Commit
โข
9873fd5
1
Parent(s):
b1f7647
Upload 2 files
Browse files- .streamlit/config.toml +4 -0
- pages/beta.py +302 -0
.streamlit/config.toml
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[theme]
|
2 |
+
|
3 |
+
base = "dark"
|
4 |
+
primaryColor="#87CEFA"
|
pages/beta.py
ADDED
@@ -0,0 +1,302 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import requests
|
3 |
+
import streamlit as st
|
4 |
+
from streamlit_lottie import st_lottie
|
5 |
+
import torch
|
6 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
7 |
+
import re
|
8 |
+
|
9 |
+
# Page Config
|
10 |
+
st.set_page_config(
|
11 |
+
page_title="๋
ธ๋ ๊ฐ์ฌ nํ์ Beta",
|
12 |
+
page_icon="๐",
|
13 |
+
layout="wide"
|
14 |
+
)
|
15 |
+
# st.text(os.listdir(os.curdir))
|
16 |
+
|
17 |
+
### Model
|
18 |
+
tokenizer = AutoTokenizer.from_pretrained("wumusill/final_project_kogpt2")
|
19 |
+
|
20 |
+
@st.cache(show_spinner=False)
|
21 |
+
def load_model():
|
22 |
+
model = AutoModelForCausalLM.from_pretrained("wumusill/final_project_kogpt2")
|
23 |
+
return model
|
24 |
+
|
25 |
+
model = load_model()
|
26 |
+
|
27 |
+
word = pd.read_csv("ballad_word.csv", encoding="cp949")
|
28 |
+
# st.dataframe(word)
|
29 |
+
|
30 |
+
one = word[word["0"].str.startswith("ํ")].sample(1).values[0][0]
|
31 |
+
# st.header(type(one))
|
32 |
+
# st.header(one)
|
33 |
+
|
34 |
+
|
35 |
+
# Class : Dict ์ค๋ณต ํค ์ถ๋ ฅ
|
36 |
+
class poem(object):
|
37 |
+
def __init__(self,letter):
|
38 |
+
self.letter = letter
|
39 |
+
|
40 |
+
def __str__(self):
|
41 |
+
return self.letter
|
42 |
+
|
43 |
+
def __repr__(self):
|
44 |
+
return "'"+self.letter+"'"
|
45 |
+
|
46 |
+
|
47 |
+
def beta_poem(input_letter):
|
48 |
+
# ๋์ ๋ฒ์น ์ฌ์
|
49 |
+
dooeum = {"๋ผ":"๋", "๋ฝ":"๋", "๋":"๋", "๋":"๋ ", "๋":"๋จ", "๋":"๋ฉ", "๋":"๋ญ",
|
50 |
+
"๋":"๋ด", "๋ญ":"๋", "๋":"์ฝ", "๋ต":"์ฝ", "๋ฅ":"์", "๋":"์", "๋
":"์ฌ",
|
51 |
+
"๋ ค":"์ฌ", "๋
":"์ญ", "๋ ฅ":"์ญ", "๋
":"์ฐ", "๋ จ":"์ฐ", "๋
":"์ด", "๋ ฌ":"์ด",
|
52 |
+
"๋
":"์ผ", "๋ ด":"์ผ", "๋ ต":"์ฝ", "๋
":"์", "๋ น":"์", "๋
":"์", "๋ก":"์",
|
53 |
+
"๋ก":"๋
ธ", "๋ก":"๋
น", "๋ก ":"๋
ผ", "๋กฑ":"๋", "๋ขฐ":"๋", "๋จ":"์", "๋ฃ":"์",
|
54 |
+
"๋ฃก":"์ฉ", "๋ฃจ":"๋", "๋ด":"์ ", "๋ฅ":"์ ", "๋ต":"์ก", "๋ฅ":"์ก", "๋ฅ":"์ค",
|
55 |
+
"๋ฅ ":"์จ", "๋ฅญ":"์ต", "๋ฅต":"๋", "๋ฆ":"๋ ", "๋ฆ":"๋ฅ", "๋":"์ด", "๋ฆฌ":"์ด",
|
56 |
+
"๋ฆฐ":'์ธ', '๋ฆผ':'์', '๋ฆฝ':'์
'}
|
57 |
+
# ๊ฒฐ๊ณผ๋ฌผ์ ๋ด์ list
|
58 |
+
res_l = []
|
59 |
+
len_sequence = 0
|
60 |
+
|
61 |
+
# ํ ๊ธ์์ฉ ์ธ๋ฑ์ค์ ํจ๊ป ๊ฐ์ ธ์ด
|
62 |
+
for idx, val in enumerate(input_letter):
|
63 |
+
# ๋์ ๋ฒ์น ์ ์ฉ
|
64 |
+
if val in dooeum.keys():
|
65 |
+
val = dooeum[val]
|
66 |
+
|
67 |
+
# ๋ฐ๋ผ๋์ ์๋ ๋จ์ด ์ ์ฉ
|
68 |
+
try:
|
69 |
+
word = words[words.str.startswith(val)].sample(1).values[0]
|
70 |
+
except:
|
71 |
+
word = val
|
72 |
+
|
73 |
+
# ์ข๋ ๋งค๋๋ฌ์ด ์ผํ์๋ฅผ ์ํด ์ด์ ๋ฌธ์ฅ์ด๋ ํ์ฌ ์์ ์ฐ๊ฒฐ
|
74 |
+
# ์ดํ generate ๋ ๋ฌธ์ฅ์์ ์ด์ ๋ฌธ์ฅ์ ๋ํ ๋ฐ์ดํฐ ์ ๊ฑฐ
|
75 |
+
link_with_pre_sentence = (" ".join(res_l)+ " " + word + " " if idx != 0 else word).strip()
|
76 |
+
# print(link_with_pre_sentence)
|
77 |
+
|
78 |
+
# ์ฐ๊ฒฐ๋ ๋ฌธ์ฅ์ ์ธ์ฝ๋ฉ
|
79 |
+
input_ids = tokenizer.encode(link_with_pre_sentence, add_special_tokens=False, return_tensors="pt")
|
80 |
+
|
81 |
+
# ์ธ์ฝ๋ฉ ๊ฐ์ผ๋ก ๋ฌธ์ฅ ์์ฑ
|
82 |
+
output_sequence = model.generate(
|
83 |
+
input_ids=input_ids,
|
84 |
+
do_sample=True,
|
85 |
+
max_length=42,
|
86 |
+
min_length=len_sequence + 2,
|
87 |
+
temperature=0.9,
|
88 |
+
repetition_penalty=1.5,
|
89 |
+
no_repeat_ngram_size=2)
|
90 |
+
|
91 |
+
# ์์ฑ๋ ๋ฌธ์ฅ ๋ฆฌ์คํธ๋ก ๋ณํ (์ธ์ฝ๋ฉ ๋์ด์๊ณ , ์์ฑ๋ ๋ฌธ์ฅ ๋ค๋ก padding ์ด ์๋ ์ํ)
|
92 |
+
generated_sequence = output_sequence.tolist()[0]
|
93 |
+
|
94 |
+
# padding index ์๊น์ง slicing ํจ์ผ๋ก์จ padding ์ ๊ฑฐ, padding์ด ์์ ์๋ ์๊ธฐ ๋๋ฌธ์ ์กฐ๊ฑด๋ฌธ ํ์ธ ํ ์ ๊ฑฐ
|
95 |
+
# ์ฌ์ฉํ generated_sequence ๊ฐ 5๋ณด๋ค ์งง์ผ๋ฉด ๊ฐ์ ์ ์ผ๋ก ๊ธธ์ด๋ฅผ 8๋ก ํด์ค๋ค...
|
96 |
+
if tokenizer.pad_token_id in generated_sequence:
|
97 |
+
check_index = generated_sequence.index(tokenizer.pad_token_id)
|
98 |
+
check_index = check_index if check_index-len_sequence > 3 else len_sequence + 8
|
99 |
+
generated_sequence = generated_sequence[:check_index]
|
100 |
+
|
101 |
+
word_encode = tokenizer.encode(word, add_special_tokens=False, return_tensors="pt").tolist()[0][0]
|
102 |
+
split_index = len(generated_sequence) - 1 - generated_sequence[::-1].index(word_encode)
|
103 |
+
|
104 |
+
# ์ฒซ ๊ธ์๊ฐ ์๋๋ผ๋ฉด, generate ๋ ์์ ๋ง ๊ฒฐ๊ณผ๋ฌผ list์ ๋ค์ด๊ฐ ์ ์๊ฒ ์ ๋ฌธ์ฅ์ ๋ํ ์ธ์ฝ๋ฉ ๊ฐ ์ ๊ฑฐ
|
105 |
+
generated_sequence = generated_sequence[split_index:]
|
106 |
+
|
107 |
+
# print(tokenizer.decode(generated_sequence, clean_up_tokenization_spaces=True, skip_special_tokens=True))
|
108 |
+
# ๋ค์ ์์ ์ ์ํด ๊ธธ์ด ๊ฐฑ์
|
109 |
+
len_sequence += len([elem for elem in generated_sequence if elem not in(tokenizer.all_special_ids)])
|
110 |
+
# ๊ฒฐ๊ณผ๋ฌผ ๋์ฝ๋ฉ
|
111 |
+
decoded_sequence = tokenizer.decode(generated_sequence, clean_up_tokenization_spaces=True, skip_special_tokens=True)
|
112 |
+
|
113 |
+
# ๊ฒฐ๊ณผ๋ฌผ ๋ฆฌ์คํธ์ ๋ด๊ธฐ
|
114 |
+
res_l.append(decoded_sequence)
|
115 |
+
|
116 |
+
poem_dict = {"Type":"beta"}
|
117 |
+
|
118 |
+
for letter, res in zip(input_letter, res_l):
|
119 |
+
# decode_res = tokenizer.decode(res, clean_up_tokenization_spaces=True, skip_special_tokens=True)
|
120 |
+
poem_dict[poem(letter)] = res
|
121 |
+
|
122 |
+
return poem_dict
|
123 |
+
|
124 |
+
def alpha_poem(input_letter):
|
125 |
+
|
126 |
+
# ๋์ ๋ฒ์น ์ฌ์
|
127 |
+
dooeum = {"๋ผ":"๋", "๋ฝ":"๋", "๋":"๋", "๋":"๋ ", "๋":"๋จ", "๋":"๋ฉ", "๋":"๋ญ",
|
128 |
+
"๋":"๋ด", "๋ญ":"๋", "๋":"์ฝ", "๋ต":"์ฝ", "๋ฅ":"์", "๋":"์", "๋
":"์ฌ",
|
129 |
+
"๋ ค":"์ฌ", "๋
":"์ญ", "๋ ฅ":"์ญ", "๋
":"์ฐ", "๋ จ":"์ฐ", "๋
":"์ด", "๋ ฌ":"์ด",
|
130 |
+
"๋
":"์ผ", "๋ ด":"์ผ", "๋ ต":"์ฝ", "๋
":"์", "๋ น":"์", "๋
":"์", "๋ก":"์",
|
131 |
+
"๋ก":"๋
ธ", "๋ก":"๋
น", "๋ก ":"๋
ผ", "๋กฑ":"๋", "๋ขฐ":"๋", "๋จ":"์", "๋ฃ":"์",
|
132 |
+
"๋ฃก":"์ฉ", "๋ฃจ":"๋", "๋ด":"์ ", "๋ฅ":"์ ", "๋ต":"์ก", "๋ฅ":"์ก", "๋ฅ":"์ค",
|
133 |
+
"๋ฅ ":"์จ", "๋ฅญ":"์ต", "๋ฅต":"๋", "๋ฆ":"๋ ", "๋ฆ":"๋ฅ", "๋":"์ด", "๋ฆฌ":"์ด",
|
134 |
+
"๋ฆฐ":'์ธ', '๋ฆผ':'์', '๋ฆฝ':'์
'}
|
135 |
+
# ๊ฒฐ๊ณผ๋ฌผ์ ๋ด์ list
|
136 |
+
res_l = []
|
137 |
+
|
138 |
+
# ํ ๊ธ์์ฉ ์ธ๋ฑ์ค์ ํจ๊ป ๊ฐ์ ธ์ด
|
139 |
+
for idx, val in enumerate(input_letter):
|
140 |
+
# ๋์ ๋ฒ์น ์ ์ฉ
|
141 |
+
if val in dooeum.keys():
|
142 |
+
val = dooeum[val]
|
143 |
+
|
144 |
+
|
145 |
+
while True:
|
146 |
+
# ๋ง์ฝ idx ๊ฐ 0 ์ด๋ผ๋ฉด == ์ฒซ ๊ธ์
|
147 |
+
if idx == 0:
|
148 |
+
# ์ฒซ ๊ธ์ ์ธ์ฝ๋ฉ
|
149 |
+
input_ids = tokenizer.encode(
|
150 |
+
val, add_special_tokens=False, return_tensors="pt")
|
151 |
+
# print(f"{idx}๋ฒ ์ธ์ฝ๋ฉ : {input_ids}\n") # 2์ฐจ์ ํ
์
|
152 |
+
|
153 |
+
# ์ฒซ ๊ธ์ ์ธ์ฝ๋ฉ ๊ฐ์ผ๋ก ๋ฌธ์ฅ ์์ฑ
|
154 |
+
output_sequence = model.generate(
|
155 |
+
input_ids=input_ids,
|
156 |
+
do_sample=True,
|
157 |
+
max_length=42,
|
158 |
+
min_length=5,
|
159 |
+
temperature=0.9,
|
160 |
+
repetition_penalty=1.7,
|
161 |
+
no_repeat_ngram_size=2)[0]
|
162 |
+
# print("์ฒซ ๊ธ์ ์ธ์ฝ๋ฉ ํ generate ๊ฒฐ๊ณผ:", output_sequence, "\n") # tensor
|
163 |
+
|
164 |
+
# ์ฒซ ๊ธ์๊ฐ ์๋๋ผ๋ฉด
|
165 |
+
else:
|
166 |
+
# ํ ์์
|
167 |
+
input_ids = tokenizer.encode(
|
168 |
+
val, add_special_tokens=False, return_tensors="pt")
|
169 |
+
# print(f"{idx}๋ฒ ์งธ ๊ธ์ ์ธ์ฝ๋ฉ : {input_ids} \n")
|
170 |
+
|
171 |
+
# ์ข๋ ๋งค๋๋ฌ์ด ์ผํ์๋ฅผ ์ํด ์ด์ ์ธ์ฝ๋ฉ๊ณผ ์ง๊ธ ์ธ์ฝ๋ฉ ์ฐ๊ฒฐ
|
172 |
+
link_with_pre_sentence = torch.cat((generated_sequence, input_ids[0]), 0)
|
173 |
+
link_with_pre_sentence = torch.reshape(link_with_pre_sentence, (1, len(link_with_pre_sentence)))
|
174 |
+
# print(f"์ด์ ํ
์์ ์ฐ๊ฒฐ๋ ํ
์ {link_with_pre_sentence} \n")
|
175 |
+
|
176 |
+
# ์ธ์ฝ๋ฉ ๊ฐ์ผ๋ก ๋ฌธ์ฅ ์์ฑ
|
177 |
+
output_sequence = model.generate(
|
178 |
+
input_ids=link_with_pre_sentence,
|
179 |
+
do_sample=True,
|
180 |
+
max_length=42,
|
181 |
+
min_length=5,
|
182 |
+
temperature=0.9,
|
183 |
+
repetition_penalty=1.7,
|
184 |
+
no_repeat_ngram_size=2)[0]
|
185 |
+
# print(f"{idx}๋ฒ ์ธ์ฝ๋ฉ ํ generate : {output_sequence}")
|
186 |
+
|
187 |
+
# ์์ฑ๋ ๋ฌธ์ฅ ๋ฆฌ์คํธ๋ก ๋ณํ (์ธ์ฝ๋ฉ ๋์ด์๊ณ , ์์ฑ๋ ๋ฌธ์ฅ ๋ค๋ก padding ์ด ์๋ ์ํ)
|
188 |
+
generated_sequence = output_sequence.tolist()
|
189 |
+
# print(f"{idx}๋ฒ ์ธ์ฝ๋ฉ ๋ฆฌ์คํธ : {generated_sequence} \n")
|
190 |
+
|
191 |
+
# padding index ์๊น์ง slicing ํจ์ผ๋ก์จ padding ์ ๊ฑฐ, padding์ด ์์ ์๋ ์๊ธฐ ๋๋ฌธ์ ์กฐ๊ฑด๋ฌธ ํ์ธ ํ ์ ๊ฑฐ
|
192 |
+
if tokenizer.pad_token_id in generated_sequence:
|
193 |
+
generated_sequence = generated_sequence[:generated_sequence.index(tokenizer.pad_token_id)]
|
194 |
+
|
195 |
+
generated_sequence = torch.tensor(generated_sequence)
|
196 |
+
# print(f"{idx}๋ฒ ์ธ์ฝ๋ฉ ๋ฆฌ์คํธ ํจ๋ฉ ์ ๊ฑฐ ํ ๋ค์ ํ
์ : {generated_sequence} \n")
|
197 |
+
|
198 |
+
# ์ฒซ ๊ธ์๊ฐ ์๋๋ผ๋ฉด, generate ๋ ์์ ๋ง ๊ฒฐ๊ณผ๋ฌผ list์ ๋ค์ด๊ฐ ์ ์๊ฒ ์ ๋ฌธ์ฅ์ ๋ํ ์ธ์ฝ๋ฉ ๊ฐ ์ ๊ฑฐ
|
199 |
+
# print(generated_sequence)
|
200 |
+
if idx != 0:
|
201 |
+
# ์ด์ ๋ฌธ์ฅ์ ๊ธธ์ด ์ดํ๋ก ์ฌ๋ผ์ด์ฑํด์ ์ ๋ฌธ์ฅ ์ ๊ฑฐ
|
202 |
+
generated_sequence = generated_sequence[len_sequence:]
|
203 |
+
|
204 |
+
len_sequence = len(generated_sequence)
|
205 |
+
# print("len_seq", len_sequence)
|
206 |
+
|
207 |
+
# ์์ ๊ทธ๋๋ก ๋ฑ์ผ๋ฉด ๋ค์ ํด์, ์๋๋ฉด while๋ฌธ ํ์ถ
|
208 |
+
if len_sequence > 1:
|
209 |
+
break
|
210 |
+
|
211 |
+
# ๊ฒฐ๊ณผ๋ฌผ ๋ฆฌ์คํธ์ ๋ด๊ธฐ
|
212 |
+
res_l.append(generated_sequence)
|
213 |
+
|
214 |
+
poem_dict = {"Type":"alpha"}
|
215 |
+
|
216 |
+
for letter, res in zip(input_letter, res_l):
|
217 |
+
decode_res = tokenizer.decode(res, clean_up_tokenization_spaces=True, skip_special_tokens=True)
|
218 |
+
poem_dict[poem(letter)] = decode_res
|
219 |
+
|
220 |
+
return poem_dict
|
221 |
+
|
222 |
+
# Image(.gif)
|
223 |
+
@st.cache(show_spinner=False)
|
224 |
+
def load_lottieurl(url: str):
|
225 |
+
r = requests.get(url)
|
226 |
+
if r.status_code != 200:
|
227 |
+
return None
|
228 |
+
return r.json()
|
229 |
+
|
230 |
+
lottie_url = "https://assets7.lottiefiles.com/private_files/lf30_fjln45y5.json"
|
231 |
+
|
232 |
+
lottie_json = load_lottieurl(lottie_url)
|
233 |
+
st_lottie(lottie_json, speed=1, height=200, key="initial")
|
234 |
+
|
235 |
+
|
236 |
+
# Title
|
237 |
+
row0_spacer1, row0_1, row0_spacer2, row0_2, row0_spacer3 = st.columns(
|
238 |
+
(0.01, 2, 0.05, 0.5, 0.01)
|
239 |
+
)
|
240 |
+
|
241 |
+
with row0_1:
|
242 |
+
st.markdown("# ํ๊ธ ๋
ธ๋ ๊ฐ์ฌ nํ์โ")
|
243 |
+
st.markdown("### ๐ฆ๋ฉ์์ด์ฌ์์ฒ๋ผ AIS7๐ฆ - ํ์ด๋ ํ๋ก์ ํธ")
|
244 |
+
|
245 |
+
with row0_2:
|
246 |
+
st.write("")
|
247 |
+
st.write("")
|
248 |
+
st.write("")
|
249 |
+
st.subheader("1์กฐ - ํดํ๋ฆฌ")
|
250 |
+
st.write("์ด์งํ, ์ต์ง์, ๊ถ์ํฌ, ๋ฌธ์ข
ํ, ๊ตฌ์ํ, ๊น์์ค")
|
251 |
+
|
252 |
+
st.write('---')
|
253 |
+
|
254 |
+
# Explanation
|
255 |
+
row1_spacer1, row1_1, row1_spacer2 = st.columns((0.01, 0.01, 0.01))
|
256 |
+
|
257 |
+
with row1_1:
|
258 |
+
st.markdown("### nํ์ ๊ฐ์ด๋๋ผ์ธ")
|
259 |
+
st.markdown("1. ํ๋จ์ ์๋ ํ
์คํธ๋ฐ์ 5์ ์ดํ ๋จ์ด๋ฅผ ๋ฃ์ด์ฃผ์ธ์")
|
260 |
+
st.markdown("2. 'nํ์ ์ ์ํ๊ธฐ' ๋ฒํผ์ ํด๋ฆญํด์ฃผ์ธ์")
|
261 |
+
|
262 |
+
st.write('---')
|
263 |
+
|
264 |
+
# Model & Input
|
265 |
+
row2_spacer1, row2_1, row2_spacer2= st.columns((0.01, 0.01, 0.01))
|
266 |
+
|
267 |
+
col1, col2 = st.columns(2)
|
268 |
+
|
269 |
+
# Word Input
|
270 |
+
with row2_1:
|
271 |
+
|
272 |
+
with col1:
|
273 |
+
genre = st.radio(
|
274 |
+
"nํ์ ํ์
์ ํ",
|
275 |
+
('Alpha', 'Beta(test์ค)'))
|
276 |
+
|
277 |
+
if genre == 'Alpha':
|
278 |
+
n_line_poem = alpha_poem
|
279 |
+
|
280 |
+
else:
|
281 |
+
n_line_poem = beta_poem
|
282 |
+
|
283 |
+
with col2:
|
284 |
+
word_input = st.text_input(
|
285 |
+
"nํ์์ ์ฌ์ฉํ ๋จ์ด๋ฅผ ์ ๊ณ ๋ฒํผ์ ๋๋ฌ์ฃผ์ธ์.(์ต๋ 5์) ๐",
|
286 |
+
placeholder='ํ๊ธ ๋จ์ด๋ฅผ ์
๋ ฅํด์ฃผ์ธ์',
|
287 |
+
max_chars=5
|
288 |
+
)
|
289 |
+
word_input = re.sub("[^๊ฐ-ํฃ]", "", word_input)
|
290 |
+
|
291 |
+
if st.button('nํ์ ์ ์ํ๊ธฐ'):
|
292 |
+
if word_input == "":
|
293 |
+
st.error("์จ์ ํ ํ๊ธ ๋จ์ด๋ฅผ ์ฌ์ฉํด์ฃผ์ธ์!")
|
294 |
+
|
295 |
+
else:
|
296 |
+
st.write("nํ์ ๋จ์ด : ", word_input)
|
297 |
+
with st.spinner('์ ์ ๊ธฐ๋ค๋ ค์ฃผ์ธ์...'):
|
298 |
+
result = n_line_poem(word_input)
|
299 |
+
st.success('์๋ฃ๋์ต๋๋ค!')
|
300 |
+
for r in result:
|
301 |
+
st.write(f'{r} : {result[r]}')
|
302 |
+
|