ApsidalSolid4 commited on
Commit
29740c6
·
verified ·
1 Parent(s): be06247

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -39
app.py CHANGED
@@ -780,28 +780,34 @@ def create_interface():
780
  color: white !important;
781
  }
782
 
783
- /* Clean styling for the upload button */
784
- .upload-document-btn {
785
  margin-left: 15px;
786
- height: 38px;
787
- padding: 0 15px;
788
- border-radius: 4px;
789
- background-color: #f0f0f0;
790
- border: 1px solid #d9d9d9;
791
- cursor: pointer;
792
- font-size: 14px;
793
- display: inline-flex;
794
- align-items: center;
795
- justify-content: center;
796
  }
797
 
798
- .upload-document-btn:hover {
799
- background-color: #e0e0e0;
 
800
  }
801
 
802
- /* Hide the standard file upload component */
803
- #hidden-file-upload {
804
- display: none !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
805
  }
806
  """
807
 
@@ -833,19 +839,13 @@ def create_interface():
833
  show_label=False
834
  )
835
 
836
- # Hidden file upload component
837
- file_upload = gr.File(
838
- file_types=["image", "pdf", "doc", "docx"],
839
- type="binary",
840
- elem_id="hidden-file-upload",
841
- visible=False
842
- )
843
-
844
- # Visible upload button
845
- upload_btn = gr.Button(
846
- "Upload Document",
847
- elem_classes=["upload-document-btn"]
848
- )
849
 
850
  # Analyze button
851
  analyze_btn = gr.Button("Analyze Text", elem_id="analyze-btn")
@@ -864,15 +864,7 @@ def create_interface():
864
  outputs=[output_html, output_sentences, output_result]
865
  )
866
 
867
- # 2. Upload button click - make file upload visible
868
- upload_btn.click(
869
- fn=lambda: gr.update(visible=True),
870
- inputs=None,
871
- outputs=file_upload,
872
- _js="() => {document.querySelector('#hidden-file-upload input[type=file]').click(); return {}}"
873
- )
874
-
875
- # 3. File upload change event
876
  file_upload.change(
877
  fn=handle_file_upload_and_analyze,
878
  inputs=[file_upload, mode_selection],
 
780
  color: white !important;
781
  }
782
 
783
+ /* Styling for the file upload component to make it look like a button */
784
+ .custom-file-upload {
785
  margin-left: 15px;
 
 
 
 
 
 
 
 
 
 
786
  }
787
 
788
+ /* Hide file upload preview */
789
+ .custom-file-upload .file-preview {
790
+ display: none !important;
791
  }
792
 
793
+ /* Style the file upload button to look like our desired Upload Document button */
794
+ .custom-file-upload > div:last-child {
795
+ height: 38px !important;
796
+ padding: 0 15px !important;
797
+ background-color: #f0f0f0 !important;
798
+ border: 1px solid #d9d9d9 !important;
799
+ border-radius: 4px !important;
800
+ }
801
+
802
+ /* Style the upload button text */
803
+ .custom-file-upload label span {
804
+ font-size: 14px !important;
805
+ font-weight: normal !important;
806
+ }
807
+
808
+ /* Hover effect */
809
+ .custom-file-upload > div:last-child:hover {
810
+ background-color: #e0e0e0 !important;
811
  }
812
  """
813
 
 
839
  show_label=False
840
  )
841
 
842
+ # Custom styled file upload component
843
+ with gr.Column(elem_classes=["custom-file-upload"], scale=0, min_width=150):
844
+ file_upload = gr.File(
845
+ file_types=["image", "pdf", "doc", "docx"],
846
+ type="binary",
847
+ label="Upload Document"
848
+ )
 
 
 
 
 
 
849
 
850
  # Analyze button
851
  analyze_btn = gr.Button("Analyze Text", elem_id="analyze-btn")
 
864
  outputs=[output_html, output_sentences, output_result]
865
  )
866
 
867
+ # 2. File upload change event - directly handle file upload without an intermediate button
 
 
 
 
 
 
 
 
868
  file_upload.change(
869
  fn=handle_file_upload_and_analyze,
870
  inputs=[file_upload, mode_selection],