Yiming-M commited on
Commit
dde77f8
·
1 Parent(s): 0f2ce4d

2025-08-01 09:46 🚀

Browse files
Files changed (1) hide show
  1. app.py +30 -498
app.py CHANGED
@@ -486,521 +486,53 @@ def predict(image: Image.Image, variant_dataset_metric: str):
486
  # Build Gradio Interface using Blocks for a two-column layout
487
  # -----------------------------
488
  css = """
489
- /* 分割线样式 - 灰色不可选择 */
490
- .dropdown select option[value*="━━━━━━"] {
491
- color: #999 !important;
492
- background-color: #f0f0f0 !important;
493
- font-style: italic !important;
494
- text-align: center !important;
495
- pointer-events: none !important;
496
- cursor: not-allowed !important;
497
- border: none !important;
498
- }
499
-
500
- /* Gradio下拉菜单中的分割线样式 */
501
- .gr-dropdown .choices__item[data-value*="━━━━━━"] {
502
- color: #999 !important;
503
- background-color: #f0f0f0 !important;
504
- font-style: italic !important;
505
- text-align: center !important;
506
- pointer-events: none !important;
507
- cursor: not-allowed !important;
508
- user-select: none !important;
509
- opacity: 0.6 !important;
510
- }
511
-
512
- /* 悬停时保持灰色 */
513
- .gr-dropdown .choices__item[data-value*="━━━━━━"]:hover {
514
- background-color: #f0f0f0 !important;
515
- color: #999 !important;
516
- cursor: not-allowed !important;
517
- }
518
-
519
- /* 通用的分割线样式 */
520
- option:disabled {
521
- color: #999 !important;
522
- background-color: #f0f0f0 !important;
523
- font-style: italic !important;
524
- }
525
-
526
- /* 为包含分割线字符的选项添加样式 */
527
- option[value*="━━━━━━"],
528
- select option[value*="━━━━━━"] {
529
- color: #999 !important;
530
- background-color: #f0f0f0 !important;
531
- cursor: not-allowed !important;
532
- pointer-events: none !important;
533
- text-align: center !important;
534
- opacity: 0.6 !important;
535
- }
536
-
537
- /* 整体主题美化 */
538
  .gradio-container {
539
- max-width: 1600px !important;
540
- margin: 0 auto !important;
541
- font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
542
- background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%) !important;
543
- min-height: 100vh !important;
544
- padding: 20px !important;
545
  }
546
 
547
- /* 响应式布局 - 自动调整列宽 */
548
- @media (max-width: 1400px) {
549
- .gradio-container {
550
- max-width: 1200px !important;
551
- padding: 18px !important;
552
- }
553
  }
554
 
555
- @media (max-width: 1200px) {
556
- .gradio-container {
557
- max-width: 100% !important;
558
- padding: 16px !important;
559
- }
560
-
561
- /* 在中等屏幕上,将第二行改为垂直布局 */
562
- .gr-row:nth-of-type(2) {
563
- flex-direction: column !important;
564
- }
565
-
566
- .gr-row:nth-of-type(2) .gr-column {
567
- width: 100% !important;
568
- margin-bottom: 20px !important;
569
- }
570
-
571
- /* 重置中等屏幕上的组件高度 */
572
- .gr-row:nth-of-type(2) .gr-group,
573
- .gr-row:nth-of-type(3) .gr-group {
574
- height: auto !important;
575
- min-height: auto !important;
576
- position: static !important;
577
- }
578
-
579
- .gr-row:nth-of-type(3) .gr-column:first-child .gr-group {
580
- position: static !important;
581
- }
582
-
583
- .gr-row:nth-of-type(3) .gr-column:first-child .gr-button {
584
- position: static !important;
585
- bottom: auto !important;
586
- left: auto !important;
587
- right: auto !important;
588
- width: auto !important;
589
- margin-top: 16px !important;
590
- }
591
  }
592
 
593
- @media (max-width: 900px) {
594
- /* 在小屏幕上,将第三行也改为垂直布局 */
595
- .gr-row:nth-of-type(3) {
596
- flex-direction: column !important;
597
- }
598
-
599
- .gr-row:nth-of-type(3) .gr-column {
600
- width: 100% !important;
601
- margin-bottom: 20px !important;
602
- }
603
-
604
- /* Zero Analysis 在小屏幕上也改为垂直布局 */
605
- .gr-group .gr-row {
606
- flex-direction: column !important;
607
- }
608
-
609
- .gr-group .gr-row .gr-column {
610
- width: 100% !important;
611
- margin-bottom: 16px !important;
612
- }
613
-
614
- /* 重置小屏幕上的组件高度 */
615
- .gr-row:nth-of-type(2) .gr-group,
616
- .gr-row:nth-of-type(3) .gr-group {
617
- height: auto !important;
618
- min-height: auto !important;
619
- position: static !important;
620
- }
621
-
622
- .gr-row:nth-of-type(3) .gr-column:first-child .gr-group {
623
- position: static !important;
624
- }
625
-
626
- .gr-row:nth-of-type(3) .gr-column:first-child .gr-button {
627
- position: static !important;
628
- bottom: auto !important;
629
- left: auto !important;
630
- right: auto !important;
631
- width: auto !important;
632
- margin-top: 16px !important;
633
- }
634
  }
635
 
636
- @media (max-width: 768px) {
637
- .gradio-container {
638
- padding: 12px !important;
639
- }
640
-
641
- .gr-column {
642
- margin-bottom: 16px !important;
643
- padding: 0 4px !important;
644
- }
645
-
646
- .gr-markdown h1 {
647
- font-size: 2rem !important;
648
- }
649
-
650
- .gr-group {
651
- padding: 16px !important;
652
- }
653
-
654
- .gr-button {
655
- padding: 12px 24px !important;
656
- font-size: 1rem !important;
657
- }
658
-
659
- /* 图像高度在小屏幕上调整 */
660
- .gr-image {
661
- height: 300px !important;
662
- }
663
-
664
- .zero-analysis-image {
665
- height: 300px !important;
666
- }
667
-
668
- /* 小屏幕上重置组件高度 */
669
- .gr-row:nth-of-type(2) .gr-group,
670
- .gr-row:nth-of-type(3) .gr-group {
671
- height: auto !important;
672
- min-height: auto !important;
673
- position: static !important;
674
- }
675
-
676
- .gr-row:nth-of-type(3) .gr-column:first-child .gr-group {
677
- position: static !important;
678
- }
679
-
680
- .gr-row:nth-of-type(3) .gr-column:first-child .gr-button {
681
- position: static !important;
682
- bottom: auto !important;
683
- left: auto !important;
684
- right: auto !important;
685
- width: auto !important;
686
- margin-top: 16px !important;
687
- }
688
-
689
- .gr-row:nth-of-type(2) .gr-textbox,
690
- .gr-row:nth-of-type(2) .gr-dropdown {
691
- min-height: auto !important;
692
- max-height: none !important;
693
- }
694
-
695
- .gr-row:nth-of-type(3) .gr-image {
696
- height: 300px !important;
697
- min-height: auto !important;
698
- max-height: none !important;
699
- flex: none !important;
700
- }
701
  }
702
 
703
- /* 超宽屏幕优化 */
704
- @media (min-width: 1600px) {
705
  .gradio-container {
706
- max-width: 1800px !important;
707
- padding: 24px !important;
708
  }
709
 
710
  .gr-image {
711
- height: 450px !important;
712
- }
713
-
714
- .zero-analysis-image {
715
- height: 450px !important;
716
  }
717
  }
718
-
719
- /* 标题样式 */
720
- .gr-markdown h1 {
721
- text-align: center !important;
722
- color: #2563eb !important;
723
- font-weight: 700 !important;
724
- font-size: 3rem !important;
725
- margin-bottom: 0.5rem !important;
726
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
727
- -webkit-background-clip: text !important;
728
- -webkit-text-fill-color: transparent !important;
729
- text-shadow: 0 4px 8px rgba(0,0,0,0.1) !important;
730
- }
731
-
732
- /* 副标题样式 */
733
- .gr-markdown p {
734
- text-align: center !important;
735
- color: #6b7280 !important;
736
- font-size: 1.2rem !important;
737
- margin-bottom: 2rem !important;
738
- font-weight: 500 !important;
739
- }
740
-
741
- /* 主要布局组美化 */
742
- .gr-group {
743
- background: rgba(255, 255, 255, 0.9) !important;
744
- backdrop-filter: blur(10px) !important;
745
- border-radius: 20px !important;
746
- padding: 24px !important;
747
- margin: 16px 0 !important;
748
- box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1) !important;
749
- border: 1px solid rgba(255, 255, 255, 0.2) !important;
750
- transition: all 0.3s ease !important;
751
- }
752
-
753
- .gr-group:hover {
754
- transform: translateY(-4px) !important;
755
- box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15) !important;
756
- }
757
-
758
- /* 按钮美化 */
759
- .gr-button {
760
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
761
- border: none !important;
762
- border-radius: 12px !important;
763
- color: white !important;
764
- font-weight: 600 !important;
765
- font-size: 1.1rem !important;
766
- padding: 16px 32px !important;
767
- transition: all 0.3s ease !important;
768
- box-shadow: 0 6px 20px rgba(102, 126, 234, 0.3) !important;
769
- text-transform: uppercase !important;
770
- letter-spacing: 0.5px !important;
771
- }
772
-
773
- .gr-button:hover {
774
- transform: translateY(-3px) !important;
775
- box-shadow: 0 10px 30px rgba(102, 126, 234, 0.4) !important;
776
- background: linear-gradient(135deg, #5a67d8 0%, #6b46c1 100%) !important;
777
- }
778
-
779
- /* 输入框样式 */
780
- .gr-textbox, .gr-dropdown {
781
- border-radius: 12px !important;
782
- border: 2px solid #e5e7eb !important;
783
- transition: all 0.3s ease !important;
784
- background: rgba(255, 255, 255, 0.8) !important;
785
- font-size: 1rem !important;
786
- padding: 12px 16px !important;
787
- }
788
-
789
- .gr-textbox:focus, .gr-dropdown:focus {
790
- border-color: #667eea !important;
791
- box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1) !important;
792
- background: rgba(255, 255, 255, 1) !important;
793
- }
794
-
795
- /* 图像容器美化 - 统一尺寸 */
796
- .gr-image {
797
- border-radius: 16px !important;
798
- overflow: hidden !important;
799
- box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15) !important;
800
- transition: all 0.3s ease !important;
801
- background: white !important;
802
- height: 400px !important;
803
- width: 100% !important;
804
- }
805
-
806
- .gr-image:hover {
807
- box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2) !important;
808
- transform: translateY(-2px) !important;
809
- }
810
-
811
- /* 确保第二行组件等高 - 重新调整为三列等宽 */
812
- .gr-row:nth-of-type(2) .gr-group {
813
- min-height: 180px !important;
814
- display: flex !important;
815
- flex-direction: column !important;
816
- justify-content: center !important;
817
- }
818
-
819
- .gr-row:nth-of-type(2) .gr-group > * {
820
- flex: 1 !important;
821
- }
822
-
823
- /* 确保第二行的文本框具有相同的高度 */
824
- .gr-row:nth-of-type(2) .gr-textbox {
825
- min-height: 100px !important;
826
- max-height: 100px !important;
827
- display: flex !important;
828
- align-items: center !important;
829
- }
830
-
831
- /* 确保第二行下拉菜单区域等高 */
832
- .gr-row:nth-of-type(2) .gr-dropdown {
833
- min-height: 80px !important;
834
- }
835
-
836
- /* 确保下拉框可以正常展开 */
837
- .gr-dropdown {
838
- position: relative !important;
839
- z-index: 1000 !important;
840
- }
841
-
842
- .gr-dropdown .choices {
843
- position: absolute !important;
844
- z-index: 1001 !important;
845
- width: 100% !important;
846
- max-height: 300px !important;
847
- overflow-y: auto !important;
848
- }
849
-
850
- /* 确保第三行组件等高 - 重新调整高度 */
851
- .gr-row:nth-of-type(3) .gr-group {
852
- height: 520px !important;
853
- min-height: 520px !important;
854
- display: flex !important;
855
- flex-direction: column !important;
856
- justify-content: flex-start !important;
857
- }
858
-
859
- /* 第三行的图像容器统一高度 */
860
- .gr-row:nth-of-type(3) .gr-image {
861
- height: 400px !important;
862
- min-height: 400px !important;
863
- max-height: 400px !important;
864
- flex: 0 0 400px !important;
865
- }
866
-
867
- /* 第三行的按钮固定在底部 - 只对第一列(Image Input)应用 */
868
- .gr-row:nth-of-type(3) .gr-column:first-child .gr-group {
869
- position: relative !important;
870
- }
871
-
872
- .gr-row:nth-of-type(3) .gr-column:first-child .gr-button {
873
- position: absolute !important;
874
- bottom: 24px !important;
875
- left: 24px !important;
876
- right: 24px !important;
877
- margin: 0 !important;
878
- width: calc(100% - 48px) !important;
879
- }
880
-
881
- /* 列间距优化 */
882
- .gr-column {
883
- padding: 0 8px !important;
884
- margin-bottom: 16px !important;
885
- }
886
-
887
- /* 第二行特殊布局调整 - 移除,现在是三列等宽 */
888
- .gr-row:nth-of-type(2) .gr-column {
889
- padding: 0 8px !important;
890
- }
891
-
892
- /* 标签美化 */
893
- .gr-label {
894
- font-weight: 700 !important;
895
- color: #374151 !important;
896
- margin-bottom: 12px !important;
897
- font-size: 1.1rem !important;
898
- text-transform: uppercase !important;
899
- letter-spacing: 0.5px !important;
900
- }
901
-
902
- /* 模型状态框特殊样式 */
903
- .gr-textbox[data-testid*="model-status"] {
904
- background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%) !important;
905
- font-family: 'Monaco', 'Menlo', monospace !important;
906
- font-size: 0.95rem !important;
907
- font-weight: 600 !important;
908
- border: 2px solid #10b981 !important;
909
- }
910
-
911
- /* Zero Analysis 特殊布局 */
912
- .gr-row:has(.gr-image[label*="Zero"]) {
913
- background: linear-gradient(135deg, rgba(255,255,255,0.95) 0%, rgba(248,250,252,0.95) 100%) !important;
914
- border-radius: 20px !important;
915
- padding: 24px !important;
916
- margin: 20px 0 !important;
917
- box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1) !important;
918
- }
919
-
920
- /* Zero Analysis 图像特殊样式 - 统一尺寸 */
921
- .zero-analysis-image {
922
- border: 3px solid transparent !important;
923
- background: linear-gradient(white, white) padding-box,
924
- linear-gradient(135deg, #667eea, #764ba2) border-box !important;
925
- border-radius: 16px !important;
926
- transition: all 0.3s ease !important;
927
- height: 400px !important;
928
- width: 100% !important;
929
- }
930
-
931
- .zero-analysis-image:hover {
932
- transform: scale(1.02) !important;
933
- box-shadow: 0 12px 35px rgba(102, 126, 234, 0.2) !important;
934
- }
935
-
936
- /* 确保所有行的组件等高 */
937
- .gr-row .gr-group {
938
- min-height: 100% !important;
939
- display: flex !important;
940
- flex-direction: column !important;
941
- }
942
-
943
- .gr-row .gr-column {
944
- height: 100% !important;
945
- }
946
-
947
- /* 第二行内部子行等高处理 - 移除,现在不需要内部子行 */
948
-
949
- /* 统计信息卡片美化 */
950
- .gr-textbox[label*="Count"] {
951
- background: linear-gradient(135deg, #ecfcff 0%, #cffafe 100%) !important;
952
- border: 2px solid #06b6d4 !important;
953
- font-size: 1.2rem !important;
954
- font-weight: 700 !important;
955
- text-align: center !important;
956
- color: #0e7490 !important;
957
- }
958
-
959
- /* 示例区域美化 */
960
- .gr-examples {
961
- background: linear-gradient(135deg, rgba(255,255,255,0.9) 0%, rgba(248,250,252,0.9) 100%) !important;
962
- backdrop-filter: blur(10px) !important;
963
- border-radius: 20px !important;
964
- padding: 30px !important;
965
- margin-top: 30px !important;
966
- border: 1px solid rgba(255, 255, 255, 0.2) !important;
967
- box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1) !important;
968
- }
969
-
970
- /* Accordion 美化 */
971
- .gr-accordion {
972
- background: rgba(255, 255, 255, 0.8) !important;
973
- border-radius: 16px !important;
974
- margin: 16px 0 !important;
975
- border: 1px solid rgba(255, 255, 255, 0.2) !important;
976
- box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08) !important;
977
- }
978
-
979
- /* 响应式设计 - 移除旧的媒体查询,已在上方重新定义 */
980
-
981
- /* 加载动画 */
982
- @keyframes pulse {
983
- 0%, 100% { opacity: 1; }
984
- 50% { opacity: 0.5; }
985
- }
986
-
987
- .gr-loading .gr-image {
988
- animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite !important;
989
- }
990
-
991
- /* 成功状态指示 */
992
- .status-success {
993
- color: #059669 !important;
994
- background-color: #d1fae5 !important;
995
- border: 1px solid #a7f3d0 !important;
996
- }
997
-
998
- /* 错误状态指示 */
999
- .status-error {
1000
- color: #dc2626 !important;
1001
- background-color: #fee2e2 !important;
1002
- border: 1px solid #fecaca !important;
1003
- }
1004
  """
1005
 
1006
  with gr.Blocks(css=css, theme=gr.themes.Soft(), title="ZIP Crowd Counting") as demo:
 
486
  # Build Gradio Interface using Blocks for a two-column layout
487
  # -----------------------------
488
  css = """
489
+ /* 基础样式 - 保持功能性 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
490
  .gradio-container {
491
+ max-width: 1600px;
492
+ margin: 0 auto;
493
+ padding: 20px;
 
 
 
494
  }
495
 
496
+ /* 简单的分割线样式 */
497
+ option[value*="━━━━━━"] {
498
+ color: #999;
499
+ background-color: #f0f0f0;
500
+ text-align: center;
 
501
  }
502
 
503
+ /* 基础组件样式 */
504
+ .gr-group {
505
+ background: white;
506
+ border-radius: 8px;
507
+ padding: 16px;
508
+ margin: 8px 0;
509
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
510
  }
511
 
512
+ .gr-button {
513
+ background: #3b82f6;
514
+ color: white;
515
+ border: none;
516
+ border-radius: 6px;
517
+ padding: 12px 24px;
518
+ font-weight: 600;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
519
  }
520
 
521
+ .gr-image {
522
+ border-radius: 8px;
523
+ height: 400px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
524
  }
525
 
526
+ /* 响应式设计 */
527
+ @media (max-width: 768px) {
528
  .gradio-container {
529
+ padding: 12px;
 
530
  }
531
 
532
  .gr-image {
533
+ height: 300px;
 
 
 
 
534
  }
535
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
536
  """
537
 
538
  with gr.Blocks(css=css, theme=gr.themes.Soft(), title="ZIP Crowd Counting") as demo: