ApsidalSolid4 commited on
Commit
0b18d85
·
verified ·
1 Parent(s): 1419b33

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +86 -43
app.py CHANGED
@@ -779,42 +779,46 @@ def setup_interface():
779
 
780
  def handle_file_upload_wrapper(file_obj, mode):
781
  if file_obj is None:
782
- return analyze_text_wrapper("", mode) # Return empty analysis
783
  return handle_file_upload_and_analyze(file_obj, mode, classifier)
784
 
785
- # Create the interface similar to the original but with a small file upload button
786
  with gr.Blocks(title="AI Text Detector") as demo:
787
  gr.Markdown("# AI Text Detector")
788
 
789
  with gr.Row():
790
- # Left column for input
791
  with gr.Column():
792
  text_input = gr.Textbox(
793
- lines=8,
794
  placeholder="Enter text to analyze...",
795
  label="Input Text"
796
  )
797
 
798
- with gr.Row():
799
- # Mode selection (same as original)
800
- mode_selection = gr.Radio(
801
- choices=["quick", "detailed"],
802
- value="quick",
803
- label="Analysis Mode",
804
- info="Quick mode for faster analysis. Detailed mode for sentence-level analysis."
805
- )
806
 
807
- # Small file upload button (like the Claude paperclip)
808
- file_upload = gr.File(
809
- label="",
810
- file_types=["image", "pdf", "doc", "docx"],
811
- type="binary",
812
- elem_classes=["small-file-upload"]
813
- )
 
 
 
 
 
 
 
 
814
 
815
  analyze_button = gr.Button("Analyze Text")
816
 
817
- # Right column for output
818
  with gr.Column():
819
  output_html = gr.HTML(label="Highlighted Analysis")
820
  output_sentences = gr.Textbox(label="Sentence-by-Sentence Analysis", lines=10)
@@ -833,44 +837,83 @@ def setup_interface():
833
  outputs=[output_html, output_sentences, output_result]
834
  )
835
 
836
- # Custom CSS to style the file upload button like a small paperclip
837
  gr.HTML("""
838
  <style>
839
- /* Make the file upload small and positioned correctly */
840
- .small-file-upload {
 
841
  width: 40px !important;
 
842
  margin-left: 10px !important;
843
- margin-top: 15px !important;
844
  }
845
 
846
- .small-file-upload > .wrap {
847
- padding: 0 !important;
848
- margin: 0 !important;
 
 
 
849
  }
850
 
851
- .small-file-upload .file-preview {
852
- min-height: 0 !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
853
  padding: 0 !important;
 
 
854
  }
855
 
856
- /* Make file upload look like a paperclip icon */
857
- .small-file-upload .icon {
858
- font-size: 1.2em !important;
859
- opacity: 0.7 !important;
860
  }
861
 
862
- .small-file-upload .upload-button {
863
- border-radius: 50% !important;
864
- padding: 5px !important;
865
- width: 30px !important;
866
- height: 30px !important;
867
- display: flex !important;
868
- align-items: center !important;
869
- justify-content: center !important;
870
  }
871
 
872
- .small-file-upload .upload-button:hover {
873
- background-color: #f0f0f0 !important;
 
874
  }
875
  </style>
876
  """)
 
779
 
780
  def handle_file_upload_wrapper(file_obj, mode):
781
  if file_obj is None:
782
+ return analyze_text_wrapper("", mode)
783
  return handle_file_upload_and_analyze(file_obj, mode, classifier)
784
 
 
785
  with gr.Blocks(title="AI Text Detector") as demo:
786
  gr.Markdown("# AI Text Detector")
787
 
788
  with gr.Row():
789
+ # Left column - Input
790
  with gr.Column():
791
  text_input = gr.Textbox(
792
+ lines=8,
793
  placeholder="Enter text to analyze...",
794
  label="Input Text"
795
  )
796
 
797
+ # Custom container for radio buttons and small file upload
798
+ with gr.Column():
799
+ gr.Markdown("Analysis Mode", elem_id="analysis-mode-label")
800
+ gr.Markdown("Quick mode for faster analysis. Detailed mode for sentence-level analysis.",
801
+ elem_classes=["description-text"])
 
 
 
802
 
803
+ with gr.Row():
804
+ mode_selection = gr.Radio(
805
+ choices=["quick", "detailed"],
806
+ value="quick",
807
+ label="",
808
+ elem_classes=["mode-radio"]
809
+ )
810
+
811
+ # Tiny file button (hidden until CSS applies)
812
+ file_upload = gr.File(
813
+ file_types=["image", "pdf", "doc", "docx"],
814
+ type="binary",
815
+ label="",
816
+ elem_id="tiny-file-upload"
817
+ )
818
 
819
  analyze_button = gr.Button("Analyze Text")
820
 
821
+ # Right column - Results
822
  with gr.Column():
823
  output_html = gr.HTML(label="Highlighted Analysis")
824
  output_sentences = gr.Textbox(label="Sentence-by-Sentence Analysis", lines=10)
 
837
  outputs=[output_html, output_sentences, output_result]
838
  )
839
 
840
+ # Custom CSS that completely transforms the file upload into a small icon
841
  gr.HTML("""
842
  <style>
843
+ /* Hide the default file upload completely */
844
+ #tiny-file-upload {
845
+ position: relative;
846
  width: 40px !important;
847
+ vertical-align: middle !important;
848
  margin-left: 10px !important;
849
+ margin-top: 5px !important;
850
  }
851
 
852
+ #tiny-file-upload > .wrap {
853
+ position: relative;
854
+ display: inline-block;
855
+ width: 32px !important;
856
+ height: 32px !important;
857
+ overflow: hidden;
858
  }
859
 
860
+ /* Hide all the default upload UI elements */
861
+ #tiny-file-upload .file-preview,
862
+ #tiny-file-upload .file-preview p,
863
+ #tiny-file-upload .hidden-upload,
864
+ #tiny-file-upload .upload-prompt,
865
+ #tiny-file-upload .remove-file,
866
+ #tiny-file-upload > label {
867
+ display: none !important;
868
+ }
869
+
870
+ /* Create a paperclip-like button */
871
+ #tiny-file-upload .wrap:before {
872
+ content: "📎";
873
+ font-size: 20px;
874
+ position: absolute;
875
+ top: 2px;
876
+ left: 5px;
877
+ opacity: 0.7;
878
+ cursor: pointer;
879
+ z-index: 10;
880
+ }
881
+
882
+ #tiny-file-upload .wrap:hover:before {
883
+ opacity: 1;
884
+ }
885
+
886
+ /* Adjust upload zone to be clickable but mostly invisible */
887
+ #tiny-file-upload .upload-button {
888
+ position: absolute;
889
+ width: 32px !important;
890
+ height: 32px !important;
891
+ left: 0 !important;
892
+ top: 0 !important;
893
+ opacity: 0.01 !important;
894
+ margin: 0 !important;
895
  padding: 0 !important;
896
+ cursor: pointer !important;
897
+ z-index: 5 !important;
898
  }
899
 
900
+ /* Fix the radio button alignment */
901
+ .mode-radio {
902
+ margin-top: 0 !important;
903
+ display: inline-block !important;
904
  }
905
 
906
+ /* Make description text smaller */
907
+ .description-text {
908
+ font-size: 0.85em;
909
+ color: #666;
910
+ margin-top: -5px;
911
+ margin-bottom: 5px;
 
 
912
  }
913
 
914
+ /* More compact layout */
915
+ #analysis-mode-label {
916
+ margin-bottom: 0 !important;
917
  }
918
  </style>
919
  """)