ApsidalSolid4 commited on
Commit
225dc24
Β·
verified Β·
1 Parent(s): 83f1e8a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -91
app.py CHANGED
@@ -774,7 +774,7 @@ classifier = TextClassifier()
774
  # Create Gradio interface with a small file upload button next to the radio buttons
775
  # Modified approach - simplify by using custom HTML/CSS to achieve the exact layout
776
  def setup_interface():
777
- # Create analyzer functions that capture the classifier
778
  def analyze_text_wrapper(text, mode):
779
  return analyze_text(text, mode, classifier)
780
 
@@ -786,7 +786,34 @@ def setup_interface():
786
  def clear_inputs():
787
  return "", None, None, None
788
 
789
- with gr.Blocks(title="AI Text Detector") as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
790
  gr.Markdown("# AI Text Detector")
791
 
792
  with gr.Row():
@@ -799,35 +826,29 @@ def setup_interface():
799
  )
800
 
801
  gr.Markdown("Analysis Mode")
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
 
833
  # Right column - Results
@@ -849,84 +870,22 @@ def setup_interface():
849
  outputs=[text_input, output_html, output_sentences, output_result]
850
  )
851
 
 
 
 
 
 
 
 
 
 
 
 
852
  file_upload.change(
853
  handle_file_upload_wrapper,
854
  inputs=[file_upload, mode_selection],
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 */
862
- #analyze-btn {
863
- background-color: #FF8C00 !important;
864
- border-color: #FF8C00 !important;
865
- color: white !important;
866
- font-weight: normal !important;
867
- }
868
-
869
- #clear-btn {
870
- background-color: #E0E0E0 !important;
871
- border-color: #E0E0E0 !important;
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 */
905
- .description-text {
906
- font-size: 0.85em !important;
907
- color: #666 !important;
908
- margin-top: -10px !important;
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
932
  # Setup the app with CORS middleware
 
774
  # Create Gradio interface with a small file upload button next to the radio buttons
775
  # Modified approach - simplify by using custom HTML/CSS to achieve the exact layout
776
  def setup_interface():
777
+ # Create analyzer functions
778
  def analyze_text_wrapper(text, mode):
779
  return analyze_text(text, mode, classifier)
780
 
 
786
  def clear_inputs():
787
  return "", None, None, None
788
 
789
+ # Create a custom CSS class
790
+ css = """
791
+ #analyze-btn {
792
+ background-color: #FF8C00 !important;
793
+ border-color: #FF8C00 !important;
794
+ color: white !important;
795
+ }
796
+
797
+ .radio-with-icon {
798
+ display: flex;
799
+ align-items: center;
800
+ }
801
+
802
+ .paperclip-icon {
803
+ display: inline-block;
804
+ margin-left: 10px;
805
+ font-size: 20px;
806
+ cursor: pointer;
807
+ opacity: 0.7;
808
+ }
809
+
810
+ .paperclip-icon:hover {
811
+ opacity: 1;
812
+ }
813
+ """
814
+
815
+ # Create the interface with custom CSS
816
+ with gr.Blocks(title="AI Text Detector", css=css) as demo:
817
  gr.Markdown("# AI Text Detector")
818
 
819
  with gr.Row():
 
826
  )
827
 
828
  gr.Markdown("Analysis Mode")
829
+ gr.Markdown("Quick mode for faster analysis. Detailed mode for sentence-level analysis.")
 
830
 
831
+ # Create a visible radio button row
832
+ with gr.Row(elem_classes=["radio-with-icon"]):
833
  mode_selection = gr.Radio(
834
  choices=["quick", "detailed"],
835
  value="quick",
836
  label=""
837
  )
838
+
839
+ # Create a button that looks like a paperclip and triggers file upload
840
+ upload_trigger = gr.Button("πŸ“Ž", elem_classes=["paperclip-icon"])
841
 
842
+ # Hidden file upload that will be triggered by the paperclip button
 
 
 
 
 
 
 
843
  file_upload = gr.File(
844
  file_types=["image", "pdf", "doc", "docx"],
845
  type="binary",
846
+ visible=False
 
847
  )
848
 
849
+ # Action buttons
850
  with gr.Row():
851
+ clear_btn = gr.Button("Clear")
852
  analyze_btn = gr.Button("Analyze Text", elem_id="analyze-btn")
853
 
854
  # Right column - Results
 
870
  outputs=[text_input, output_html, output_sentences, output_result]
871
  )
872
 
873
+ # Make the paperclip button trigger the file upload
874
+ def trigger_upload():
875
+ return gr.update(visible=True)
876
+
877
+ upload_trigger.click(
878
+ trigger_upload,
879
+ inputs=None,
880
+ outputs=file_upload
881
+ )
882
+
883
+ # Process the file when uploaded
884
  file_upload.change(
885
  handle_file_upload_wrapper,
886
  inputs=[file_upload, mode_selection],
887
  outputs=[output_html, output_sentences, output_result]
888
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
889
 
890
  return demo
891
  # Setup the app with CORS middleware