Spaces:
Runtime error
Runtime error
anonymousauthors
commited on
Commit
β’
379719e
1
Parent(s):
91b1515
Delete pages/1_π_Dictionary_(Browse).py
Browse files
pages/1_π_Dictionary_(Browse).py
DELETED
@@ -1,175 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
-
# import gdown
|
4 |
-
import os
|
5 |
-
import pickle
|
6 |
-
from streamlit import session_state as _state
|
7 |
-
|
8 |
-
from PyDictionary import PyDictionary
|
9 |
-
from streamlit_extras.colored_header import colored_header
|
10 |
-
|
11 |
-
dictionary = PyDictionary()
|
12 |
-
|
13 |
-
st.set_page_config(layout="wide", page_title="ACl23 Secret Language")
|
14 |
-
from streamlit_extras.switch_page_button import switch_page
|
15 |
-
from streamlit_extras.stateful_button import button
|
16 |
-
# for key in st.session_state.keys():
|
17 |
-
# del st.session_state[key]
|
18 |
-
# st.markdown(st.session_state)
|
19 |
-
# want_to_contribute = st.button("I want to contribute!")
|
20 |
-
# if want_to_contribute:
|
21 |
-
# # switch_page("dictionary (search)")
|
22 |
-
# switch_page("home")
|
23 |
-
|
24 |
-
# st.title("ACl23 Secret Language")
|
25 |
-
|
26 |
-
# sidebar
|
27 |
-
st.sidebar.header("π Dictionary (Browse)")
|
28 |
-
# title = st.sidebar.text_input(":red[Search secret languages given the following word]", 'Asian')
|
29 |
-
buttons = {}
|
30 |
-
|
31 |
-
# def call_back():
|
32 |
-
# for k in buttons:
|
33 |
-
# if buttons[k]:
|
34 |
-
# st.text(k)
|
35 |
-
|
36 |
-
with st.sidebar:
|
37 |
-
cols0 = st.columns(8)
|
38 |
-
for i in range(len(cols0)):
|
39 |
-
with cols0[i]:
|
40 |
-
buttons[chr(65 + i)] = st.button(chr(65 + i))
|
41 |
-
# buttons[chr(65 + i)] = button(chr(65 + i), key=chr(65 + i))
|
42 |
-
cols1 = st.columns(8)
|
43 |
-
for i in range(len(cols1)):
|
44 |
-
with cols1[i]:
|
45 |
-
buttons[chr(65 + 8 + i)] = st.button(chr(65 + 8 + i))
|
46 |
-
# buttons[chr(65 + 8 + i)] = button(chr(65 + 8 + i), key=chr(65 + 8 + i))
|
47 |
-
cols2 = st.columns(8)
|
48 |
-
for i in range(len(cols2)):
|
49 |
-
with cols2[i]:
|
50 |
-
buttons[chr(65 + 16 + i)] = st.button(chr(65 + 16 + i))
|
51 |
-
# buttons[chr(65 + 16 + i)] = button(chr(65 + 16 + i), key=chr(65 + 16 + i))
|
52 |
-
cols3 = st.columns(8)
|
53 |
-
for i in range(2):
|
54 |
-
with cols3[i]:
|
55 |
-
buttons[chr(65 + 24 + i)] = st.button(chr(65 + 24 + i))
|
56 |
-
# buttons[chr(65 + 24 + i)] = button(chr(65 + 24 + i), key=chr(65 + 24 + i))
|
57 |
-
cols4 = st.columns(2)
|
58 |
-
buttons['0-9'] = cols4[0].button('0-9')
|
59 |
-
buttons['Others'] = cols4[1].button('Others')
|
60 |
-
# select = st.radio(
|
61 |
-
# "Select initial to browse.",
|
62 |
-
# [chr(i) for i in range(97, 123)] + ['0-9', 'Others'],
|
63 |
-
# key="nokeyjustselect",
|
64 |
-
# )
|
65 |
-
|
66 |
-
# if select == '0-9':
|
67 |
-
# st.title(select)
|
68 |
-
# file_names = ['num_dict.pkl']
|
69 |
-
# elif select == 'Others':
|
70 |
-
# st.title(select)
|
71 |
-
# file_names = ['other_dict.pkl']
|
72 |
-
# elif ord(select[0]) in list(range(97, 123)) + list(range(65, 91)):
|
73 |
-
# st.title(chr(ord(select)))
|
74 |
-
# file_names = [f'{ord(select[0]) - 32}_dict.pkl', f'{ord(select[0])}_dict.pkl']
|
75 |
-
# all_data = {}
|
76 |
-
# all_key = []
|
77 |
-
# for file_name in file_names:
|
78 |
-
# _data = pickle.load(open(f'all_secret_langauge_by_fist/{file_name}', 'rb'))
|
79 |
-
# all_data.update(_data)
|
80 |
-
# all_key.extend(sorted(list(_data.keys())))
|
81 |
-
# # st.markdown(file_name, unsafe_allow_html=True)
|
82 |
-
# # st.markdown(_data.keys(), unsafe_allow_html=True)
|
83 |
-
|
84 |
-
# all_key = sorted(list(set(all_key)))
|
85 |
-
# # st.markdown(','.join(all_key))
|
86 |
-
# for key in all_key:
|
87 |
-
# # if len(key) and key[0] != '"':
|
88 |
-
# # st.markdown(key, unsafe_allow_html=True)
|
89 |
-
# # st.change_page("home")
|
90 |
-
# # st.markdown(f'<a href="Dictionary_(Search)?word={key}" target="_self">{key}</a>', unsafe_allow_html=True)
|
91 |
-
# # print(key)
|
92 |
-
# # word_buttons.append(st.button(f'{key}', key=key))
|
93 |
-
# _button = st.button(f'{key}', key=key)
|
94 |
-
# if _button:
|
95 |
-
# st.session_state.click_word = key
|
96 |
-
# switch_page("dictionary (search)")
|
97 |
-
|
98 |
-
|
99 |
-
# st.markdown(st.session_state)
|
100 |
-
all_word_button = {}
|
101 |
-
# for key in all_word_button:
|
102 |
-
# if all_word_button[key]:
|
103 |
-
# st.session_state.click_word = key
|
104 |
-
# switch_page("dictionary (search)")
|
105 |
-
for k in st.session_state.keys():
|
106 |
-
if st.session_state[k]:
|
107 |
-
if 'button_' in k:
|
108 |
-
st.session_state.click_word = k.split('button_')[-1]
|
109 |
-
# st.markdown(k)
|
110 |
-
switch_page("dictionary (search)")
|
111 |
-
|
112 |
-
# all_condition = False
|
113 |
-
word_buttons = None
|
114 |
-
|
115 |
-
for k in buttons:
|
116 |
-
if buttons[k]:
|
117 |
-
# for _k in buttons:
|
118 |
-
# if _k != k:
|
119 |
-
# st.session_state[_k] = False
|
120 |
-
|
121 |
-
word_buttons = []
|
122 |
-
if k == '0-9':
|
123 |
-
# st.title(k)
|
124 |
-
colored_header(
|
125 |
-
label=k,
|
126 |
-
description="",
|
127 |
-
color_name="violet-70",
|
128 |
-
)
|
129 |
-
file_names = ['num_dict.pkl']
|
130 |
-
elif k == 'Others':
|
131 |
-
# st.title(k)
|
132 |
-
colored_header(
|
133 |
-
label=k,
|
134 |
-
description="",
|
135 |
-
color_name="violet-70",
|
136 |
-
)
|
137 |
-
file_names = ['other_dict.pkl']
|
138 |
-
elif ord(k[0]) in list(range(97, 123)) + list(range(65, 91)):
|
139 |
-
# st.title(chr(ord(k)))
|
140 |
-
colored_header(
|
141 |
-
label=chr(ord(k)),
|
142 |
-
description="",
|
143 |
-
color_name="violet-70",
|
144 |
-
)
|
145 |
-
file_names = [f'{ord(k[0]) + 32}_dict.pkl', f'{ord(k[0])}_dict.pkl']
|
146 |
-
all_data = {}
|
147 |
-
all_key = []
|
148 |
-
for file_name in file_names:
|
149 |
-
_data = pickle.load(open(f'all_secret_langauge_by_fist/{file_name}', 'rb'))
|
150 |
-
all_data.update(_data)
|
151 |
-
all_key.extend(sorted(list(_data.keys())))
|
152 |
-
# st.markdown(file_name, unsafe_allow_html=True)
|
153 |
-
# st.markdown(_data.keys(), unsafe_allow_html=True)
|
154 |
-
|
155 |
-
all_key = sorted(list(set(all_key)))
|
156 |
-
# st.markdown(','.join(all_key))
|
157 |
-
for key in all_key:
|
158 |
-
# if len(key) and key[0] != '"':
|
159 |
-
# st.markdown(key, unsafe_allow_html=True)
|
160 |
-
# st.change_page("home")
|
161 |
-
# st.markdown(f'<a href="Dictionary_(Search)?word={key}" target="_self">{key}</a>', unsafe_allow_html=True)
|
162 |
-
# print(key)
|
163 |
-
# word_buttons.append(st.button(f'{key}', key=key))
|
164 |
-
all_word_button[key] = st.button(f'{key}', key=f'button_{key}')
|
165 |
-
# all_word_button[key] = button(f'{key}', key=key)
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
# for _button in word_buttons:
|
170 |
-
# if _button:
|
171 |
-
# # st.session_state.click_word = key
|
172 |
-
# # st.markdown('asdfd')
|
173 |
-
# switch_page("home")
|
174 |
-
# with st.expander(key):
|
175 |
-
# st.markdown(':red[Secret Languages:' + ','.join(all_data[key]['secret languages']), unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|