ApsidalSolid4 commited on
Commit
bc0ac29
·
verified ·
1 Parent(s): 927052a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -31
app.py CHANGED
@@ -814,7 +814,7 @@ def analyze_text(text: str, mode: str, classifier: TextClassifier) -> tuple:
814
  # Modified Gradio interface setup function to include file upload
815
  def setup_gradio_interface(classifier):
816
  """
817
- Set up Gradio interface with original layout plus a small file upload button
818
 
819
  Args:
820
  classifier: The TextClassifier instance
@@ -833,7 +833,6 @@ def setup_gradio_interface(classifier):
833
  return analyze_text_wrapper("", mode) # Return empty analysis
834
  return handle_file_upload_and_analyze(file_obj, mode, classifier)
835
 
836
- # Create layout with side-by-side content
837
  with gr.Blocks(title="AI Text Detector") as demo:
838
  gr.Markdown("# AI Text Detector")
839
 
@@ -847,61 +846,81 @@ def setup_gradio_interface(classifier):
847
  )
848
 
849
  with gr.Row():
850
- # Analysis mode selection
851
- mode_selection = gr.Radio(
852
- choices=["quick", "detailed"],
853
- value="quick",
854
- label="Analysis Mode",
855
- info="Quick mode for faster analysis, Detailed mode for sentence-level analysis"
856
- )
 
 
857
 
858
- # Small file upload button (similar to paperclip in Claude)
859
- file_upload = gr.File(
860
- label="",
861
- file_types=["image", "pdf", "doc", "docx"],
862
- type="binary",
863
- elem_id="file_upload_small"
864
- )
 
865
 
866
- # Original analyze button
867
  analyze_button = gr.Button("Analyze Text")
868
 
869
- # Right column - Results (same as original)
870
  with gr.Column():
871
  output_html = gr.HTML(label="Highlighted Analysis")
872
  output_sentences = gr.Textbox(label="Sentence-by-Sentence Analysis", lines=10)
873
  output_result = gr.Textbox(label="Overall Result", lines=4)
874
 
875
- # Connect original analyze button
876
  analyze_button.click(
877
  analyze_text_wrapper,
878
  inputs=[text_input, mode_selection],
879
  outputs=[output_html, output_sentences, output_result]
880
  )
881
 
882
- # Connect file upload changes to automatically process
883
  file_upload.change(
884
  handle_file_upload_wrapper,
885
  inputs=[file_upload, mode_selection],
886
  outputs=[output_html, output_sentences, output_result]
887
  )
888
 
889
- # Add CSS to make file upload button small and icon-like
890
  gr.HTML("""
891
  <style>
892
- #file_upload_small {
893
- max-width: 50px;
894
- margin-top: 25px;
895
  }
896
- #file_upload_small .label-wrap {
897
- display: none;
 
 
 
 
 
 
898
  }
899
- </style>
900
- """)
901
 
902
- # Small text about file upload (at bottom)
903
- gr.Markdown("""
904
- *You can also upload an image, PDF, or Word document (max 1MB) for OCR text extraction and analysis.*
 
 
 
 
 
 
 
 
 
 
 
 
 
905
  """)
906
 
907
  return demo
 
814
  # Modified Gradio interface setup function to include file upload
815
  def setup_gradio_interface(classifier):
816
  """
817
+ Set up Gradio interface with a more aligned and compact file upload
818
 
819
  Args:
820
  classifier: The TextClassifier instance
 
833
  return analyze_text_wrapper("", mode) # Return empty analysis
834
  return handle_file_upload_and_analyze(file_obj, mode, classifier)
835
 
 
836
  with gr.Blocks(title="AI Text Detector") as demo:
837
  gr.Markdown("# AI Text Detector")
838
 
 
846
  )
847
 
848
  with gr.Row():
849
+ # Left side: Analysis mode radio buttons
850
+ with gr.Column(scale=4):
851
+ gr.Markdown("Analysis Mode")
852
+ gr.Markdown("Quick mode for faster analysis. Detailed mode for sentence-level analysis.", elem_classes=["description-text"])
853
+ mode_selection = gr.Radio(
854
+ choices=["quick", "detailed"],
855
+ value="quick",
856
+ label=""
857
+ )
858
 
859
+ # Right side: File upload (compact and aligned)
860
+ with gr.Column(scale=1, elem_classes=["file-upload-container"]):
861
+ file_upload = gr.File(
862
+ label="File",
863
+ file_types=["image", "pdf", "doc", "docx"],
864
+ type="binary",
865
+ elem_classes=["compact-file-upload"]
866
+ )
867
 
868
+ # Analyze button
869
  analyze_button = gr.Button("Analyze Text")
870
 
871
+ # Right column - Results
872
  with gr.Column():
873
  output_html = gr.HTML(label="Highlighted Analysis")
874
  output_sentences = gr.Textbox(label="Sentence-by-Sentence Analysis", lines=10)
875
  output_result = gr.Textbox(label="Overall Result", lines=4)
876
 
877
+ # Connect buttons to functions
878
  analyze_button.click(
879
  analyze_text_wrapper,
880
  inputs=[text_input, mode_selection],
881
  outputs=[output_html, output_sentences, output_result]
882
  )
883
 
884
+ # Connect file upload to automatically process when changed
885
  file_upload.change(
886
  handle_file_upload_wrapper,
887
  inputs=[file_upload, mode_selection],
888
  outputs=[output_html, output_sentences, output_result]
889
  )
890
 
891
+ # Add custom CSS for alignment and styling
892
  gr.HTML("""
893
  <style>
894
+ /* Make file upload more compact */
895
+ .compact-file-upload {
896
+ max-width: 100%;
897
  }
898
+
899
+ .compact-file-upload > .wrap {
900
+ margin: 0;
901
+ padding: 0;
902
+ }
903
+
904
+ .compact-file-upload .file-preview {
905
+ min-height: 0;
906
  }
 
 
907
 
908
+ /* Align file upload with radio buttons */
909
+ .file-upload-container {
910
+ display: flex;
911
+ align-items: flex-end;
912
+ justify-content: center;
913
+ padding-bottom: 10px;
914
+ }
915
+
916
+ /* Make description text smaller */
917
+ .description-text {
918
+ font-size: 0.85em;
919
+ color: #666;
920
+ margin-top: -5px;
921
+ margin-bottom: 5px;
922
+ }
923
+ </style>
924
  """)
925
 
926
  return demo