Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -780,22 +780,34 @@ def create_interface():
|
|
780 |
color: white !important;
|
781 |
}
|
782 |
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
|
|
|
|
|
|
|
|
787 |
cursor: pointer;
|
|
|
|
|
|
|
|
|
788 |
padding: 0;
|
|
|
|
|
789 |
display: inline-flex;
|
790 |
align-items: center;
|
791 |
justify-content: center;
|
792 |
-
width: 30px;
|
793 |
-
height: 30px;
|
794 |
-
font-size: 18px;
|
795 |
}
|
796 |
|
797 |
-
.
|
798 |
-
opacity: 0.
|
|
|
|
|
|
|
|
|
|
|
799 |
}
|
800 |
"""
|
801 |
|
@@ -813,26 +825,26 @@ def create_interface():
|
|
813 |
label="Input Text"
|
814 |
)
|
815 |
|
816 |
-
# Analysis
|
817 |
-
|
|
|
|
|
|
|
|
|
|
|
818 |
mode_selection = gr.Radio(
|
819 |
choices=["quick", "detailed"],
|
820 |
value="quick",
|
821 |
-
label="
|
822 |
-
|
823 |
)
|
824 |
|
825 |
-
#
|
826 |
file_upload = gr.File(
|
827 |
file_types=["image", "pdf", "doc", "docx"],
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
# Visible file upload button (paperclip icon)
|
833 |
-
file_button = gr.Button(
|
834 |
-
"π",
|
835 |
-
elem_classes=["file-upload-btn"],
|
836 |
)
|
837 |
|
838 |
# Analyze button with custom styling
|
@@ -852,19 +864,45 @@ def create_interface():
|
|
852 |
outputs=[output_html, output_sentences, output_result]
|
853 |
)
|
854 |
|
855 |
-
# 2. File
|
856 |
-
file_button.click(
|
857 |
-
fn=lambda: gr.update(visible=True),
|
858 |
-
inputs=None,
|
859 |
-
outputs=file_upload
|
860 |
-
)
|
861 |
-
|
862 |
-
# 3. File upload change event
|
863 |
file_upload.change(
|
864 |
fn=handle_file_upload_and_analyze,
|
865 |
inputs=[file_upload, mode_selection],
|
866 |
outputs=[output_html, output_sentences, output_result]
|
867 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
868 |
|
869 |
return demo
|
870 |
|
|
|
780 |
color: white !important;
|
781 |
}
|
782 |
|
783 |
+
/* Custom styling for the radio group container */
|
784 |
+
.radio-group-container {
|
785 |
+
display: flex;
|
786 |
+
align-items: center;
|
787 |
+
}
|
788 |
+
|
789 |
+
/* Paperclip button styling */
|
790 |
+
.paperclip-btn {
|
791 |
cursor: pointer;
|
792 |
+
background: none;
|
793 |
+
border: none;
|
794 |
+
font-size: 18px;
|
795 |
+
margin-left: 10px;
|
796 |
padding: 0;
|
797 |
+
width: 24px;
|
798 |
+
height: 24px;
|
799 |
display: inline-flex;
|
800 |
align-items: center;
|
801 |
justify-content: center;
|
|
|
|
|
|
|
802 |
}
|
803 |
|
804 |
+
.paperclip-btn:hover {
|
805 |
+
opacity: 0.7;
|
806 |
+
}
|
807 |
+
|
808 |
+
/* Hide the actual file upload element but make it accessible */
|
809 |
+
#file-upload {
|
810 |
+
display: none;
|
811 |
}
|
812 |
"""
|
813 |
|
|
|
825 |
label="Input Text"
|
826 |
)
|
827 |
|
828 |
+
# Analysis Mode label
|
829 |
+
gr.Markdown("Analysis Mode")
|
830 |
+
gr.Markdown("Quick mode for faster analysis. Detailed mode for sentence-level analysis.")
|
831 |
+
|
832 |
+
# Create a row for radio buttons and paperclip
|
833 |
+
with gr.Row(elem_classes=["radio-group-container"]):
|
834 |
+
# Radio buttons for analysis mode selection
|
835 |
mode_selection = gr.Radio(
|
836 |
choices=["quick", "detailed"],
|
837 |
value="quick",
|
838 |
+
label="",
|
839 |
+
show_label=False
|
840 |
)
|
841 |
|
842 |
+
# File upload component (will be triggered by paperclip)
|
843 |
file_upload = gr.File(
|
844 |
file_types=["image", "pdf", "doc", "docx"],
|
845 |
+
type="binary",
|
846 |
+
elem_id="file-upload",
|
847 |
+
visible=True, # Set to visible but we'll hide it with CSS
|
|
|
|
|
|
|
|
|
|
|
848 |
)
|
849 |
|
850 |
# Analyze button with custom styling
|
|
|
864 |
outputs=[output_html, output_sentences, output_result]
|
865 |
)
|
866 |
|
867 |
+
# 2. File upload change event
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
868 |
file_upload.change(
|
869 |
fn=handle_file_upload_and_analyze,
|
870 |
inputs=[file_upload, mode_selection],
|
871 |
outputs=[output_html, output_sentences, output_result]
|
872 |
)
|
873 |
+
|
874 |
+
# Add custom JavaScript for the paperclip functionality
|
875 |
+
demo.load(js="""
|
876 |
+
function setupPaperclip() {
|
877 |
+
// Get the file upload element and its parent
|
878 |
+
const fileUpload = document.getElementById('file-upload');
|
879 |
+
const radioGroup = document.querySelector('.radio-group-container');
|
880 |
+
|
881 |
+
// Create paperclip button
|
882 |
+
const paperclip = document.createElement('button');
|
883 |
+
paperclip.innerHTML = 'π';
|
884 |
+
paperclip.className = 'paperclip-btn';
|
885 |
+
paperclip.title = 'Upload a document';
|
886 |
+
|
887 |
+
// Insert paperclip button after the radio group
|
888 |
+
radioGroup.appendChild(paperclip);
|
889 |
+
|
890 |
+
// When paperclip is clicked, trigger the file upload dialog
|
891 |
+
paperclip.addEventListener('click', function() {
|
892 |
+
fileUpload.querySelector('input[type="file"]').click();
|
893 |
+
});
|
894 |
+
|
895 |
+
// Make the file upload container itself invisible (but still functional)
|
896 |
+
fileUpload.style.display = 'none';
|
897 |
+
}
|
898 |
+
|
899 |
+
// Run setup when page loads
|
900 |
+
if (document.readyState === 'complete') {
|
901 |
+
setupPaperclip();
|
902 |
+
} else {
|
903 |
+
window.addEventListener('load', setupPaperclip);
|
904 |
+
}
|
905 |
+
""")
|
906 |
|
907 |
return demo
|
908 |
|