ApsidalSolid4 commited on
Commit
f61bc7a
·
verified ·
1 Parent(s): d00b248

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -27
app.py CHANGED
@@ -772,7 +772,7 @@ 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 - simplified to focus on essential styling
776
  css = """
777
  #analyze-btn {
778
  background-color: #FF8C00 !important;
@@ -780,30 +780,46 @@ def create_interface():
780
  color: white !important;
781
  }
782
 
783
- /* Style file upload button container */
784
- .upload-btn-container {
785
- display: inline-block;
786
- margin-left: 15px;
787
- vertical-align: middle;
788
  }
789
 
790
- /* Target Gradio's file upload component */
791
- .upload-btn-container > div {
792
- width: 150px !important;
793
- box-sizing: border-box !important;
 
 
 
794
  }
795
 
796
- /* Fix the height to match radio buttons */
797
- .upload-btn-container button {
798
  height: 40px !important;
799
- border-radius: 4px !important;
800
  background-color: #f0f0f0 !important;
801
- color: #333 !important;
802
  border: 1px solid #d9d9d9 !important;
 
 
803
  font-size: 14px !important;
804
- line-height: normal !important;
805
- padding: 8px 12px !important;
 
806
  margin: 0 !important;
 
 
 
 
 
 
 
 
 
 
 
 
807
  }
808
  """
809
 
@@ -825,7 +841,7 @@ def create_interface():
825
  gr.Markdown("Analysis Mode")
826
  gr.Markdown("Quick mode for faster analysis. Detailed mode for sentence-level analysis.")
827
 
828
- # Simple row layout for radio buttons
829
  with gr.Row():
830
  mode_selection = gr.Radio(
831
  choices=["quick", "detailed"],
@@ -834,13 +850,13 @@ def create_interface():
834
  show_label=False
835
  )
836
 
837
- # File upload in a custom-styled container
838
- with gr.Column(elem_classes=["upload-btn-container"], scale=0):
839
- file_upload = gr.UploadButton(
840
- label="Upload Document",
841
- file_types=["image", "pdf", "doc", "docx"],
842
- size="sm"
843
- )
844
 
845
  # Analyze button
846
  analyze_btn = gr.Button("Analyze Text", elem_id="analyze-btn")
@@ -858,9 +874,9 @@ def create_interface():
858
  outputs=[output_html, output_sentences, output_result]
859
  )
860
 
861
- # Connect file upload
862
- file_upload.upload(
863
- fn=lambda file, mode: handle_file_upload_and_analyze(file, mode, classifier),
864
  inputs=[file_upload, mode_selection],
865
  outputs=[output_html, output_sentences, output_result]
866
  )
 
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 = """
777
  #analyze-btn {
778
  background-color: #FF8C00 !important;
 
780
  color: white !important;
781
  }
782
 
783
+ /* Style the file upload to be more compact */
784
+ .file-upload {
785
+ width: 150px !important;
786
+ margin-left: 15px !important;
 
787
  }
788
 
789
+ /* Hide file preview elements */
790
+ .file-upload .file-preview,
791
+ .file-upload p:not(.file-upload p:first-child),
792
+ .file-upload svg,
793
+ .file-upload [data-testid="chunkFileDropArea"],
794
+ .file-upload .file-drop {
795
+ display: none !important;
796
  }
797
 
798
+ /* Style the upload button */
799
+ .file-upload button {
800
  height: 40px !important;
801
+ width: 100% !important;
802
  background-color: #f0f0f0 !important;
 
803
  border: 1px solid #d9d9d9 !important;
804
+ border-radius: 4px !important;
805
+ color: #333 !important;
806
  font-size: 14px !important;
807
+ display: flex !important;
808
+ align-items: center !important;
809
+ justify-content: center !important;
810
  margin: 0 !important;
811
+ padding: 0 !important;
812
+ }
813
+
814
+ /* Hide the "or" text */
815
+ .file-upload .or {
816
+ display: none !important;
817
+ }
818
+
819
+ /* Make the container compact */
820
+ .file-upload [data-testid="block"] {
821
+ margin: 0 !important;
822
+ padding: 0 !important;
823
  }
824
  """
825
 
 
841
  gr.Markdown("Analysis Mode")
842
  gr.Markdown("Quick mode for faster analysis. Detailed mode for sentence-level analysis.")
843
 
844
+ # Simple row layout for radio buttons and file upload
845
  with gr.Row():
846
  mode_selection = gr.Radio(
847
  choices=["quick", "detailed"],
 
850
  show_label=False
851
  )
852
 
853
+ # Revert to File component but with better styling
854
+ file_upload = gr.File(
855
+ file_types=["image", "pdf", "doc", "docx"],
856
+ type="binary",
857
+ label="Upload Document",
858
+ elem_classes=["file-upload"]
859
+ )
860
 
861
  # Analyze button
862
  analyze_btn = gr.Button("Analyze Text", elem_id="analyze-btn")
 
874
  outputs=[output_html, output_sentences, output_result]
875
  )
876
 
877
+ # Use the original file upload handler
878
+ file_upload.change(
879
+ fn=handle_file_upload_and_analyze,
880
  inputs=[file_upload, mode_selection],
881
  outputs=[output_html, output_sentences, output_result]
882
  )