-
Notifications
You must be signed in to change notification settings - Fork 2
/
streamlitapp.py
104 lines (77 loc) · 2.5 KB
/
streamlitapp.py
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
import streamlit as st
import streamlit.components.v1 as components
from EmojiFinder import EmojiFinderSql
st.set_page_config(page_title="Emoji Finder", )
st.title('Semantic Emoji Search')
st.markdown(
"Also try [the Dash Version](https://marcoshuerta.com/dash/emoji_finder/) for more options and persistent settings. Source code and more info on [Github](https://github.com/astrowonk/emoji_finder)."
)
@st.cache_data(ttl=3600)
def make_class():
return EmojiFinderSql()
e = make_class()
search = st.text_input("Search")
col1, col2 = st.columns(2)
# Auto focus on input
components.html(f"""
<script>
var input = window.parent.document.querySelector("input[type=text]");
input.focus();
</script>
""",
width=10,
height=0)
st.markdown("""
<style>
div[data-testid="column"]:nth-of-type(1)
{
text-align: center;
align-self: center;
}
div[data-testid="column"]:nth-of-type(2)
{
text-align: center;
}
h1, h3 {
padding-top: 0px;
}
div[data-testid="stVerticalBlock"] {
gap: 0em;
display: inline;
}
pre {
margin-top: 1em !important;
margin-bottom: 1em !important;
}
div[data-testid="stText"] {
margin-top: 1em !important;
margin-bottom: 1em !important;
}
div.block-container {
padding: 3rem 1rem 10rem;
}
</style>
""",
unsafe_allow_html=True)
if search:
st.subheader("Results:")
full_res = e.top_emojis(search)
if not full_res.empty:
res_list = full_res.to_dict('records')
variants = []
for rec in res_list:
variants.extend(e.add_variants(rec['label']))
## remove variants from list
full_res = full_res.query("label not in @variants")
for item in full_res.to_dict('records'):
with st.container():
col1, col2 = st.columns(2)
with col1:
st.text(item['text'])
with col2:
st.code(item['emoji'])
additional_emojis = e.add_variants(item['label'])
with st.expander("See More:"):
for x in additional_emojis:
st.code(e.emoji_dict[x]['emoji'])
st.text(e.emoji_dict[x]['text'])