Spaces:
Build error
Build error
Mya-Mya
commited on
Commit
•
0093e01
1
Parent(s):
53c9b7f
Update frontend.py
Browse files- frontend.py +88 -14
frontend.py
CHANGED
@@ -1,15 +1,89 @@
|
|
1 |
-
from gradio import
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
with Blocks() as frontend:
|
5 |
-
Markdown(""
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from gradio import (
|
2 |
+
update,
|
3 |
+
Blocks,
|
4 |
+
Row,
|
5 |
+
Examples,
|
6 |
+
Group,
|
7 |
+
Markdown,
|
8 |
+
Textbox,
|
9 |
+
Button,
|
10 |
+
Tabs,
|
11 |
+
TabItem,
|
12 |
+
DataFrame as GRDataFrame,
|
13 |
+
)
|
14 |
+
from ambiguous_search_backends import AmbiguousSearchBackend
|
15 |
+
from classic_search_backends import ClassicSearchBackend
|
16 |
+
|
17 |
+
|
18 |
+
def launch_frontend(
|
19 |
+
ambiguous_search_backend: AmbiguousSearchBackend,
|
20 |
+
classic_search_backend: ClassicSearchBackend,
|
21 |
+
):
|
22 |
+
def on_ambiguous_search_click(query: str):
|
23 |
+
result = ambiguous_search_backend.submit(query)
|
24 |
+
return GRDataFrame.update(value=result, visible=True)
|
25 |
+
|
26 |
+
def on_ambiguous_search_query_clear_click():
|
27 |
+
return Textbox.update(value="")
|
28 |
+
|
29 |
+
def on_classic_search_click(query: str):
|
30 |
+
result = classic_search_backend.submit(query)
|
31 |
+
return GRDataFrame.update(value=result, visible=True)
|
32 |
+
|
33 |
with Blocks() as frontend:
|
34 |
+
Markdown("## Himitsudogu Search")
|
35 |
+
with Tabs():
|
36 |
+
with TabItem("あいまい検索"):
|
37 |
+
Markdown(
|
38 |
+
"""
|
39 |
+
自然言語処理モデル"Sentence BERT"を使って、ドラえもんのひみつ道具をあいまい検索。
|
40 |
+
"""
|
41 |
+
)
|
42 |
+
query_textbox = Textbox(
|
43 |
+
label="自分の言葉でひみつ道具を説明してください", max_lines=1
|
44 |
+
)
|
45 |
+
with Row():
|
46 |
+
submit_button = Button("検索", variant="primary")
|
47 |
+
clear_button = Button("クリア")
|
48 |
+
result_table = GRDataFrame(visible=False)
|
49 |
+
Examples(
|
50 |
+
examples=[
|
51 |
+
"ふりかけると水を色々な性質にできる",
|
52 |
+
"小さいカメラが飛ぶ",
|
53 |
+
"壁を通り抜けられるようにする輪",
|
54 |
+
"地図をいじって実際の町の建物などの位置を変える",
|
55 |
+
"歌声を綺麗にする",
|
56 |
+
],
|
57 |
+
inputs=query_textbox,
|
58 |
+
)
|
59 |
+
|
60 |
+
submit_button.click(
|
61 |
+
on_ambiguous_search_click,
|
62 |
+
inputs=query_textbox,
|
63 |
+
outputs=result_table,
|
64 |
+
)
|
65 |
+
clear_button.click(
|
66 |
+
on_ambiguous_search_query_clear_click,
|
67 |
+
inputs=None,
|
68 |
+
outputs=query_textbox,
|
69 |
+
)
|
70 |
+
|
71 |
+
with TabItem("古典検索"):
|
72 |
+
Markdown(
|
73 |
+
f"""
|
74 |
+
キーワードから検索。
|
75 |
+
検索可能なひみつ道具は全{classic_search_backend.get_num_items()}種類。
|
76 |
+
"""
|
77 |
+
)
|
78 |
+
query_textbox = Textbox(label="キーワード", max_lines=1)
|
79 |
+
with Row():
|
80 |
+
submit_button = Button("検索", variant="primary")
|
81 |
+
result_table = GRDataFrame(visible=False)
|
82 |
+
|
83 |
+
submit_button.click(
|
84 |
+
on_classic_search_click,
|
85 |
+
inputs=query_textbox,
|
86 |
+
outputs=result_table,
|
87 |
+
)
|
88 |
+
|
89 |
+
frontend.launch()
|