Update app.py
Browse files
app.py
CHANGED
|
@@ -802,28 +802,31 @@ def setup_interface():
|
|
| 802 |
gr.Markdown("Quick mode for faster analysis. Detailed mode for sentence-level analysis.",
|
| 803 |
elem_classes=["description-text"])
|
| 804 |
|
| 805 |
-
#
|
| 806 |
-
with gr.Row(elem_id="
|
| 807 |
-
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
|
| 813 |
-
|
| 814 |
-
|
| 815 |
-
|
| 816 |
-
|
| 817 |
-
|
| 818 |
-
|
| 819 |
-
|
| 820 |
-
|
| 821 |
-
|
| 822 |
-
|
| 823 |
-
|
|
|
|
|
|
|
|
|
|
| 824 |
|
| 825 |
# Action buttons row
|
| 826 |
-
with gr.Row(
|
| 827 |
clear_btn = gr.Button("Clear", elem_id="clear-btn")
|
| 828 |
analyze_btn = gr.Button("Analyze Text", elem_id="analyze-btn")
|
| 829 |
|
|
@@ -852,7 +855,7 @@ def setup_interface():
|
|
| 852 |
outputs=[output_html, output_sentences, output_result]
|
| 853 |
)
|
| 854 |
|
| 855 |
-
#
|
| 856 |
gr.HTML("""
|
| 857 |
<style>
|
| 858 |
/* Button styling */
|
|
@@ -869,67 +872,33 @@ def setup_interface():
|
|
| 869 |
color: black !important;
|
| 870 |
}
|
| 871 |
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
|
| 876 |
-
|
| 877 |
-
|
| 878 |
-
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
padding: 0 !important;
|
| 882 |
-
margin-left: -15px !important;
|
| 883 |
-
margin-top: 8px !important;
|
| 884 |
-
}
|
| 885 |
-
|
| 886 |
-
/* Hide virtually everything in the file upload except the emoji */
|
| 887 |
-
.paperclip-button .wrap {
|
| 888 |
-
border: none !important;
|
| 889 |
-
background: none !important;
|
| 890 |
-
padding: 0 !important;
|
| 891 |
-
margin: 0 !important;
|
| 892 |
-
height: 30px !important;
|
| 893 |
-
min-height: 0 !important;
|
| 894 |
-
}
|
| 895 |
-
|
| 896 |
-
.paperclip-button .file-preview {
|
| 897 |
-
display: none !important;
|
| 898 |
}
|
| 899 |
|
| 900 |
-
|
| 901 |
-
|
|
|
|
|
|
|
| 902 |
}
|
| 903 |
|
| 904 |
-
|
| 905 |
-
|
| 906 |
-
border: none !important;
|
| 907 |
-
padding: 0 !important;
|
| 908 |
-
margin: 0 !important;
|
| 909 |
-
width: 25px !important;
|
| 910 |
-
height: 25px !important;
|
| 911 |
-
opacity: 0.6 !important;
|
| 912 |
}
|
| 913 |
|
| 914 |
-
|
| 915 |
-
|
| 916 |
-
|
| 917 |
-
|
| 918 |
-
|
| 919 |
-
|
| 920 |
-
content: "π" !important;
|
| 921 |
-
font-size: 18px !important;
|
| 922 |
-
position: absolute !important;
|
| 923 |
-
left: 3px !important;
|
| 924 |
-
top: 2px !important;
|
| 925 |
-
}
|
| 926 |
-
|
| 927 |
-
.paperclip-button .upload-button .icon {
|
| 928 |
-
display: none !important;
|
| 929 |
-
}
|
| 930 |
-
|
| 931 |
-
.paperclip-button .upload-button .text-button {
|
| 932 |
-
display: none !important;
|
| 933 |
}
|
| 934 |
|
| 935 |
/* Description text styling */
|
|
@@ -940,6 +909,23 @@ def setup_interface():
|
|
| 940 |
margin-bottom: 5px !important;
|
| 941 |
}
|
| 942 |
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 943 |
""")
|
| 944 |
|
| 945 |
return demo
|
|
|
|
| 802 |
gr.Markdown("Quick mode for faster analysis. Detailed mode for sentence-level analysis.",
|
| 803 |
elem_classes=["description-text"])
|
| 804 |
|
| 805 |
+
# Container for radio buttons
|
| 806 |
+
with gr.Row(elem_id="radio-container"):
|
| 807 |
+
mode_selection = gr.Radio(
|
| 808 |
+
choices=["quick", "detailed"],
|
| 809 |
+
value="quick",
|
| 810 |
+
label=""
|
| 811 |
+
)
|
| 812 |
+
|
| 813 |
+
# Add paperclip as an HTML element next to the radio buttons
|
| 814 |
+
gr.HTML("""
|
| 815 |
+
<div id="paperclip-container">
|
| 816 |
+
<label for="hidden-file-input" id="paperclip-label">π</label>
|
| 817 |
+
</div>
|
| 818 |
+
""", elem_id="paperclip-html")
|
| 819 |
+
|
| 820 |
+
# Hidden file upload
|
| 821 |
+
file_upload = gr.File(
|
| 822 |
+
file_types=["image", "pdf", "doc", "docx"],
|
| 823 |
+
type="binary",
|
| 824 |
+
visible=False,
|
| 825 |
+
elem_id="hidden-file-upload"
|
| 826 |
+
)
|
| 827 |
|
| 828 |
# Action buttons row
|
| 829 |
+
with gr.Row():
|
| 830 |
clear_btn = gr.Button("Clear", elem_id="clear-btn")
|
| 831 |
analyze_btn = gr.Button("Analyze Text", elem_id="analyze-btn")
|
| 832 |
|
|
|
|
| 855 |
outputs=[output_html, output_sentences, output_result]
|
| 856 |
)
|
| 857 |
|
| 858 |
+
# Extensive custom CSS and JavaScript to make everything work properly
|
| 859 |
gr.HTML("""
|
| 860 |
<style>
|
| 861 |
/* Button styling */
|
|
|
|
| 872 |
color: black !important;
|
| 873 |
}
|
| 874 |
|
| 875 |
+
/* Paperclip styling */
|
| 876 |
+
#paperclip-container {
|
| 877 |
+
display: inline-block;
|
| 878 |
+
position: relative;
|
| 879 |
+
top: -52px;
|
| 880 |
+
left: 170px;
|
| 881 |
+
width: 20px;
|
| 882 |
+
height: 20px;
|
| 883 |
+
z-index: 100;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 884 |
}
|
| 885 |
|
| 886 |
+
#paperclip-label {
|
| 887 |
+
font-size: 18px;
|
| 888 |
+
opacity: 0.6;
|
| 889 |
+
cursor: pointer;
|
| 890 |
}
|
| 891 |
|
| 892 |
+
#paperclip-label:hover {
|
| 893 |
+
opacity: 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 894 |
}
|
| 895 |
|
| 896 |
+
/* Hide the paperclip-html container (but not its contents) */
|
| 897 |
+
#paperclip-html {
|
| 898 |
+
height: 0;
|
| 899 |
+
overflow: visible;
|
| 900 |
+
margin: 0;
|
| 901 |
+
padding: 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 902 |
}
|
| 903 |
|
| 904 |
/* Description text styling */
|
|
|
|
| 909 |
margin-bottom: 5px !important;
|
| 910 |
}
|
| 911 |
</style>
|
| 912 |
+
|
| 913 |
+
<script>
|
| 914 |
+
// Connect paperclip button to the hidden file input
|
| 915 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 916 |
+
setTimeout(function() {
|
| 917 |
+
const paperclipLabel = document.getElementById('paperclip-label');
|
| 918 |
+
const hiddenFileInput = document.querySelector('#hidden-file-upload input[type="file"]');
|
| 919 |
+
|
| 920 |
+
if (paperclipLabel && hiddenFileInput) {
|
| 921 |
+
paperclipLabel.addEventListener('click', function(e) {
|
| 922 |
+
e.preventDefault();
|
| 923 |
+
hiddenFileInput.click();
|
| 924 |
+
});
|
| 925 |
+
}
|
| 926 |
+
}, 1000); // Wait for Gradio to fully render
|
| 927 |
+
});
|
| 928 |
+
</script>
|
| 929 |
""")
|
| 930 |
|
| 931 |
return demo
|