Update app.py
Browse files
app.py
CHANGED
@@ -783,12 +783,15 @@ def setup_interface():
|
|
783 |
return analyze_text_wrapper("", mode)
|
784 |
return handle_file_upload_and_analyze(file_obj, mode, classifier)
|
785 |
|
786 |
-
|
|
|
|
|
|
|
787 |
gr.Markdown("# AI Text Detector")
|
788 |
|
789 |
with gr.Row():
|
790 |
# Left column - Input
|
791 |
-
with gr.Column(
|
792 |
text_input = gr.Textbox(
|
793 |
lines=8,
|
794 |
placeholder="Enter text to analyze...",
|
@@ -799,116 +802,105 @@ def setup_interface():
|
|
799 |
gr.Markdown("Quick mode for faster analysis. Detailed mode for sentence-level analysis.",
|
800 |
elem_classes=["description-text"])
|
801 |
|
802 |
-
with
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
# Hidden file upload that will be repositioned with CSS
|
811 |
-
with gr.Column(scale=1, elem_id="file-upload-column"):
|
812 |
-
file_upload = gr.File(
|
813 |
-
file_types=["image", "pdf", "doc", "docx"],
|
814 |
-
type="binary",
|
815 |
-
label="",
|
816 |
-
elem_id="hidden-file-upload"
|
817 |
-
)
|
818 |
|
819 |
-
|
|
|
|
|
|
|
820 |
|
821 |
# Right column - Results
|
822 |
-
with gr.Column(
|
823 |
output_html = gr.HTML(label="Highlighted Analysis")
|
824 |
output_sentences = gr.Textbox(label="Sentence-by-Sentence Analysis", lines=10)
|
825 |
output_result = gr.Textbox(label="Overall Result", lines=4)
|
826 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
827 |
# Connect the components
|
828 |
-
|
829 |
analyze_text_wrapper,
|
830 |
inputs=[text_input, mode_selection],
|
831 |
outputs=[output_html, output_sentences, output_result]
|
832 |
)
|
833 |
|
|
|
|
|
|
|
|
|
|
|
|
|
834 |
file_upload.change(
|
835 |
handle_file_upload_wrapper,
|
836 |
inputs=[file_upload, mode_selection],
|
837 |
outputs=[output_html, output_sentences, output_result]
|
838 |
)
|
839 |
|
840 |
-
#
|
841 |
-
# and replace it with a small paperclip
|
842 |
gr.HTML("""
|
843 |
<style>
|
844 |
-
/*
|
845 |
#analyze-btn {
|
846 |
background-color: #FF8C00 !important;
|
847 |
border-color: #FF8C00 !important;
|
|
|
|
|
848 |
}
|
849 |
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
padding-left: 0 !important;
|
855 |
-
padding-right: 0 !important;
|
856 |
-
margin-top: 8px;
|
857 |
}
|
858 |
|
859 |
-
|
860 |
-
|
861 |
-
display: none !important;
|
862 |
}
|
863 |
|
864 |
-
|
|
|
865 |
position: relative;
|
866 |
-
width: 32px !important;
|
867 |
-
height: 32px !important;
|
868 |
-
padding: 0 !important;
|
869 |
-
margin: 0 !important;
|
870 |
}
|
871 |
|
872 |
-
/*
|
873 |
-
#
|
874 |
-
content: "📎";
|
875 |
position: absolute;
|
876 |
-
top:
|
877 |
-
left:
|
878 |
-
|
|
|
|
|
|
|
879 |
cursor: pointer;
|
880 |
-
|
881 |
opacity: 0.7;
|
882 |
}
|
883 |
|
884 |
-
#
|
885 |
opacity: 1;
|
886 |
}
|
887 |
|
888 |
-
/*
|
889 |
-
#hidden-file-upload .upload-button {
|
890 |
-
position: absolute !important;
|
891 |
-
width: 32px !important;
|
892 |
-
height: 32px !important;
|
893 |
-
opacity: 0 !important;
|
894 |
-
cursor: pointer !important;
|
895 |
-
z-index: 1000 !important;
|
896 |
-
margin: 0 !important;
|
897 |
-
padding: 0 !important;
|
898 |
-
}
|
899 |
-
|
900 |
-
/* Hide everything else in the file upload container */
|
901 |
-
#hidden-file-upload .hide,
|
902 |
-
#hidden-file-upload p,
|
903 |
-
#hidden-file-upload > .wrap > div:not(.upload-button),
|
904 |
-
#hidden-file-upload > label,
|
905 |
-
#hidden-file-upload > .wrap > p,
|
906 |
-
#hidden-file-upload .file-preview,
|
907 |
-
#hidden-file-upload .absolute {
|
908 |
-
display: none !important;
|
909 |
-
}
|
910 |
-
|
911 |
-
/* Make description text smaller */
|
912 |
.description-text {
|
913 |
font-size: 0.85em !important;
|
914 |
color: #666 !important;
|
@@ -916,6 +908,18 @@ def setup_interface():
|
|
916 |
margin-bottom: 5px !important;
|
917 |
}
|
918 |
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
919 |
""")
|
920 |
|
921 |
return demo
|
|
|
783 |
return analyze_text_wrapper("", mode)
|
784 |
return handle_file_upload_and_analyze(file_obj, mode, classifier)
|
785 |
|
786 |
+
def clear_inputs():
|
787 |
+
return "", None, None, None
|
788 |
+
|
789 |
+
with gr.Blocks(title="AI Text Detector") as demo:
|
790 |
gr.Markdown("# AI Text Detector")
|
791 |
|
792 |
with gr.Row():
|
793 |
# Left column - Input
|
794 |
+
with gr.Column():
|
795 |
text_input = gr.Textbox(
|
796 |
lines=8,
|
797 |
placeholder="Enter text to analyze...",
|
|
|
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 with embedded file upload
|
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 |
+
# Buttons row
|
814 |
+
with gr.Row(elem_id="button-row"):
|
815 |
+
clear_btn = gr.Button("Clear", elem_id="clear-btn")
|
816 |
+
analyze_btn = gr.Button("Analyze Text", elem_id="analyze-btn")
|
817 |
|
818 |
# Right column - Results
|
819 |
+
with gr.Column():
|
820 |
output_html = gr.HTML(label="Highlighted Analysis")
|
821 |
output_sentences = gr.Textbox(label="Sentence-by-Sentence Analysis", lines=10)
|
822 |
output_result = gr.Textbox(label="Overall Result", lines=4)
|
823 |
|
824 |
+
# Custom file upload area for paperclip
|
825 |
+
gr.HTML("""
|
826 |
+
<div id="paperclip-wrapper">
|
827 |
+
<label for="paperclip-input" id="paperclip-label">📎</label>
|
828 |
+
<input type="file" id="paperclip-input" style="display:none;">
|
829 |
+
</div>
|
830 |
+
""")
|
831 |
+
|
832 |
+
# Add hidden file upload that we'll control with custom JS
|
833 |
+
file_upload = gr.File(
|
834 |
+
file_types=["image", "pdf", "doc", "docx"],
|
835 |
+
type="binary",
|
836 |
+
visible=False,
|
837 |
+
elem_id="hidden-file-upload"
|
838 |
+
)
|
839 |
+
|
840 |
# Connect the components
|
841 |
+
analyze_btn.click(
|
842 |
analyze_text_wrapper,
|
843 |
inputs=[text_input, mode_selection],
|
844 |
outputs=[output_html, output_sentences, output_result]
|
845 |
)
|
846 |
|
847 |
+
clear_btn.click(
|
848 |
+
clear_inputs,
|
849 |
+
inputs=None,
|
850 |
+
outputs=[text_input, output_html, output_sentences, output_result]
|
851 |
+
)
|
852 |
+
|
853 |
file_upload.change(
|
854 |
handle_file_upload_wrapper,
|
855 |
inputs=[file_upload, mode_selection],
|
856 |
outputs=[output_html, output_sentences, output_result]
|
857 |
)
|
858 |
|
859 |
+
# Add custom CSS and JavaScript
|
|
|
860 |
gr.HTML("""
|
861 |
<style>
|
862 |
+
/* Button styling to match original */
|
863 |
#analyze-btn {
|
864 |
background-color: #FF8C00 !important;
|
865 |
border-color: #FF8C00 !important;
|
866 |
+
color: white !important;
|
867 |
+
font-weight: normal !important;
|
868 |
}
|
869 |
|
870 |
+
#clear-btn {
|
871 |
+
background-color: #E0E0E0 !important;
|
872 |
+
border-color: #E0E0E0 !important;
|
873 |
+
color: black !important;
|
|
|
|
|
|
|
874 |
}
|
875 |
|
876 |
+
#button-row {
|
877 |
+
gap: 10px !important;
|
|
|
878 |
}
|
879 |
|
880 |
+
/* Radio button container styling */
|
881 |
+
#radio-container {
|
882 |
position: relative;
|
|
|
|
|
|
|
|
|
883 |
}
|
884 |
|
885 |
+
/* Paperclip styling */
|
886 |
+
#paperclip-wrapper {
|
|
|
887 |
position: absolute;
|
888 |
+
top: 334px;
|
889 |
+
left: 160px;
|
890 |
+
z-index: 100;
|
891 |
+
}
|
892 |
+
|
893 |
+
#paperclip-label {
|
894 |
cursor: pointer;
|
895 |
+
font-size: 20px;
|
896 |
opacity: 0.7;
|
897 |
}
|
898 |
|
899 |
+
#paperclip-label:hover {
|
900 |
opacity: 1;
|
901 |
}
|
902 |
|
903 |
+
/* Description text styling */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
904 |
.description-text {
|
905 |
font-size: 0.85em !important;
|
906 |
color: #666 !important;
|
|
|
908 |
margin-bottom: 5px !important;
|
909 |
}
|
910 |
</style>
|
911 |
+
|
912 |
+
<script>
|
913 |
+
// Connect custom paperclip to the hidden file input
|
914 |
+
document.addEventListener('DOMContentLoaded', function() {
|
915 |
+
const paperclipLabel = document.getElementById('paperclip-label');
|
916 |
+
const hiddenFileInput = document.querySelector('#hidden-file-upload input[type="file"]');
|
917 |
+
|
918 |
+
paperclipLabel.addEventListener('click', function() {
|
919 |
+
hiddenFileInput.click();
|
920 |
+
});
|
921 |
+
});
|
922 |
+
</script>
|
923 |
""")
|
924 |
|
925 |
return demo
|