Update app.py
Browse files
app.py
CHANGED
|
@@ -61,7 +61,6 @@ def fetch_available_standards():
|
|
| 61 |
# ==========================================
|
| 62 |
# 2. UI Component Handlers
|
| 63 |
# ==========================================
|
| 64 |
-
|
| 65 |
def load_initial_standards():
|
| 66 |
return gr.Dropdown(choices=fetch_available_standards())
|
| 67 |
|
|
@@ -221,7 +220,6 @@ def reset_comp_selections():
|
|
| 221 |
# ==========================================
|
| 222 |
# 3. Core Logic & Data Processing
|
| 223 |
# ==========================================
|
| 224 |
-
|
| 225 |
def generate_html_diff(base_text, comp_text):
|
| 226 |
base_text = "" if pd.isna(base_text) else str(base_text)
|
| 227 |
comp_text = "" if pd.isna(comp_text) else str(comp_text)
|
|
@@ -403,14 +401,11 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 403 |
else: new_cols.append(col)
|
| 404 |
return df[new_cols]
|
| 405 |
|
| 406 |
-
# 1. ๋จ์ผ ์กฐํ (์ฌ๊ธฐ์ ์๋ combine_code_desc๋ฅผ ์ญ์ ํ์ต๋๋ค!)
|
| 407 |
if base_std and base_ver and base_cat and (not comp_std or not comp_ver or not comp_cat):
|
| 408 |
df, _ = fetch_database_records(base_std, base_ver, base_cat, type_b)
|
| 409 |
if "Error" in df.columns: return df
|
| 410 |
-
# ์ด์ ๋ถ๋ฆฌ๋ ์ํ ๊ทธ๋๋ก ์ ์งํ๊ณ , ์ค๋ณต ๋น์นธ ์ฒ๋ฆฌ๋ง ์ํ
|
| 411 |
return apply_visual_merge(df, df.columns)
|
| 412 |
|
| 413 |
-
# 2. ๋น๊ต ์กฐํ
|
| 414 |
if all([base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat]):
|
| 415 |
df_base, real_anchors_b = fetch_database_records(base_std, base_ver, base_cat, type_b)
|
| 416 |
df_comp, real_anchors_c = fetch_database_records(comp_std, comp_ver, comp_cat, type_c)
|
|
@@ -487,7 +482,6 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 487 |
else:
|
| 488 |
bridge = df_mapping.copy()
|
| 489 |
|
| 490 |
-
# (์ค๋ณต ์์ฑ๋ rename_b ์ญ์ ์๋ฃ)
|
| 491 |
rename_b = {c: f"{c}_{base_ver}" for c in df_base.columns if c != 'merge_key'}
|
| 492 |
df_base = df_base.rename(columns=rename_b)
|
| 493 |
|
|
@@ -519,7 +513,6 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 519 |
row_dict[rename_b[orig_col]], row_dict[rename_c[orig_col]] = generate_html_diff(b_v, c_v)
|
| 520 |
result_rows.append(row_dict)
|
| 521 |
|
| 522 |
-
# ๋น๊ต ์กฐํ ์์๋ ๋ฒํธ์ ์ค๋ช
์ ํฉ์นฉ๋๋ค
|
| 523 |
final_df = combine_code_desc(pd.DataFrame(result_rows))
|
| 524 |
|
| 525 |
if diff_only:
|
|
@@ -547,12 +540,10 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
|
|
| 547 |
with gr.Blocks() as demo:
|
| 548 |
gr.Markdown("# ๐ Regulation Viewer")
|
| 549 |
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
with gr.Accordion("๐ ๊ธฐ์ค ๋ฒ๊ท", open=True):
|
| 554 |
with gr.Column():
|
| 555 |
-
# ๋ฒํผ์ ์๋ก ์ฌ๋ฆฌ๊ณ ์ฌ์ด์ฆ๋ฅผ ์๊ฒ ๋ง๋ญ๋๋ค
|
| 556 |
base_reset_btn = gr.Button("โบ ๊ธฐ์ค ๋ฒ๊ท ์ด๊ธฐํ", size="sm")
|
| 557 |
base_standard = gr.Dropdown(label="Standard")
|
| 558 |
base_version = gr.Dropdown(label="Version")
|
|
@@ -565,9 +556,15 @@ with gr.Blocks() as demo:
|
|
| 565 |
comp_version = gr.Dropdown(label="Version", choices=[])
|
| 566 |
comp_category = gr.Dropdown(label="Category", choices=[])
|
| 567 |
|
| 568 |
-
|
| 569 |
-
|
| 570 |
search_btn = gr.Button("๐ ์กฐํ", variant="primary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 571 |
output_df = gr.Dataframe(wrap=True, interactive=False, datatype="html", max_height=800)
|
| 572 |
|
| 573 |
demo.load(fn=load_initial_standards, inputs=None, outputs=base_standard)
|
|
@@ -601,7 +598,6 @@ with gr.Blocks() as demo:
|
|
| 601 |
# ==========================================
|
| 602 |
# 5. Application Styling (CSS)
|
| 603 |
# ==========================================
|
| 604 |
-
|
| 605 |
css = """
|
| 606 |
table {
|
| 607 |
table-layout: auto !important;
|
|
@@ -677,21 +673,22 @@ td img {
|
|
| 677 |
display: block;
|
| 678 |
max-width: none !important;
|
| 679 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 680 |
#diff_toggle_row {
|
| 681 |
-
|
|
|
|
| 682 |
margin-top: 5px !important;
|
| 683 |
-
margin-bottom: -15px !important; /* ํ์
|
| 684 |
-
|
| 685 |
}
|
| 686 |
|
| 687 |
#diff_cb_item {
|
| 688 |
-
flex:
|
| 689 |
-
width:
|
| 690 |
-
min-width:
|
| 691 |
-
background: transparent !important; /* ๋ฐฐ๊ฒฝ์ ํฌ๋ช
ํ๊ฒ ํด์ ๊น๋ํ๊ฒ ๋ง๋ญ๋๋ค */
|
| 692 |
-
border: none !important;
|
| 693 |
-
box-shadow: none !important;
|
| 694 |
-
pointer-events: auto; /* ์ฒดํฌ๋ฐ์ค ๋ถ๋ถ๋ง ํด๋ฆญ ๊ฐ๋ฅํ๊ฒ ๋ณต๊ตฌ */
|
| 695 |
}
|
| 696 |
"""
|
| 697 |
|
|
|
|
| 61 |
# ==========================================
|
| 62 |
# 2. UI Component Handlers
|
| 63 |
# ==========================================
|
|
|
|
| 64 |
def load_initial_standards():
|
| 65 |
return gr.Dropdown(choices=fetch_available_standards())
|
| 66 |
|
|
|
|
| 220 |
# ==========================================
|
| 221 |
# 3. Core Logic & Data Processing
|
| 222 |
# ==========================================
|
|
|
|
| 223 |
def generate_html_diff(base_text, comp_text):
|
| 224 |
base_text = "" if pd.isna(base_text) else str(base_text)
|
| 225 |
comp_text = "" if pd.isna(comp_text) else str(comp_text)
|
|
|
|
| 401 |
else: new_cols.append(col)
|
| 402 |
return df[new_cols]
|
| 403 |
|
|
|
|
| 404 |
if base_std and base_ver and base_cat and (not comp_std or not comp_ver or not comp_cat):
|
| 405 |
df, _ = fetch_database_records(base_std, base_ver, base_cat, type_b)
|
| 406 |
if "Error" in df.columns: return df
|
|
|
|
| 407 |
return apply_visual_merge(df, df.columns)
|
| 408 |
|
|
|
|
| 409 |
if all([base_std, base_ver, base_cat, comp_std, comp_ver, comp_cat]):
|
| 410 |
df_base, real_anchors_b = fetch_database_records(base_std, base_ver, base_cat, type_b)
|
| 411 |
df_comp, real_anchors_c = fetch_database_records(comp_std, comp_ver, comp_cat, type_c)
|
|
|
|
| 482 |
else:
|
| 483 |
bridge = df_mapping.copy()
|
| 484 |
|
|
|
|
| 485 |
rename_b = {c: f"{c}_{base_ver}" for c in df_base.columns if c != 'merge_key'}
|
| 486 |
df_base = df_base.rename(columns=rename_b)
|
| 487 |
|
|
|
|
| 513 |
row_dict[rename_b[orig_col]], row_dict[rename_c[orig_col]] = generate_html_diff(b_v, c_v)
|
| 514 |
result_rows.append(row_dict)
|
| 515 |
|
|
|
|
| 516 |
final_df = combine_code_desc(pd.DataFrame(result_rows))
|
| 517 |
|
| 518 |
if diff_only:
|
|
|
|
| 540 |
with gr.Blocks() as demo:
|
| 541 |
gr.Markdown("# ๐ Regulation Viewer")
|
| 542 |
|
| 543 |
+
# [์์ ์๋ฃ] ์์ฝ๋์ธ์ ๊นจ๋ํ Row ์์ ์์ ํ๊ฒ ๋ค์ด๊ฐ์ต๋๋ค!
|
| 544 |
+
with gr.Row():
|
|
|
|
| 545 |
with gr.Accordion("๐ ๊ธฐ์ค ๋ฒ๊ท", open=True):
|
| 546 |
with gr.Column():
|
|
|
|
| 547 |
base_reset_btn = gr.Button("โบ ๊ธฐ์ค ๋ฒ๊ท ์ด๊ธฐํ", size="sm")
|
| 548 |
base_standard = gr.Dropdown(label="Standard")
|
| 549 |
base_version = gr.Dropdown(label="Version")
|
|
|
|
| 556 |
comp_version = gr.Dropdown(label="Version", choices=[])
|
| 557 |
comp_category = gr.Dropdown(label="Category", choices=[])
|
| 558 |
|
|
|
|
|
|
|
| 559 |
search_btn = gr.Button("๐ ์กฐํ", variant="primary")
|
| 560 |
+
|
| 561 |
+
# =======================================================
|
| 562 |
+
# [์์ ์๋ฃ] ์ฒดํฌ๋ฐ์ค๋ ์์ฝ๋์ธ ๋ฐ์ผ๋ก ๊บผ๋ด์ ์กฐํ ๋ฒํผ ๋ฐ์ ๋ถ์์ต๋๋ค!
|
| 563 |
+
# container=False๋ฅผ ์ฃผ์ด ํ์ ๋ฐ์ค๋ ์๋ฒฝํ๊ฒ ๋ ๋ ธ์ต๋๋ค.
|
| 564 |
+
# =======================================================
|
| 565 |
+
with gr.Row(elem_id="diff_toggle_row"):
|
| 566 |
+
diff_filter_cb = gr.Checkbox(label="๐ก ๋ณ๊ฒฝ๋ ๋ด์ฉ๋ง ๋ณด๊ธฐ (Diff Only)", value=False, elem_id="diff_cb_item", container=False)
|
| 567 |
+
|
| 568 |
output_df = gr.Dataframe(wrap=True, interactive=False, datatype="html", max_height=800)
|
| 569 |
|
| 570 |
demo.load(fn=load_initial_standards, inputs=None, outputs=base_standard)
|
|
|
|
| 598 |
# ==========================================
|
| 599 |
# 5. Application Styling (CSS)
|
| 600 |
# ==========================================
|
|
|
|
| 601 |
css = """
|
| 602 |
table {
|
| 603 |
table-layout: auto !important;
|
|
|
|
| 673 |
display: block;
|
| 674 |
max-width: none !important;
|
| 675 |
}
|
| 676 |
+
|
| 677 |
+
/* ----------------------------------------------------
|
| 678 |
+
[์์ ์๋ฃ] Diff ํํฐ ์ฒดํฌ๋ฐ์ค ์ฐ์ธก ์๋จ ๊ฐ์ ๋ฐฐ์น
|
| 679 |
+
---------------------------------------------------- */
|
| 680 |
#diff_toggle_row {
|
| 681 |
+
display: flex !important;
|
| 682 |
+
justify-content: flex-end !important; /* ์ค๋ฅธ์ชฝ ๋์ผ๋ก ๊ฐ์ ์ ๋ ฌ */
|
| 683 |
margin-top: 5px !important;
|
| 684 |
+
margin-bottom: -15px !important; /* ํ์ ๊ฐ๊น๊ฒ ์๋๋ก ๋น๊น */
|
| 685 |
+
padding-right: 10px !important;
|
| 686 |
}
|
| 687 |
|
| 688 |
#diff_cb_item {
|
| 689 |
+
flex-grow: 0 !important; /* ๊ฐ๋ก ๊ณต๊ฐ ๋ค ์ฐจ์งํ๋ ๊ฒ ๋ฐฉ์ง */
|
| 690 |
+
width: max-content !important; /* ๊ธ์ ํฌ๊ธฐ๋งํผ๋ง ๋๋น ์ฐจ์ง */
|
| 691 |
+
min-width: 0 !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 692 |
}
|
| 693 |
"""
|
| 694 |
|