File size: 6,212 Bytes
701f8ff
 
6437e07
701f8ff
 
 
 
 
5a5f4eb
a3fb811
 
701f8ff
 
ec80e89
a3fb811
75d0a70
 
 
a3fb811
 
 
 
701f8ff
 
 
 
 
 
 
 
 
 
 
 
 
 
75d0a70
 
 
3e701f9
 
75d0a70
 
 
3e701f9
 
75d0a70
 
 
3e701f9
 
75d0a70
 
 
3e701f9
 
75d0a70
 
 
 
 
 
 
 
a3fb811
75d0a70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a3fb811
75d0a70
 
 
 
 
 
 
 
 
 
 
 
 
a3fb811
701f8ff
3e701f9
 
 
 
 
 
 
b00878a
 
 
 
 
3e701f9
75d0a70
 
3e701f9
75d0a70
 
3e701f9
 
 
75d0a70
 
 
5a5f4eb
 
 
 
 
 
75d0a70
 
5a5f4eb
 
 
 
 
 
75d0a70
 
5a5f4eb
 
 
 
 
 
75d0a70
 
 
 
 
 
 
 
 
 
b00878a
75d0a70
 
 
 
 
 
 
 
3e701f9
75d0a70
701f8ff
 
b00878a
a3fb811
 
 
 
 
701f8ff
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import streamlit as st
import pandas as pd
# import gdown
import os
import pickle
from streamlit import session_state as _state

from PyDictionary import PyDictionary
from streamlit_extras.colored_header import colored_header

dictionary = PyDictionary()

st.set_page_config(layout="wide", page_title="ACl23 Secret Language")
from streamlit_extras.switch_page_button import switch_page
from streamlit_extras.stateful_button import button
# for key in st.session_state.keys():
    # del st.session_state[key]
# st.markdown(st.session_state)
# want_to_contribute = st.button("I want to contribute!")
# if want_to_contribute:
#     # switch_page("dictionary (search)")
#     switch_page("home")

# st.title("ACl23 Secret Language")

# sidebar
st.sidebar.header("πŸ“™ Dictionary (Browse)")
# title = st.sidebar.text_input(":red[Search secret languages given the following word]", 'Asian')
buttons = {}

# def call_back():
#     for k in buttons:
#         if buttons[k]:
#             st.text(k)

with st.sidebar:
    cols0 = st.columns(8)
    for i in range(len(cols0)):
        with cols0[i]:
            buttons[chr(65 + i)] = st.button(chr(65 + i))
            # buttons[chr(65 + i)] = button(chr(65 + i), key=chr(65 + i))
    cols1 = st.columns(8)
    for i in range(len(cols1)):
        with cols1[i]:
            buttons[chr(65 + 8 + i)] = st.button(chr(65 + 8 + i))
            # buttons[chr(65 + 8 + i)] = button(chr(65 + 8 + i), key=chr(65 + 8 + i))
    cols2 = st.columns(8)
    for i in range(len(cols2)):
        with cols2[i]:
            buttons[chr(65 + 16 + i)] = st.button(chr(65 + 16 + i))
            # buttons[chr(65 + 16 + i)] = button(chr(65 + 16 + i), key=chr(65 + 16 + i))
    cols3 = st.columns(8)
    for i in range(2):
        with cols3[i]:
            buttons[chr(65 + 24 + i)] = st.button(chr(65 + 24 + i))
            # buttons[chr(65 + 24 + i)] = button(chr(65 + 24 + i), key=chr(65 + 24 + i))
    cols4 = st.columns(2)
    buttons['0-9'] = cols4[0].button('0-9')
    buttons['Others'] = cols4[1].button('Others')
#     select = st.radio(
#         "Select initial to browse.",
#         [chr(i) for i in range(97, 123)] + ['0-9', 'Others'],
#         key="nokeyjustselect",
#     )

# if select == '0-9':
#     st.title(select)
#     file_names = ['num_dict.pkl']
# elif select == 'Others':
#     st.title(select)
#     file_names = ['other_dict.pkl']
# elif ord(select[0]) in list(range(97, 123)) + list(range(65, 91)):
#     st.title(chr(ord(select)))
#     file_names = [f'{ord(select[0]) - 32}_dict.pkl', f'{ord(select[0])}_dict.pkl']
# all_data = {}
# all_key = []
# for file_name in file_names:
#     _data = pickle.load(open(f'all_secret_langauge_by_fist/{file_name}', 'rb'))
#     all_data.update(_data)
#     all_key.extend(sorted(list(_data.keys())))
#     # st.markdown(file_name, unsafe_allow_html=True)
#     # st.markdown(_data.keys(), unsafe_allow_html=True)

# all_key = sorted(list(set(all_key)))
# # st.markdown(','.join(all_key))
# for key in all_key:
#     # if len(key) and key[0] != '"':
#     #     st.markdown(key, unsafe_allow_html=True)
#     # st.change_page("home")
#     # st.markdown(f'<a href="Dictionary_(Search)?word={key}" target="_self">{key}</a>', unsafe_allow_html=True)
#     # print(key)
#     # word_buttons.append(st.button(f'{key}', key=key))
#     _button = st.button(f'{key}', key=key)
#     if _button:
#         st.session_state.click_word = key
#         switch_page("dictionary (search)")


# st.markdown(st.session_state)
all_word_button = {}
# for key in all_word_button:
    # if all_word_button[key]:
    #     st.session_state.click_word = key
    #     switch_page("dictionary (search)")
for k in st.session_state.keys():
    if st.session_state[k]:
        if 'button_' in k:
            st.session_state.click_word = k.split('button_')[-1]
            # st.markdown(k)
            switch_page("dictionary (search)")

# all_condition = False
word_buttons = None

for k in buttons:
    if buttons[k]:
        # for _k in buttons:
        #     if _k != k:
        #         st.session_state[_k] = False

        word_buttons = []
        if k == '0-9':
            # st.title(k)
            colored_header(
                label=k,
                description="",
                color_name="violet-70",
            )
            file_names = ['num_dict.pkl']
        elif k == 'Others':
            # st.title(k)
            colored_header(
                label=k,
                description="",
                color_name="violet-70",
            )
            file_names = ['other_dict.pkl']
        elif ord(k[0]) in list(range(97, 123)) + list(range(65, 91)):
            # st.title(chr(ord(k)))
            colored_header(
                label=chr(ord(k)),
                description="",
                color_name="violet-70",
            )
            file_names = [f'{ord(k[0]) + 32}_dict.pkl', f'{ord(k[0])}_dict.pkl']
        all_data = {}
        all_key = []
        for file_name in file_names:
            _data = pickle.load(open(f'all_secret_langauge_by_fist/{file_name}', 'rb'))
            all_data.update(_data)
            all_key.extend(sorted(list(_data.keys())))
            # st.markdown(file_name, unsafe_allow_html=True)
            # st.markdown(_data.keys(), unsafe_allow_html=True)

        all_key = sorted(list(set(all_key)))
        # st.markdown(','.join(all_key))
        for key in all_key:
            # if len(key) and key[0] != '"':
            #     st.markdown(key, unsafe_allow_html=True)
            # st.change_page("home")
            # st.markdown(f'<a href="Dictionary_(Search)?word={key}" target="_self">{key}</a>', unsafe_allow_html=True)
            # print(key)
            # word_buttons.append(st.button(f'{key}', key=key))
            all_word_button[key] = st.button(f'{key}', key=f'button_{key}')
            # all_word_button[key] = button(f'{key}', key=key)



# for _button in word_buttons:
#     if _button:
# # st.session_state.click_word = key
# # st.markdown('asdfd')
#         switch_page("home")
            # with st.expander(key):
            #     st.markdown(':red[Secret Languages:' + ','.join(all_data[key]['secret languages']), unsafe_allow_html=True)