Spaces:
Runtime error
Runtime error
anonymousauthors
commited on
Commit
β’
a3fb811
1
Parent(s):
11dce1d
Update pages/1_π_Dictionary_(Browse).py
Browse files- pages/1_π_Dictionary_(Browse).py +109 -52
pages/1_π_Dictionary_(Browse).py
CHANGED
@@ -5,16 +5,18 @@ import os
|
|
5 |
import pickle
|
6 |
from streamlit import session_state as _state
|
7 |
|
8 |
-
|
9 |
from PyDictionary import PyDictionary
|
10 |
-
|
|
|
11 |
|
12 |
st.set_page_config(layout="wide", page_title="ACl23 Secret Language")
|
13 |
from streamlit_extras.switch_page_button import switch_page
|
|
|
14 |
|
15 |
-
want_to_contribute = st.button("I want to contribute!")
|
16 |
-
if want_to_contribute:
|
17 |
-
|
|
|
18 |
|
19 |
# st.title("ACl23 Secret Language")
|
20 |
|
@@ -29,56 +31,111 @@ buttons = {}
|
|
29 |
# st.text(k)
|
30 |
|
31 |
with st.sidebar:
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
cols1 = st.columns(8)
|
38 |
-
for i in range(len(cols1)):
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
buttons[
|
51 |
-
buttons[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
-
# all_condition = False
|
55 |
-
for k in buttons:
|
56 |
-
if buttons[k]:
|
57 |
-
if k == '0-9':
|
58 |
-
st.title(k)
|
59 |
-
file_names = ['num_dict.pkl']
|
60 |
-
elif k == 'Others':
|
61 |
-
st.title(k)
|
62 |
-
file_names = ['other_dict.pkl']
|
63 |
-
elif ord(k[0]) in list(range(97, 123)) + list(range(65, 91)):
|
64 |
-
st.title(chr(ord(k)))
|
65 |
-
file_names = [f'{ord(k[0]) + 32}_dict.pkl', f'{ord(k[0])}_dict.pkl']
|
66 |
-
all_data = {}
|
67 |
-
all_key = []
|
68 |
-
for file_name in file_names:
|
69 |
-
_data = pickle.load(open(f'all_secret_langauge_by_fist/{file_name}', 'rb'))
|
70 |
-
all_data.update(_data)
|
71 |
-
all_key.extend(sorted(list(_data.keys())))
|
72 |
-
# st.markdown(file_name, unsafe_allow_html=True)
|
73 |
-
# st.markdown(_data.keys(), unsafe_allow_html=True)
|
74 |
-
|
75 |
-
all_key = list(set(all_key))
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
# with st.expander(key):
|
83 |
# st.markdown(':red[Secret Languages:' + ','.join(all_data[key]['secret languages']), unsafe_allow_html=True)
|
84 |
|
|
|
5 |
import pickle
|
6 |
from streamlit import session_state as _state
|
7 |
|
|
|
8 |
from PyDictionary import PyDictionary
|
9 |
+
|
10 |
+
dictionary = PyDictionary()
|
11 |
|
12 |
st.set_page_config(layout="wide", page_title="ACl23 Secret Language")
|
13 |
from streamlit_extras.switch_page_button import switch_page
|
14 |
+
from streamlit_extras.stateful_button import button
|
15 |
|
16 |
+
# want_to_contribute = st.button("I want to contribute!")
|
17 |
+
# if want_to_contribute:
|
18 |
+
# # switch_page("dictionary (search)")
|
19 |
+
# switch_page("home")
|
20 |
|
21 |
# st.title("ACl23 Secret Language")
|
22 |
|
|
|
31 |
# st.text(k)
|
32 |
|
33 |
with st.sidebar:
|
34 |
+
# cols0 = st.columns(8)
|
35 |
+
# for i in range(len(cols0)):
|
36 |
+
# with cols0[i]:
|
37 |
+
# # buttons[chr(65 + i)] = st.button(chr(65 + i))
|
38 |
+
# buttons[chr(65 + i)] = button(chr(65 + i), key=chr(65 + i))
|
39 |
+
# cols1 = st.columns(8)
|
40 |
+
# for i in range(len(cols1)):
|
41 |
+
# with cols1[i]:
|
42 |
+
# # buttons[chr(65 + 8 + i)] = st.button(chr(65 + 8 + i))
|
43 |
+
# buttons[chr(65 + 8 + i)] = button(chr(65 + 8 + i), key=chr(65 + 8 + i))
|
44 |
+
# cols2 = st.columns(8)
|
45 |
+
# for i in range(len(cols2)):
|
46 |
+
# with cols2[i]:
|
47 |
+
# # buttons[chr(65 + 16 + i)] = st.button(chr(65 + 16 + i))
|
48 |
+
# buttons[chr(65 + 16 + i)] = button(chr(65 + 16 + i), key=chr(65 + 16 + i))
|
49 |
+
# cols3 = st.columns(8)
|
50 |
+
# for i in range(2):
|
51 |
+
# with cols3[i]:
|
52 |
+
# # buttons[chr(65 + 24 + i)] = st.button(chr(65 + 24 + i))
|
53 |
+
# buttons[chr(65 + 24 + i)] = button(chr(65 + 24 + i), key=chr(65 + 24 + i))
|
54 |
+
# cols4 = st.columns(2)
|
55 |
+
# buttons['0-9'] = cols4[0].button('0-9')
|
56 |
+
# buttons['Others'] = cols4[1].button('Others')
|
57 |
+
select = st.radio(
|
58 |
+
"Select initial to browse.",
|
59 |
+
[chr(i) for i in range(97, 123)] + ['0-9', 'Others'],
|
60 |
+
key="nokeyjustselect",
|
61 |
+
)
|
62 |
+
|
63 |
+
if select == '0-9':
|
64 |
+
st.title(select)
|
65 |
+
file_names = ['num_dict.pkl']
|
66 |
+
elif select == 'Others':
|
67 |
+
st.title(select)
|
68 |
+
file_names = ['other_dict.pkl']
|
69 |
+
elif ord(select[0]) in list(range(97, 123)) + list(range(65, 91)):
|
70 |
+
st.title(chr(ord(select)))
|
71 |
+
file_names = [f'{ord(select[0]) - 32}_dict.pkl', f'{ord(select[0])}_dict.pkl']
|
72 |
+
all_data = {}
|
73 |
+
all_key = []
|
74 |
+
for file_name in file_names:
|
75 |
+
_data = pickle.load(open(f'all_secret_langauge_by_fist/{file_name}', 'rb'))
|
76 |
+
all_data.update(_data)
|
77 |
+
all_key.extend(sorted(list(_data.keys())))
|
78 |
+
# st.markdown(file_name, unsafe_allow_html=True)
|
79 |
+
# st.markdown(_data.keys(), unsafe_allow_html=True)
|
80 |
+
|
81 |
+
all_key = sorted(list(set(all_key)))
|
82 |
+
# st.markdown(','.join(all_key))
|
83 |
+
for key in all_key:
|
84 |
+
# if len(key) and key[0] != '"':
|
85 |
+
# st.markdown(key, unsafe_allow_html=True)
|
86 |
+
# st.change_page("home")
|
87 |
+
# st.markdown(f'<a href="Dictionary_(Search)?word={key}" target="_self">{key}</a>', unsafe_allow_html=True)
|
88 |
+
# print(key)
|
89 |
+
# word_buttons.append(st.button(f'{key}', key=key))
|
90 |
+
_button = st.button(f'{key}', key=key)
|
91 |
+
if _button:
|
92 |
+
st.session_state.click_word = key
|
93 |
+
switch_page("dictionary (search)")
|
94 |
+
|
95 |
|
96 |
+
# # all_condition = False
|
97 |
+
# word_buttons = None
|
98 |
+
# for k in buttons:
|
99 |
+
# if buttons[k]:
|
100 |
+
# word_buttons = []
|
101 |
+
# if k == '0-9':
|
102 |
+
# st.title(k)
|
103 |
+
# file_names = ['num_dict.pkl']
|
104 |
+
# elif k == 'Others':
|
105 |
+
# st.title(k)
|
106 |
+
# file_names = ['other_dict.pkl']
|
107 |
+
# elif ord(k[0]) in list(range(97, 123)) + list(range(65, 91)):
|
108 |
+
# st.title(chr(ord(k)))
|
109 |
+
# file_names = [f'{ord(k[0]) + 32}_dict.pkl', f'{ord(k[0])}_dict.pkl']
|
110 |
+
# all_data = {}
|
111 |
+
# all_key = []
|
112 |
+
# for file_name in file_names:
|
113 |
+
# _data = pickle.load(open(f'all_secret_langauge_by_fist/{file_name}', 'rb'))
|
114 |
+
# all_data.update(_data)
|
115 |
+
# all_key.extend(sorted(list(_data.keys())))
|
116 |
+
# # st.markdown(file_name, unsafe_allow_html=True)
|
117 |
+
# # st.markdown(_data.keys(), unsafe_allow_html=True)
|
118 |
+
#
|
119 |
+
# all_key = list(set(all_key))
|
120 |
+
# st.markdown(','.join(all_key))
|
121 |
+
# for key in all_key:
|
122 |
+
# # if len(key) and key[0] != '"':
|
123 |
+
# # st.markdown(key, unsafe_allow_html=True)
|
124 |
+
# # st.change_page("home")
|
125 |
+
# # st.markdown(f'<a href="Dictionary_(Search)?word={key}" target="_self">{key}</a>', unsafe_allow_html=True)
|
126 |
+
# # print(key)
|
127 |
+
# # word_buttons.append(st.button(f'{key}', key=key))
|
128 |
+
# _button = st.button(f'{key}', key=key)
|
129 |
+
# if _button:
|
130 |
+
# st.session_state.click_word = key
|
131 |
+
# # switch_page("dictionary (search)")
|
132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
+
# for _button in word_buttons:
|
135 |
+
# if _button:
|
136 |
+
# # st.session_state.click_word = key
|
137 |
+
# # st.markdown('asdfd')
|
138 |
+
# switch_page("home")
|
139 |
# with st.expander(key):
|
140 |
# st.markdown(':red[Secret Languages:' + ','.join(all_data[key]['secret languages']), unsafe_allow_html=True)
|
141 |
|