Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -779,32 +779,35 @@ def create_interface():
|
|
779 |
border-color: #FF8C00 !important;
|
780 |
color: white !important;
|
781 |
}
|
782 |
-
|
783 |
-
/*
|
784 |
-
.
|
785 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
786 |
border: none;
|
787 |
font-size: 18px;
|
|
|
788 |
padding: 0;
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
.paperclip-container .file-preview,
|
795 |
-
.paperclip-container .file-preview > div:first-child,
|
796 |
-
.paperclip-container label span {
|
797 |
-
display: none !important;
|
798 |
}
|
799 |
|
800 |
-
|
801 |
-
|
802 |
-
display: flex;
|
803 |
-
align-items: center;
|
804 |
}
|
805 |
|
806 |
-
|
807 |
-
|
|
|
808 |
}
|
809 |
"""
|
810 |
|
@@ -822,13 +825,13 @@ def create_interface():
|
|
822 |
label="Input Text"
|
823 |
)
|
824 |
|
825 |
-
# Analysis Mode
|
826 |
gr.Markdown("Analysis Mode")
|
827 |
gr.Markdown("Quick mode for faster analysis. Detailed mode for sentence-level analysis.")
|
828 |
|
829 |
-
#
|
830 |
-
with gr.Row(elem_classes=["radio-container"]):
|
831 |
-
# Radio buttons for analysis mode
|
832 |
mode_selection = gr.Radio(
|
833 |
choices=["quick", "detailed"],
|
834 |
value="quick",
|
@@ -836,24 +839,15 @@ def create_interface():
|
|
836 |
show_label=False
|
837 |
)
|
838 |
|
839 |
-
#
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
elem_id="file-upload"
|
847 |
-
)
|
848 |
-
|
849 |
-
# Add a simple overlay button that looks like a paperclip
|
850 |
-
paperclip_btn = gr.Button(
|
851 |
-
"📎",
|
852 |
-
elem_classes=["paperclip-button"],
|
853 |
-
size="sm"
|
854 |
-
)
|
855 |
|
856 |
-
# Analyze button
|
857 |
analyze_btn = gr.Button("Analyze Text", elem_id="analyze-btn")
|
858 |
|
859 |
# Right column - Results
|
@@ -870,25 +864,45 @@ def create_interface():
|
|
870 |
outputs=[output_html, output_sentences, output_result]
|
871 |
)
|
872 |
|
873 |
-
# 2.
|
874 |
-
def trigger_file_selector():
|
875 |
-
# This function doesn't need to do anything - the button will visually
|
876 |
-
# overlap with the file upload component's button
|
877 |
-
return None
|
878 |
-
|
879 |
-
paperclip_btn.click(
|
880 |
-
fn=trigger_file_selector,
|
881 |
-
inputs=None,
|
882 |
-
outputs=None,
|
883 |
-
_js="() => {document.querySelector('#file-upload input[type=file]').click()}"
|
884 |
-
)
|
885 |
-
|
886 |
-
# 3. File upload change event
|
887 |
file_upload.change(
|
888 |
fn=handle_file_upload_and_analyze,
|
889 |
inputs=[file_upload, mode_selection],
|
890 |
outputs=[output_html, output_sentences, output_result]
|
891 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
892 |
|
893 |
return demo
|
894 |
|
|
|
779 |
border-color: #FF8C00 !important;
|
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",
|
|
|
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
|
851 |
analyze_btn = gr.Button("Analyze Text", elem_id="analyze-btn")
|
852 |
|
853 |
# Right column - Results
|
|
|
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 |
|