ApsidalSolid4 commited on
Commit
4a931a3
·
verified ·
1 Parent(s): 0177d87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -30
app.py CHANGED
@@ -770,7 +770,7 @@ def analyze_text(text: str, mode: str, classifier: TextClassifier) -> tuple:
770
  # Initialize the classifier globally
771
  classifier = TextClassifier()
772
 
773
- # Create Gradio interface with a clear "Upload Document" button
774
  def create_interface():
775
  # Custom CSS for the interface
776
  css = """
@@ -780,28 +780,32 @@ def create_interface():
780
  color: white !important;
781
  }
782
 
783
- /* Styling for file upload button */
784
- .file-uploader {
785
  margin-left: 15px;
 
 
 
 
 
786
  }
787
 
788
- /* Hide the standard file upload appearance */
789
- .file-uploader .file-preview {
 
 
 
 
 
790
  display: none !important;
791
  }
792
 
793
- /* Hide the drop area text */
794
- .file-uploader .file-drop {
795
- display: none !important;
796
- }
797
-
798
- /* Hide the "or" text */
799
- .file-uploader p {
800
- display: none !important;
801
- }
802
-
803
- /* Style the actual button */
804
- .file-uploader > div:last-child {
805
  height: 40px !important;
806
  padding: 0 15px !important;
807
  background-color: #f0f0f0 !important;
@@ -810,19 +814,31 @@ def create_interface():
810
  display: flex !important;
811
  align-items: center !important;
812
  justify-content: center !important;
 
813
  }
814
 
815
  /* Style the button text */
816
- .file-uploader label span {
817
  font-size: 14px !important;
818
  font-weight: normal !important;
819
  margin: 0 !important;
 
820
  }
821
 
822
  /* Hover effect */
823
- .file-uploader > div:last-child:hover {
824
  background-color: #e0e0e0 !important;
825
  }
 
 
 
 
 
 
 
 
 
 
826
  """
827
 
828
  with gr.Blocks(css=css, title="AI Text Detector") as demo:
@@ -843,9 +859,8 @@ def create_interface():
843
  gr.Markdown("Analysis Mode")
844
  gr.Markdown("Quick mode for faster analysis. Detailed mode for sentence-level analysis.")
845
 
846
- # Create a row for radio buttons and upload button
847
  with gr.Row():
848
- # Radio buttons for analysis mode
849
  mode_selection = gr.Radio(
850
  choices=["quick", "detailed"],
851
  value="quick",
@@ -853,14 +868,12 @@ def create_interface():
853
  show_label=False
854
  )
855
 
856
- # File upload component
857
- file_upload = gr.File(
858
- file_types=["image", "pdf", "doc", "docx"],
859
- type="binary",
860
- label="Upload Document",
861
- elem_classes=["file-uploader"],
862
- interactive=True
863
- )
864
 
865
  # Analyze button
866
  analyze_btn = gr.Button("Analyze Text", elem_id="analyze-btn")
@@ -879,7 +892,7 @@ def create_interface():
879
  outputs=[output_html, output_sentences, output_result]
880
  )
881
 
882
- # 2. File upload change event - directly handle file upload without an intermediate button
883
  file_upload.change(
884
  fn=handle_file_upload_and_analyze,
885
  inputs=[file_upload, mode_selection],
 
770
  # Initialize the classifier globally
771
  classifier = TextClassifier()
772
 
773
+ # Create Gradio interface with a file upload button matched to the radio buttons
774
  def create_interface():
775
  # Custom CSS for the interface
776
  css = """
 
780
  color: white !important;
781
  }
782
 
783
+ /* Make upload button container match radio button container size */
784
+ .file-upload-container {
785
  margin-left: 15px;
786
+ width: 150px;
787
+ height: 40px;
788
+ display: inline-block;
789
+ vertical-align: middle;
790
+ position: relative;
791
  }
792
 
793
+ /* Hide ALL the default file upload elements */
794
+ .file-upload-container .file-preview,
795
+ .file-upload-container .file-drop,
796
+ .file-upload-container p,
797
+ .file-upload-container svg,
798
+ .file-upload-container [data-testid="chunkFileDropArea"],
799
+ .file-upload-container [data-testid="droparea"] {
800
  display: none !important;
801
  }
802
 
803
+ /* Style the button to look exactly like we want */
804
+ .file-upload-container > div:last-child {
805
+ position: absolute !important;
806
+ top: 0 !important;
807
+ left: 0 !important;
808
+ width: 100% !important;
 
 
 
 
 
 
809
  height: 40px !important;
810
  padding: 0 15px !important;
811
  background-color: #f0f0f0 !important;
 
814
  display: flex !important;
815
  align-items: center !important;
816
  justify-content: center !important;
817
+ margin: 0 !important;
818
  }
819
 
820
  /* Style the button text */
821
+ .file-upload-container label span {
822
  font-size: 14px !important;
823
  font-weight: normal !important;
824
  margin: 0 !important;
825
+ display: inline-block !important;
826
  }
827
 
828
  /* Hover effect */
829
+ .file-upload-container > div:last-child:hover {
830
  background-color: #e0e0e0 !important;
831
  }
832
+
833
+ /* Hide any additional elements that might appear */
834
+ .file-upload-container * {
835
+ margin: 0 !important;
836
+ }
837
+
838
+ /* Hide the file selection area */
839
+ .file-upload-container div[data-testid="block"] > div[data-testid="droparea"] {
840
+ display: none !important;
841
+ }
842
  """
843
 
844
  with gr.Blocks(css=css, title="AI Text Detector") as demo:
 
859
  gr.Markdown("Analysis Mode")
860
  gr.Markdown("Quick mode for faster analysis. Detailed mode for sentence-level analysis.")
861
 
862
+ # Simple row layout for radio buttons and file upload
863
  with gr.Row():
 
864
  mode_selection = gr.Radio(
865
  choices=["quick", "detailed"],
866
  value="quick",
 
868
  show_label=False
869
  )
870
 
871
+ with gr.Column(elem_classes=["file-upload-container"], scale=0):
872
+ file_upload = gr.File(
873
+ file_types=["image", "pdf", "doc", "docx"],
874
+ type="binary",
875
+ label="Upload Document"
876
+ )
 
 
877
 
878
  # Analyze button
879
  analyze_btn = gr.Button("Analyze Text", elem_id="analyze-btn")
 
892
  outputs=[output_html, output_sentences, output_result]
893
  )
894
 
895
+ # 2. File upload change event
896
  file_upload.change(
897
  fn=handle_file_upload_and_analyze,
898
  inputs=[file_upload, mode_selection],