QIDNLF commited on
Commit
d2dfd57
Β·
verified Β·
1 Parent(s): 4095663

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -8
app.py CHANGED
@@ -152,19 +152,99 @@ def display_data(standard, version, selection):
152
 
153
  # 4️⃣ UI ꡬ성
154
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
 
155
  gr.Markdown("# πŸ“œ Regulation Viewer")
156
 
157
  with gr.Row():
158
- standard_dd = gr.Dropdown(label="1. λ²•κ·œ 선택")
159
- version_dd = gr.Dropdown(label="2. Version 선택")
160
- category_dd = gr.Dropdown(label="3. Category / Table 선택")
161
 
162
- output_df = gr.Dataframe(wrap=True, interactive=False, datatype="html")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
 
164
- demo.load(on_load, None, standard_dd)
165
- standard_dd.change(update_version_dd, standard_dd, version_dd)
166
- version_dd.change(update_category_dd, [standard_dd, version_dd], category_dd)
167
- category_dd.change(display_data, [standard_dd, version_dd, category_dd], output_df)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
 
169
  if __name__ == "__main__":
170
  demo.launch()
 
152
 
153
  # 4️⃣ UI ꡬ성
154
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
155
+
156
  gr.Markdown("# πŸ“œ Regulation Viewer")
157
 
158
  with gr.Row():
 
 
 
159
 
160
+ # πŸ‘‰ μ™Όμͺ½ μ˜μ—­ (κΈ°μ€€ + 비ꡐ)
161
+ with gr.Column(scale=1):
162
+
163
+ # βœ… κΈ°μ€€ λ²•κ·œ
164
+ with gr.Group():
165
+ gr.Markdown("### πŸ“Œ κΈ°μ€€ λ²•κ·œ")
166
+ base_standard = gr.Dropdown(label="Standard")
167
+ base_version = gr.Dropdown(label="Version")
168
+ base_category = gr.Dropdown(label="Category")
169
+
170
+ # βœ… 비ꡐ λ²•κ·œ
171
+ with gr.Group():
172
+ gr.Markdown("### πŸ”„ 비ꡐ λ²•κ·œ")
173
+ comp_standard = gr.Dropdown(label="Standard")
174
+ comp_version = gr.Dropdown(label="Version")
175
+ comp_category = gr.Dropdown(label="Category")
176
+
177
+ # πŸ‘‰ 였λ₯Έμͺ½ κ²°κ³Ό μ˜μ—­
178
+ with gr.Column(scale=3):
179
+ gr.Markdown("### πŸ“Š λ‚΄μš©")
180
+ output_df = gr.Dataframe(
181
+ wrap=True,
182
+ interactive=False,
183
+ datatype="html",
184
+ height=700
185
+ )
186
+
187
+ # πŸ‘‰ λ²„νŠΌ (ν•˜λ‚˜λ§Œ)
188
+ with gr.Row():
189
+ search_btn = gr.Button("πŸ” 쑰회", size="lg")
190
+
191
+ # --------------------------
192
+ # πŸ”₯ λ“œλ‘­λ‹€μš΄ 이벀트 (κΈ°μ‘΄ μœ μ§€)
193
+ # --------------------------
194
+ demo.load(on_load, None, base_standard)
195
+ demo.load(on_load, None, comp_standard)
196
+
197
+ base_standard.change(update_version_dd, base_standard, base_version)
198
+ base_version.change(update_category_dd, [base_standard, base_version], base_category)
199
 
200
+ comp_standard.change(update_version_dd, comp_standard, comp_version)
201
+ comp_version.change(update_category_dd, [comp_standard, comp_version], comp_category)
202
+
203
+ # --------------------------
204
+ # πŸ”₯ 쑰회 둜직 (핡심)
205
+ # --------------------------
206
+ def unified_search(bs, bv, bc, cs, cv, cc):
207
+
208
+ # βœ… κΈ°μ€€λ§Œ μ„ νƒλœ 경우
209
+ if bs and bv and bc and not (cs and cv and cc):
210
+ return display_data(bs, bv, bc)
211
+
212
+ # βœ… κΈ°μ€€ + 비ꡐ λ‘˜ λ‹€ μ„ νƒλœ 경우
213
+ if bs and bv and bc and cs and cv and cc:
214
+ df_base = display_data(bs, bv, bc)
215
+ df_comp = display_data(cs, cv, cc)
216
+
217
+ # πŸ”₯ section κΈ°μ€€ outer merge
218
+ if df_base is None or df_comp is None:
219
+ return None
220
+
221
+ try:
222
+ merged = pd.merge(
223
+ df_base,
224
+ df_comp,
225
+ on="section",
226
+ how="outer",
227
+ suffixes=("_base", "_comp")
228
+ )
229
+
230
+ return merged
231
+
232
+ except Exception as e:
233
+ return pd.DataFrame({"Error": [str(e)]})
234
+
235
+ # ❌ 아무것도 μ•ˆ 선택
236
+ return pd.DataFrame({"Info": ["선택을 μ™„λ£Œν•˜μ„Έμš”"]})
237
+
238
+ # πŸ‘‰ λ²„νŠΌ 클릭 μ‹œ μ‹€ν–‰
239
+ search_btn.click(
240
+ unified_search,
241
+ [base_standard, base_version, base_category,
242
+ comp_standard, comp_version, comp_category],
243
+ output_df
244
+ )
245
+
246
+ if __name__ == "__main__":
247
+ demo.launch()
248
 
249
  if __name__ == "__main__":
250
  demo.launch()