QIDNLF commited on
Commit
4a57354
ยท
verified ยท
1 Parent(s): f24980a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -166
app.py CHANGED
@@ -495,111 +495,6 @@ def execute_unified_search(base_std, base_ver, base_cat, comp_std, comp_ver, com
495
  # ==========================================
496
  # 4. UI Layout & Event Binding
497
  # ==========================================
498
- js_resizable = """
499
- function() {
500
- console.log("๐Ÿ› ๏ธ [์ตœ์ข… ์ˆ˜์ •] ์—ด ์กฐ์ ˆ ์ด๋ฒคํŠธ ๋ฐฉ์–ด๋ง‰ ๊ฐ€๋™!");
501
-
502
- function findAllTables(root) {
503
- let tables = [];
504
- const elements = root.querySelectorAll('*');
505
- elements.forEach(el => {
506
- if (el.tagName && el.tagName.toLowerCase() === 'table') {
507
- tables.push(el);
508
- }
509
- if (el.shadowRoot) {
510
- tables = tables.concat(findAllTables(el.shadowRoot));
511
- }
512
- });
513
- return tables;
514
- }
515
-
516
- const attachResizers = () => {
517
- let tables = findAllTables(document);
518
- if (tables.length === 0) return;
519
-
520
- tables.forEach(table => {
521
- if (table.dataset.resizable === 'true') return;
522
-
523
- // ํ‘œ ์ „์ฒด์˜ ์ œ์•ฝ์„ ํ’‰๋‹ˆ๋‹ค
524
- table.style.tableLayout = 'fixed';
525
- table.style.width = 'max-content';
526
- table.style.minWidth = '100%';
527
-
528
- const headers = table.querySelectorAll('thead th, tr:first-child th, tr:first-child td');
529
-
530
- headers.forEach(th => {
531
- if (th.querySelector('.resizer')) return;
532
-
533
- const resizer = document.createElement('div');
534
- resizer.className = 'resizer';
535
- resizer.style.width = '12px';
536
- resizer.style.height = '100%';
537
- resizer.style.position = 'absolute';
538
- resizer.style.right = '0px';
539
- resizer.style.top = '0px';
540
- resizer.style.cursor = 'col-resize';
541
- resizer.style.zIndex = '999999';
542
- resizer.style.backgroundColor = 'rgba(255, 0, 0, 0.6)';
543
-
544
- th.style.position = 'relative';
545
- th.style.overflow = 'visible';
546
- th.appendChild(resizer);
547
-
548
- let startX, startWidth;
549
-
550
- function onMouseDown(e) {
551
- // [ํ•ต์‹ฌ ํ•ด๊ฒฐ์ฑ…] ๋ธŒ๋ผ์šฐ์ €์˜ ํ…์ŠคํŠธ ๋“œ๋ž˜๊ทธ๋‚˜ ๋‹ค๋ฅธ ์ด๋ฒคํŠธ๋ฅผ ๊ฐ•์ œ๋กœ ๋ง‰์Šต๋‹ˆ๋‹ค.
552
- e.preventDefault();
553
- e.stopPropagation();
554
-
555
- startX = e.clientX || e.pageX;
556
- startWidth = th.getBoundingClientRect().width;
557
-
558
- document.addEventListener('mousemove', onMouseMove);
559
- document.addEventListener('mouseup', onMouseUp);
560
-
561
- resizer.style.backgroundColor = '#1a73e8';
562
- document.body.style.cursor = 'col-resize'; // ๋งˆ์šฐ์Šค๊ฐ€ ํ™”๋ฉด ์–ด๋””์žˆ๋“  ๋ฆฌ์‚ฌ์ด์ฆˆ ์ปค์„œ ์œ ์ง€
563
- }
564
-
565
- function onMouseMove(e) {
566
- // [ํ•ต์‹ฌ ํ•ด๊ฒฐ์ฑ…] ์ด๋ฒคํŠธ๋ฅผ ๊ณ„์† ๋ถ™์žก์•„ ๋‘ก๋‹ˆ๋‹ค.
567
- e.preventDefault();
568
-
569
- const currentX = e.clientX || e.pageX;
570
- const width = Math.max(30, startWidth + (currentX - startX));
571
-
572
- th.style.width = width + 'px';
573
- th.style.minWidth = width + 'px';
574
- th.style.maxWidth = width + 'px';
575
- }
576
-
577
- function onMouseUp() {
578
- document.removeEventListener('mousemove', onMouseMove);
579
- document.removeEventListener('mouseup', onMouseUp);
580
-
581
- resizer.style.backgroundColor = 'rgba(255, 0, 0, 0.6)';
582
- document.body.style.cursor = ''; // ์ปค์„œ ์›์ƒ๋ณต๊ตฌ
583
- }
584
-
585
- resizer.addEventListener('mousedown', onMouseDown);
586
- });
587
-
588
- table.dataset.resizable = 'true';
589
- });
590
- };
591
-
592
- let attempts = 0;
593
- const interval = setInterval(() => {
594
- attachResizers();
595
- attempts++;
596
- if (attempts > 50) clearInterval(interval);
597
- }, 200);
598
-
599
- return [];
600
- }
601
- """
602
-
603
  with gr.Blocks() as demo:
604
  gr.Markdown("# ๐Ÿ“œ Regulation Viewer")
605
 
@@ -633,11 +528,12 @@ with gr.Blocks() as demo:
633
  base_category.change(fn=update_comp_category_dropdown, inputs=comp_change_triggers, outputs=[comp_category])
634
  comp_version.change(fn=update_comp_category_dropdown, inputs=comp_change_triggers, outputs=[comp_category])
635
 
 
636
  search_btn.click(
637
  fn=execute_unified_search,
638
  inputs=[base_standard, base_version, base_category, comp_standard, comp_version, comp_category],
639
  outputs=[output_df]
640
- ).then(fn=None, js=js_resizable)
641
 
642
  base_reset_btn.click(fn=reset_base_selections, inputs=None, outputs=[base_standard, base_version, base_category])
643
  comp_reset_btn.click(fn=reset_comp_selections, inputs=None, outputs=[comp_standard, comp_version, comp_category])
@@ -648,10 +544,44 @@ with gr.Blocks() as demo:
648
  # ==========================================
649
  css = """
650
  table {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
651
  width: 100% !important;
652
- border-collapse: collapse;
653
  }
654
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
655
  thead th {
656
  font-size: 18px !important;
657
  position: sticky;
@@ -659,10 +589,20 @@ thead th {
659
  background: white;
660
  z-index: 10;
661
  }
662
- td, th {
 
 
 
 
 
 
 
 
 
 
663
  font-size: 18px !important;
664
- word-break: break-word !important;
665
- white-space: normal !important;
666
  line-height: 1.6;
667
  padding: 10px;
668
  vertical-align: top !important;
@@ -672,62 +612,6 @@ td img {
672
  display: block;
673
  max-width: none !important;
674
  }
675
-
676
- .gradio-container .dataframe,
677
- .gradio-container .dataframe div,
678
- .gradio-container thead,
679
- .gradio-container tr,
680
- .gradio-container th {
681
- overflow: visible !important;
682
- }
683
- .dataframe {
684
- max-height: none !important;
685
- overflow-y: visible !important;
686
- overflow-x: auto !important;
687
- display: block;
688
- }
689
-
690
- .resizer {
691
- background-color: rgba(255, 0, 0, 0.5);
692
- width: 8px !important;
693
- height: 100%;
694
- position: absolute;
695
- right: 0;
696
- top: 0;
697
- cursor: col-resize;
698
- z-index: 9999 !important;
699
- }
700
- .resizer:hover, .resizer.resizing {
701
- background-color: #1a73e8 !important;
702
- }
703
-
704
- table:has(th:nth-last-child(2):first-child),
705
- table:has(th:nth-last-child(4):first-child),
706
- table:has(th:nth-last-child(5):first-child),
707
- table:has(th:nth-last-child(6):first-child) {
708
- table-layout: fixed;
709
- }
710
-
711
- table th:nth-last-child(2):first-child, table td:nth-last-child(2):first-child { width: 15%; }
712
- table th:nth-last-child(1), table td:nth-last-child(1) { width: 85%; }
713
-
714
- table th:nth-child(1):nth-last-child(4), table td:nth-child(1):nth-last-child(4) { width: 10%; }
715
- table th:nth-child(2):nth-last-child(3), table td:nth-child(2):nth-last-child(3) { width: 40%; }
716
- table th:nth-child(3):nth-last-child(2), table td:nth-child(3):nth-last-child(2) { width: 10%; }
717
- table th:nth-child(4):nth-last-child(1), table td:nth-child(4):nth-last-child(1) { width: 40%; }
718
-
719
- table th:nth-child(1):nth-last-child(5), table td:nth-child(1):nth-last-child(5) { width: 15%; }
720
- table th:nth-child(2):nth-last-child(4), table td:nth-child(2):nth-last-child(4) { width: 10%; }
721
- table th:nth-child(3):nth-last-child(3), table td:nth-child(3):nth-last-child(3) { width: 30%; }
722
- table th:nth-child(4):nth-last-child(2), table td:nth-child(4):nth-last-child(2) { width: 10%; }
723
- table th:nth-child(5):nth-last-child(1), table td:nth-child(5):nth-last-child(1) { width: 35%; }
724
-
725
- table th:nth-child(1):nth-last-child(6), table td:nth-child(1):nth-last-child(6) { width: 8%; }
726
- table th:nth-child(2):nth-last-child(5), table td:nth-child(2):nth-last-child(5) { width: 15%; }
727
- table th:nth-child(3):nth-last-child(4), table td:nth-child(3):nth-last-child(4) { width: 27%; }
728
- table th:nth-child(4):nth-last-child(3), table td:nth-child(4):nth-last-child(3) { width: 8%; }
729
- table th:nth-child(5):nth-last-child(2), table td:nth-child(5):nth-last-child(2) { width: 15%; }
730
- table th:nth-child(6):nth-last-child(1), table td:nth-child(6):nth-last-child(1) { width: 27%; }
731
  """
732
 
733
  if __name__ == "__main__":
 
495
  # ==========================================
496
  # 4. UI Layout & Event Binding
497
  # ==========================================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
498
  with gr.Blocks() as demo:
499
  gr.Markdown("# ๐Ÿ“œ Regulation Viewer")
500
 
 
528
  base_category.change(fn=update_comp_category_dropdown, inputs=comp_change_triggers, outputs=[comp_category])
529
  comp_version.change(fn=update_comp_category_dropdown, inputs=comp_change_triggers, outputs=[comp_category])
530
 
531
+ # JS๋ฅผ ์™„์ „ํžˆ ์ œ๊ฑฐํ•˜๊ณ  ์ˆœ์ˆ˜ํ•˜๊ฒŒ ํŒŒ์ด์ฌ ๋กœ์ง๋งŒ ๋ฐ”์ธ๋”ฉ
532
  search_btn.click(
533
  fn=execute_unified_search,
534
  inputs=[base_standard, base_version, base_category, comp_standard, comp_version, comp_category],
535
  outputs=[output_df]
536
+ )
537
 
538
  base_reset_btn.click(fn=reset_base_selections, inputs=None, outputs=[base_standard, base_version, base_category])
539
  comp_reset_btn.click(fn=reset_comp_selections, inputs=None, outputs=[comp_standard, comp_version, comp_category])
 
544
  # ==========================================
545
  css = """
546
  table {
547
+ table-layout: auto !important;
548
+ width: max-content !important;
549
+ min-width: 100% !important;
550
+ }
551
+
552
+ th, td {
553
+ min-width: 150px;
554
+ }
555
+
556
+ table:has(th:nth-last-child(2):first-child),
557
+ table:has(th:nth-last-child(4):first-child),
558
+ table:has(th:nth-last-child(5):first-child),
559
+ table:has(th:nth-last-child(6):first-child) {
560
+ table-layout: fixed !important;
561
  width: 100% !important;
 
562
  }
563
 
564
+ table th:nth-last-child(2):first-child, table td:nth-last-child(2):first-child { width: 15% !important; min-width: 0 !important; }
565
+ table th:nth-last-child(1), table td:nth-last-child(1) { width: 85% !important; min-width: 0 !important; }
566
+
567
+ table th:nth-child(1):nth-last-child(4), table td:nth-child(1):nth-last-child(4) { width: 10% !important; min-width: 0 !important; }
568
+ table th:nth-child(2):nth-last-child(3), table td:nth-child(2):nth-last-child(3) { width: 40% !important; min-width: 0 !important; }
569
+ table th:nth-child(3):nth-last-child(2), table td:nth-child(3):nth-last-child(2) { width: 10% !important; min-width: 0 !important; }
570
+ table th:nth-child(4):nth-last-child(1), table td:nth-child(4):nth-last-child(1) { width: 40% !important; min-width: 0 !important; }
571
+
572
+ table th:nth-child(1):nth-last-child(5), table td:nth-child(1):nth-last-child(5) { width: 15% !important; min-width: 0 !important; }
573
+ table th:nth-child(2):nth-last-child(4), table td:nth-child(2):nth-last-child(4) { width: 10% !important; min-width: 0 !important; }
574
+ table th:nth-child(3):nth-last-child(3), table td:nth-child(3):nth-last-child(3) { width: 30% !important; min-width: 0 !important; }
575
+ table th:nth-child(4):nth-last-child(2), table td:nth-child(4):nth-last-child(2) { width: 10% !important; min-width: 0 !important; }
576
+ table th:nth-child(5):nth-last-child(1), table td:nth-child(5):nth-last-child(1) { width: 35% !important; min-width: 0 !important; }
577
+
578
+ table th:nth-child(1):nth-last-child(6), table td:nth-child(1):nth-last-child(6) { width: 8% !important; min-width: 0 !important; }
579
+ table th:nth-child(2):nth-last-child(5), table td:nth-child(2):nth-last-child(5) { width: 15% !important; min-width: 0 !important; }
580
+ table th:nth-child(3):nth-last-child(4), table td:nth-child(3):nth-last-child(4) { width: 27% !important; min-width: 0 !important; }
581
+ table th:nth-child(4):nth-last-child(3), table td:nth-child(4):nth-last-child(3) { width: 8% !important; min-width: 0 !important; }
582
+ table th:nth-child(5):nth-last-child(2), table td:nth-child(5):nth-last-child(2) { width: 15% !important; min-width: 0 !important; }
583
+ table th:nth-child(6):nth-last-child(1), table td:nth-child(6):nth-last-child(1) { width: 27% !important; min-width: 0 !important; }
584
+
585
  thead th {
586
  font-size: 18px !important;
587
  position: sticky;
 
589
  background: white;
590
  z-index: 10;
591
  }
592
+ .dataframe {
593
+ max-height: none !important;
594
+ overflow-y: visible !important;
595
+ overflow-x: auto !important;
596
+ display: block;
597
+ }
598
+ .dataframe > div {
599
+ max-height: none !important;
600
+ overflow: visible !important;
601
+ }
602
+ td {
603
  font-size: 18px !important;
604
+ white-space: pre-wrap !important;
605
+ word-break: keep-all !important;
606
  line-height: 1.6;
607
  padding: 10px;
608
  vertical-align: top !important;
 
612
  display: block;
613
  max-width: none !important;
614
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
615
  """
616
 
617
  if __name__ == "__main__":