Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -779,35 +779,32 @@ def create_interface():
|
|
779 |
border-color: #FF8C00 !important;
|
780 |
color: white !important;
|
781 |
}
|
782 |
-
|
783 |
-
/*
|
784 |
-
.
|
785 |
-
|
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:
|
798 |
-
|
799 |
-
display: inline-flex;
|
800 |
-
align-items: center;
|
801 |
-
justify-content: center;
|
802 |
}
|
803 |
|
804 |
-
|
805 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
806 |
}
|
807 |
|
808 |
-
|
809 |
-
|
810 |
-
display: none;
|
811 |
}
|
812 |
"""
|
813 |
|
@@ -825,13 +822,13 @@ def create_interface():
|
|
825 |
label="Input Text"
|
826 |
)
|
827 |
|
828 |
-
# Analysis Mode
|
829 |
gr.Markdown("Analysis Mode")
|
830 |
gr.Markdown("Quick mode for faster analysis. Detailed mode for sentence-level analysis.")
|
831 |
|
832 |
-
#
|
833 |
-
with gr.Row(elem_classes=["radio-
|
834 |
-
# Radio buttons for analysis mode
|
835 |
mode_selection = gr.Radio(
|
836 |
choices=["quick", "detailed"],
|
837 |
value="quick",
|
@@ -839,15 +836,24 @@ def create_interface():
|
|
839 |
show_label=False
|
840 |
)
|
841 |
|
842 |
-
#
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
849 |
|
850 |
-
# Analyze button
|
851 |
analyze_btn = gr.Button("Analyze Text", elem_id="analyze-btn")
|
852 |
|
853 |
# Right column - Results
|
@@ -864,45 +870,25 @@ def create_interface():
|
|
864 |
outputs=[output_html, output_sentences, output_result]
|
865 |
)
|
866 |
|
867 |
-
# 2.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
779 |
border-color: #FF8C00 !important;
|
780 |
color: white !important;
|
781 |
}
|
782 |
+
|
783 |
+
/* Style for our special file upload button to look like a paperclip */
|
784 |
+
.paperclip-button {
|
785 |
+
background: transparent;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
786 |
border: none;
|
787 |
font-size: 18px;
|
|
|
788 |
padding: 0;
|
789 |
+
min-width: 30px;
|
790 |
+
cursor: pointer;
|
|
|
|
|
|
|
791 |
}
|
792 |
|
793 |
+
/* Hide the standard gradio file upload interface */
|
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 |
+
/* Ensure the paperclip button appears next to the radio buttons */
|
801 |
+
.radio-container {
|
802 |
+
display: flex;
|
803 |
+
align-items: center;
|
804 |
}
|
805 |
|
806 |
+
.radio-container > div:first-child {
|
807 |
+
flex-grow: 1;
|
|
|
808 |
}
|
809 |
"""
|
810 |
|
|
|
822 |
label="Input Text"
|
823 |
)
|
824 |
|
825 |
+
# Analysis Mode section
|
826 |
gr.Markdown("Analysis Mode")
|
827 |
gr.Markdown("Quick mode for faster analysis. Detailed mode for sentence-level analysis.")
|
828 |
|
829 |
+
# Container for radio buttons and paperclip
|
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 |
show_label=False
|
837 |
)
|
838 |
|
839 |
+
# Create a minimal file upload button that looks like a paperclip
|
840 |
+
with gr.Column(elem_classes=["paperclip-container"], scale=0, min_width=40):
|
841 |
+
file_upload = gr.File(
|
842 |
+
file_types=["image", "pdf", "doc", "docx"],
|
843 |
+
type="binary",
|
844 |
+
label="",
|
845 |
+
show_label=False,
|
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 |
outputs=[output_html, output_sentences, output_result]
|
871 |
)
|
872 |
|
873 |
+
# 2. Paperclip button click - trigger file selector dialog
|
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 |
|