SecretLanguage / pages /1_πŸ“™_Dictionary_(Browse).py
anonymousauthors
Update pages/1_πŸ“™_Dictionary_(Browse).py
000490a
raw
history blame
No virus
3.91 kB
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
dictionary=PyDictionary()
st.set_page_config(layout="wide", page_title="ACl23 Secret Language")
from streamlit.components.v1 import html
def nav_page(page_name, timeout_secs=3):
nav_script = """
<script type="text/javascript">
function attempt_nav_page(page_name, start_time, timeout_secs) {
var links = window.parent.document.getElementsByTagName("a");
for (var i = 0; i < links.length; i++) {
if (links[i].href.toLowerCase().endsWith("/" + page_name.toLowerCase())) {
links[i].click();
return;
}
}
var elasped = new Date() - start_time;
if (elasped < timeout_secs * 1000) {
setTimeout(attempt_nav_page, 100, page_name, start_time, timeout_secs);
} else {
alert("Unable to navigate to page '" + page_name + "' after " + timeout_secs + " second(s).");
}
}
window.addEventListener("load", function() {
attempt_nav_page("%s", new Date(), %d);
});
</script>
""" % (page_name, timeout_secs)
html(nav_script)
if st.button("< Prev"):
nav_page("πŸ“™_Dictionary_(Search)")
# 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:
st.markdown(f'<a href="Dictionary_Search" target="_self">gogogo</a>', unsafe_allow_html=True)
cols0 = st.columns(8)
for i in range(len(cols0)):
with cols0[i]:
buttons[chr(65 + i)] = st.button(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))
cols2 = st.columns(8)
for i in range(len(cols2)):
with cols2[i]:
buttons[chr(65 + 16 + i)] = st.button(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))
cols4 = st.columns(2)
buttons['0-9'] = cols4[0].button('0-9')
buttons['Others'] = cols4[1].button('Others')
# all_condition = False
for k in buttons:
if buttons[k]:
if k == '0-9':
st.title(k)
file_names = ['num_dict.pkl']
elif k == 'Others':
st.title(k)
file_names = ['other_dict.pkl']
elif ord(k[0]) in list(range(97, 123)) + list(range(65, 91)):
st.title(chr(ord(k)))
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 = list(set(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)
# with st.expander(key):
# st.markdown(':red[Secret Languages:' + ','.join(all_data[key]['secret languages']), unsafe_allow_html=True)