ApsidalSolid4 commited on
Commit
83f1e8a
Β·
verified Β·
1 Parent(s): 74b6e3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -76
app.py CHANGED
@@ -802,28 +802,31 @@ def setup_interface():
802
  gr.Markdown("Quick mode for faster analysis. Detailed mode for sentence-level analysis.",
803
  elem_classes=["description-text"])
804
 
805
- # Radio buttons with inline file upload
806
- with gr.Row(elem_id="control-row"):
807
- # First column for radio buttons
808
- with gr.Column(scale=10):
809
- mode_selection = gr.Radio(
810
- choices=["quick", "detailed"],
811
- value="quick",
812
- label=""
813
- )
814
-
815
- # Second column for tiny paperclip button
816
- with gr.Column(scale=1, elem_id="paperclip-column"):
817
- file_upload = gr.File(
818
- file_types=["image", "pdf", "doc", "docx"],
819
- type="binary",
820
- label="πŸ“Ž",
821
- elem_id="paperclip-upload",
822
- elem_classes=["paperclip-button"]
823
- )
 
 
 
824
 
825
  # Action buttons row
826
- with gr.Row(elem_id="button-row"):
827
  clear_btn = gr.Button("Clear", elem_id="clear-btn")
828
  analyze_btn = gr.Button("Analyze Text", elem_id="analyze-btn")
829
 
@@ -852,7 +855,7 @@ def setup_interface():
852
  outputs=[output_html, output_sentences, output_result]
853
  )
854
 
855
- # Add custom CSS to style everything correctly
856
  gr.HTML("""
857
  <style>
858
  /* Button styling */
@@ -869,67 +872,33 @@ def setup_interface():
869
  color: black !important;
870
  }
871
 
872
- #button-row {
873
- gap: 10px !important;
874
- margin-top: 10px !important;
875
- }
876
-
877
- /* Paperclip styling - make it tiny and minimal */
878
- #paperclip-column {
879
- min-width: 30px !important;
880
- width: 30px !important;
881
- padding: 0 !important;
882
- margin-left: -15px !important;
883
- margin-top: 8px !important;
884
- }
885
-
886
- /* Hide virtually everything in the file upload except the emoji */
887
- .paperclip-button .wrap {
888
- border: none !important;
889
- background: none !important;
890
- padding: 0 !important;
891
- margin: 0 !important;
892
- height: 30px !important;
893
- min-height: 0 !important;
894
- }
895
-
896
- .paperclip-button .file-preview {
897
- display: none !important;
898
  }
899
 
900
- .paperclip-button label {
901
- display: none !important;
 
 
902
  }
903
 
904
- .paperclip-button .upload-button {
905
- background: none !important;
906
- border: none !important;
907
- padding: 0 !important;
908
- margin: 0 !important;
909
- width: 25px !important;
910
- height: 25px !important;
911
- opacity: 0.6 !important;
912
  }
913
 
914
- .paperclip-button .upload-button:hover {
915
- opacity: 1 !important;
916
- }
917
-
918
- /* Fix file upload icon to be paperclip only */
919
- .paperclip-button .upload-button::before {
920
- content: "πŸ“Ž" !important;
921
- font-size: 18px !important;
922
- position: absolute !important;
923
- left: 3px !important;
924
- top: 2px !important;
925
- }
926
-
927
- .paperclip-button .upload-button .icon {
928
- display: none !important;
929
- }
930
-
931
- .paperclip-button .upload-button .text-button {
932
- display: none !important;
933
  }
934
 
935
  /* Description text styling */
@@ -940,6 +909,23 @@ def setup_interface():
940
  margin-bottom: 5px !important;
941
  }
942
  </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
943
  """)
944
 
945
  return demo
 
802
  gr.Markdown("Quick mode for faster analysis. Detailed mode for sentence-level analysis.",
803
  elem_classes=["description-text"])
804
 
805
+ # Container for radio buttons
806
+ with gr.Row(elem_id="radio-container"):
807
+ mode_selection = gr.Radio(
808
+ choices=["quick", "detailed"],
809
+ value="quick",
810
+ label=""
811
+ )
812
+
813
+ # Add paperclip as an HTML element next to the radio buttons
814
+ gr.HTML("""
815
+ <div id="paperclip-container">
816
+ <label for="hidden-file-input" id="paperclip-label">πŸ“Ž</label>
817
+ </div>
818
+ """, elem_id="paperclip-html")
819
+
820
+ # Hidden file upload
821
+ file_upload = gr.File(
822
+ file_types=["image", "pdf", "doc", "docx"],
823
+ type="binary",
824
+ visible=False,
825
+ elem_id="hidden-file-upload"
826
+ )
827
 
828
  # Action buttons row
829
+ with gr.Row():
830
  clear_btn = gr.Button("Clear", elem_id="clear-btn")
831
  analyze_btn = gr.Button("Analyze Text", elem_id="analyze-btn")
832
 
 
855
  outputs=[output_html, output_sentences, output_result]
856
  )
857
 
858
+ # Extensive custom CSS and JavaScript to make everything work properly
859
  gr.HTML("""
860
  <style>
861
  /* Button styling */
 
872
  color: black !important;
873
  }
874
 
875
+ /* Paperclip styling */
876
+ #paperclip-container {
877
+ display: inline-block;
878
+ position: relative;
879
+ top: -52px;
880
+ left: 170px;
881
+ width: 20px;
882
+ height: 20px;
883
+ z-index: 100;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
884
  }
885
 
886
+ #paperclip-label {
887
+ font-size: 18px;
888
+ opacity: 0.6;
889
+ cursor: pointer;
890
  }
891
 
892
+ #paperclip-label:hover {
893
+ opacity: 1;
 
 
 
 
 
 
894
  }
895
 
896
+ /* Hide the paperclip-html container (but not its contents) */
897
+ #paperclip-html {
898
+ height: 0;
899
+ overflow: visible;
900
+ margin: 0;
901
+ padding: 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
902
  }
903
 
904
  /* Description text styling */
 
909
  margin-bottom: 5px !important;
910
  }
911
  </style>
912
+
913
+ <script>
914
+ // Connect paperclip button to the hidden file input
915
+ document.addEventListener('DOMContentLoaded', function() {
916
+ setTimeout(function() {
917
+ const paperclipLabel = document.getElementById('paperclip-label');
918
+ const hiddenFileInput = document.querySelector('#hidden-file-upload input[type="file"]');
919
+
920
+ if (paperclipLabel && hiddenFileInput) {
921
+ paperclipLabel.addEventListener('click', function(e) {
922
+ e.preventDefault();
923
+ hiddenFileInput.click();
924
+ });
925
+ }
926
+ }, 1000); // Wait for Gradio to fully render
927
+ });
928
+ </script>
929
  """)
930
 
931
  return demo