Update app.py
Browse files
app.py
CHANGED
@@ -3,61 +3,98 @@ import json
|
|
3 |
import streamlit as st
|
4 |
from pyserini.search.lucene import LuceneSearcher
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import streamlit as st
|
4 |
from pyserini.search.lucene import LuceneSearcher
|
5 |
|
6 |
+
|
7 |
+
class SearchApplication:
|
8 |
+
def __init__(self):
|
9 |
+
self.title = "Awesome Japanese NLP resources search"
|
10 |
+
|
11 |
+
self.set_page_config()
|
12 |
+
self.searcher = self.set_searcher()
|
13 |
+
|
14 |
+
st.header(self.title)
|
15 |
+
col1, col2 = st.columns(2)
|
16 |
+
with col1:
|
17 |
+
self.query = st.text_input(
|
18 |
+
"Search English or Japanese words", value=""
|
19 |
+
)
|
20 |
+
|
21 |
+
with col2:
|
22 |
+
st.write("#")
|
23 |
+
self.search_button = st.button("π")
|
24 |
+
|
25 |
+
st.caption(
|
26 |
+
"You can search for open-source software from [400+ Japanese NLP"
|
27 |
+
" repositories](https://github.com/taishi-i/awesome-japanese-nlp-resources)."
|
28 |
+
)
|
29 |
+
st.write("#")
|
30 |
+
|
31 |
+
self.show_popular_words()
|
32 |
+
self.show_search_results()
|
33 |
+
|
34 |
+
def set_page_config(self):
|
35 |
+
st.set_page_config(
|
36 |
+
page_title=self.title,
|
37 |
+
page_icon="π",
|
38 |
+
layout="centered",
|
39 |
+
)
|
40 |
+
|
41 |
+
def set_searcher(self):
|
42 |
+
searcher = LuceneSearcher("indexes/docs")
|
43 |
+
searcher.set_language("ja")
|
44 |
+
return searcher
|
45 |
+
|
46 |
+
def show_popular_words(self):
|
47 |
+
st.caption("Popular words")
|
48 |
+
|
49 |
+
word1, word2, word3, word4, _ = st.columns(5)
|
50 |
+
with word1:
|
51 |
+
button1 = st.button("Python")
|
52 |
+
if button1:
|
53 |
+
self.query = "Python"
|
54 |
+
|
55 |
+
with word2:
|
56 |
+
button2 = st.button("BERT")
|
57 |
+
if button2:
|
58 |
+
self.query = "BERT"
|
59 |
+
|
60 |
+
with word3:
|
61 |
+
button3 = st.button("θΎζΈ")
|
62 |
+
if button3:
|
63 |
+
self.query = "θΎζΈ"
|
64 |
+
|
65 |
+
with word4:
|
66 |
+
button4 = st.button("γ³γΌγγΉ")
|
67 |
+
if button4:
|
68 |
+
self.query = "Corpus"
|
69 |
+
|
70 |
+
def show_search_results(self):
|
71 |
+
if self.query or self.search_button:
|
72 |
+
st.write("#")
|
73 |
+
|
74 |
+
search_results = self.searcher.search(self.query, k=500)
|
75 |
+
num_search_results = len(search_results)
|
76 |
+
st.write(f"{num_search_results} results")
|
77 |
+
|
78 |
+
for result in search_results:
|
79 |
+
data_json = json.loads(result.raw)
|
80 |
+
description = data_json["description"]
|
81 |
+
url = data_json["url"]
|
82 |
+
project_name = data_json["project_name"]
|
83 |
+
main_topic = data_json["main_topic"]
|
84 |
+
sub_topic = data_json["sub_topic"]
|
85 |
+
|
86 |
+
st.subheader(f"[{project_name}]({url})")
|
87 |
+
st.markdown(description)
|
88 |
+
if sub_topic is None:
|
89 |
+
st.caption(f"{main_topic}")
|
90 |
+
else:
|
91 |
+
st.caption(f"{main_topic} / {sub_topic}")
|
92 |
+
st.write("#")
|
93 |
+
|
94 |
+
|
95 |
+
def main():
|
96 |
+
SearchApplication()
|
97 |
+
|
98 |
+
|
99 |
+
if __name__ == "__main__":
|
100 |
+
main()
|