Add SearchButton and Links
Browse files
app.py
CHANGED
@@ -61,16 +61,20 @@ class App(GrBlocks):
|
|
61 |
}
|
62 |
}
|
63 |
|
64 |
-
|
65 |
model_dir, label_info_dics, cuisine_df_path, unify_dics_path,
|
66 |
cuisine_infos_num
|
67 |
)
|
68 |
input_samples = InputSamplesDataset()
|
69 |
extracted_words = ExtractedWordsHighlightedText(label_info_dics)
|
|
|
70 |
cuisine_infos = CuisineInfos(cuisine_infos_num)
|
|
|
|
|
|
|
71 |
|
72 |
input_submitted = GrListener(
|
73 |
-
trigger=input.comp.submit,
|
74 |
fn=input.submitted,
|
75 |
inputs=input,
|
76 |
outputs=[extracted_words, cuisine_infos],
|
@@ -84,12 +88,97 @@ class App(GrBlocks):
|
|
84 |
thens=input_submitted
|
85 |
)
|
86 |
|
87 |
-
children = [
|
|
|
|
|
88 |
listeners = [input_submitted, input_samples_selected]
|
89 |
|
90 |
return children, listeners
|
91 |
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
class InputTextbox(GrComponent):
|
94 |
"""
|
95 |
入力欄のクラス
|
@@ -149,7 +238,7 @@ class InputTextbox(GrComponent):
|
|
149 |
"""
|
150 |
label = self._create_label()
|
151 |
placeholder = 'どんな料理をお探しでしょうか?'
|
152 |
-
comp = gr.Textbox(placeholder=placeholder, label=label)
|
153 |
|
154 |
return comp
|
155 |
|
@@ -198,6 +287,24 @@ class InputTextbox(GrComponent):
|
|
198 |
return [pos_tokens] + cuisine_infos
|
199 |
|
200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
class InputSamplesDataset(GrComponent):
|
202 |
"""
|
203 |
入力例のクラス
|
@@ -291,6 +398,39 @@ class ExtractedWordsHighlightedText(GrComponent):
|
|
291 |
return comp
|
292 |
|
293 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
294 |
class CuisineInfos(GrLayout):
|
295 |
"""
|
296 |
全検索結果のクラス
|
@@ -663,7 +803,6 @@ class CuisineSearcher:
|
|
663 |
----------
|
664 |
label_info_dics : Dict[str, str | List[str]]
|
665 |
固有表現のラベルとラベルに対する各種設定情報の辞書
|
666 |
-
|
667 |
Returns
|
668 |
-------
|
669 |
Dict[str, List[str]]
|
|
|
61 |
}
|
62 |
}
|
63 |
|
64 |
+
input_search = InputSearch(
|
65 |
model_dir, label_info_dics, cuisine_df_path, unify_dics_path,
|
66 |
cuisine_infos_num
|
67 |
)
|
68 |
input_samples = InputSamplesDataset()
|
69 |
extracted_words = ExtractedWordsHighlightedText(label_info_dics)
|
70 |
+
links = Links()
|
71 |
cuisine_infos = CuisineInfos(cuisine_infos_num)
|
72 |
+
|
73 |
+
input = input_search.children['input']
|
74 |
+
search_btn = input_search.children['search_btn']
|
75 |
|
76 |
input_submitted = GrListener(
|
77 |
+
trigger=[input.comp.submit, search_btn.comp.click],
|
78 |
fn=input.submitted,
|
79 |
inputs=input,
|
80 |
outputs=[extracted_words, cuisine_infos],
|
|
|
88 |
thens=input_submitted
|
89 |
)
|
90 |
|
91 |
+
children = [
|
92 |
+
input_search, input_samples, extracted_words, links, cuisine_infos
|
93 |
+
]
|
94 |
listeners = [input_submitted, input_samples_selected]
|
95 |
|
96 |
return children, listeners
|
97 |
|
98 |
|
99 |
+
class InputSearch(GrLayout):
|
100 |
+
"""
|
101 |
+
入力欄と検索ボタンのクラス
|
102 |
+
|
103 |
+
Attributes
|
104 |
+
----------
|
105 |
+
layout_type : gr.Row
|
106 |
+
GradioのRow
|
107 |
+
"""
|
108 |
+
layout_type = gr.Row
|
109 |
+
|
110 |
+
def __init__(
|
111 |
+
self,
|
112 |
+
model_dir: str,
|
113 |
+
label_info_dics: Dict[str, str | List[str]],
|
114 |
+
cuisine_df_path: str,
|
115 |
+
unify_dics_path: str,
|
116 |
+
cuisine_infos_num: int
|
117 |
+
):
|
118 |
+
"""
|
119 |
+
コンストラクタ
|
120 |
+
|
121 |
+
Parameters
|
122 |
+
----------
|
123 |
+
model_dir : str
|
124 |
+
ファインチューニング済みモデルが保存されているディレクトリ
|
125 |
+
label_info_dics : Dict[str, str | List[str]]
|
126 |
+
固有表現のラベルとラベルに対する各種設定情報の辞書
|
127 |
+
cuisine_df_path : str
|
128 |
+
料理のデータフレームが保存されているパス
|
129 |
+
unify_dics_path : str
|
130 |
+
表記ゆれ統一用辞書が保存されているパス
|
131 |
+
cuisine_infos_num : int
|
132 |
+
表示する料理検索結果の最大数
|
133 |
+
"""
|
134 |
+
super().__init__(
|
135 |
+
model_dir,
|
136 |
+
label_info_dics,
|
137 |
+
cuisine_df_path,
|
138 |
+
unify_dics_path,
|
139 |
+
cuisine_infos_num
|
140 |
+
)
|
141 |
+
|
142 |
+
def _create(
|
143 |
+
self,
|
144 |
+
model_dir: str,
|
145 |
+
label_info_dics: Dict[str, str | List[str]],
|
146 |
+
cuisine_df_path: str,
|
147 |
+
unify_dics_path: str,
|
148 |
+
cuisine_infos_num: int
|
149 |
+
) -> Dict[str, InputTextbox | SearchButton]:
|
150 |
+
"""
|
151 |
+
子要素の作成
|
152 |
+
|
153 |
+
Parameters
|
154 |
+
----------
|
155 |
+
model_dir : str
|
156 |
+
ファインチューニング済みモデルが保存されているディレクトリ
|
157 |
+
label_info_dics : Dict[str, str | List[str]]
|
158 |
+
固有表現のラベルとラベルに対する各種設定情報の辞書
|
159 |
+
cuisine_df_path : str
|
160 |
+
料理のデータフレームが保存されているパス
|
161 |
+
unify_dics_path : str
|
162 |
+
表記ゆれ統一用辞書が保存されているパス
|
163 |
+
cuisine_infos_num : int
|
164 |
+
表示する料理検索結果の最大数
|
165 |
+
|
166 |
+
Returns
|
167 |
+
-------
|
168 |
+
Dict[str, InputTextbox | SearchButton]
|
169 |
+
入力欄と検索ボタン
|
170 |
+
"""
|
171 |
+
input = InputTextbox(
|
172 |
+
model_dir, label_info_dics, cuisine_df_path, unify_dics_path,
|
173 |
+
cuisine_infos_num
|
174 |
+
)
|
175 |
+
search_btn = SearchButton()
|
176 |
+
|
177 |
+
children = {'input': input, 'search_btn': search_btn}
|
178 |
+
|
179 |
+
return children
|
180 |
+
|
181 |
+
|
182 |
class InputTextbox(GrComponent):
|
183 |
"""
|
184 |
入力欄のクラス
|
|
|
238 |
"""
|
239 |
label = self._create_label()
|
240 |
placeholder = 'どんな料理をお探しでしょうか?'
|
241 |
+
comp = gr.Textbox(placeholder=placeholder, label=label, scale=9)
|
242 |
|
243 |
return comp
|
244 |
|
|
|
287 |
return [pos_tokens] + cuisine_infos
|
288 |
|
289 |
|
290 |
+
class SearchButton(GrComponent):
|
291 |
+
"""
|
292 |
+
検索ボタンのクラス
|
293 |
+
"""
|
294 |
+
def _create(self) -> gr.Button:
|
295 |
+
"""
|
296 |
+
コンポーネントの作成
|
297 |
+
|
298 |
+
Returns
|
299 |
+
-------
|
300 |
+
gr.Button
|
301 |
+
検索ボタンのコンポーネント
|
302 |
+
"""
|
303 |
+
comp = gr.Button(value='🔍', scale=1)
|
304 |
+
|
305 |
+
return comp
|
306 |
+
|
307 |
+
|
308 |
class InputSamplesDataset(GrComponent):
|
309 |
"""
|
310 |
入力例のクラス
|
|
|
398 |
return comp
|
399 |
|
400 |
|
401 |
+
class Links(GrComponent):
|
402 |
+
"""
|
403 |
+
外部リンクのクラス
|
404 |
+
"""
|
405 |
+
def _create(self) -> gr.HTML:
|
406 |
+
"""
|
407 |
+
コンポーネントの作成
|
408 |
+
|
409 |
+
Returns
|
410 |
+
-------
|
411 |
+
gr.HTML
|
412 |
+
外部リンクのコンポーネント
|
413 |
+
"""
|
414 |
+
qiita_link = 'https://qiita.com/wolf4032/items/9dd7423c706fa86bf005'
|
415 |
+
qiita = 'アプリに関する情報(Qiita)'
|
416 |
+
github_link = 'https://github.com/wolf4032/nlp-token-classification/tree/main'
|
417 |
+
github = 'GitHub'
|
418 |
+
|
419 |
+
value = f"""
|
420 |
+
<div style="display: flex; justify-content: center; gap: 20px;">
|
421 |
+
<div style="display: inline-block;">
|
422 |
+
<a href={qiita_link} target="_blank">{qiita}</a>
|
423 |
+
</div>
|
424 |
+
<div style="display: inline-block;">
|
425 |
+
<a href={github_link} target="_blank">{github}</a>
|
426 |
+
</div>
|
427 |
+
</div>
|
428 |
+
"""
|
429 |
+
comp = gr.HTML(value=value)
|
430 |
+
|
431 |
+
return comp
|
432 |
+
|
433 |
+
|
434 |
class CuisineInfos(GrLayout):
|
435 |
"""
|
436 |
全検索結果のクラス
|
|
|
803 |
----------
|
804 |
label_info_dics : Dict[str, str | List[str]]
|
805 |
固有表現のラベルとラベルに対する各種設定情報の辞書
|
|
|
806 |
Returns
|
807 |
-------
|
808 |
Dict[str, List[str]]
|