Update app.py
Browse files
app.py
CHANGED
@@ -780,28 +780,34 @@ def create_interface():
|
|
780 |
color: white !important;
|
781 |
}
|
782 |
|
783 |
-
/*
|
784 |
-
.
|
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 |
-
|
799 |
-
|
|
|
800 |
}
|
801 |
|
802 |
-
/*
|
803 |
-
|
804 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
805 |
}
|
806 |
"""
|
807 |
|
@@ -833,19 +839,13 @@ def create_interface():
|
|
833 |
show_label=False
|
834 |
)
|
835 |
|
836 |
-
#
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
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.
|
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],
|