Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -772,6 +772,7 @@ def analyze_text(text: str, mode: str, classifier: TextClassifier) -> tuple:
|
|
| 772 |
classifier = TextClassifier()
|
| 773 |
|
| 774 |
# Create Gradio interface with a small file upload button next to the radio buttons
|
|
|
|
| 775 |
def setup_interface():
|
| 776 |
# Create analyzer functions that capture the classifier
|
| 777 |
def analyze_text_wrapper(text, mode):
|
|
@@ -782,44 +783,43 @@ def setup_interface():
|
|
| 782 |
return analyze_text_wrapper("", mode)
|
| 783 |
return handle_file_upload_and_analyze(file_obj, mode, classifier)
|
| 784 |
|
| 785 |
-
with gr.Blocks(title="AI Text Detector") as demo:
|
| 786 |
gr.Markdown("# AI Text Detector")
|
| 787 |
|
| 788 |
with gr.Row():
|
| 789 |
# Left column - Input
|
| 790 |
-
with gr.Column():
|
| 791 |
text_input = gr.Textbox(
|
| 792 |
lines=8,
|
| 793 |
placeholder="Enter text to analyze...",
|
| 794 |
label="Input Text"
|
| 795 |
)
|
| 796 |
|
| 797 |
-
|
| 798 |
-
|
| 799 |
-
|
| 800 |
-
|
| 801 |
-
|
| 802 |
-
|
| 803 |
-
with gr.Row():
|
| 804 |
mode_selection = gr.Radio(
|
| 805 |
choices=["quick", "detailed"],
|
| 806 |
value="quick",
|
| 807 |
-
label=""
|
| 808 |
-
elem_classes=["mode-radio"]
|
| 809 |
)
|
| 810 |
-
|
| 811 |
-
|
|
|
|
| 812 |
file_upload = gr.File(
|
| 813 |
file_types=["image", "pdf", "doc", "docx"],
|
| 814 |
type="binary",
|
| 815 |
label="",
|
| 816 |
-
elem_id="
|
| 817 |
)
|
| 818 |
|
| 819 |
-
analyze_button = gr.Button("Analyze Text")
|
| 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)
|
|
@@ -837,89 +837,88 @@ def setup_interface():
|
|
| 837 |
outputs=[output_html, output_sentences, output_result]
|
| 838 |
)
|
| 839 |
|
| 840 |
-
#
|
|
|
|
| 841 |
gr.HTML("""
|
| 842 |
<style>
|
| 843 |
-
/*
|
| 844 |
-
#
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
vertical-align: middle !important;
|
| 848 |
-
margin-left: 10px !important;
|
| 849 |
-
margin-top: 5px !important;
|
| 850 |
}
|
| 851 |
|
| 852 |
-
|
|
|
|
| 853 |
position: relative;
|
| 854 |
-
display: inline-block;
|
| 855 |
width: 32px !important;
|
| 856 |
-
|
| 857 |
-
|
|
|
|
| 858 |
}
|
| 859 |
|
| 860 |
-
/* Hide all
|
| 861 |
-
#
|
| 862 |
-
#tiny-file-upload .file-preview p,
|
| 863 |
-
#tiny-file-upload .hidden-upload,
|
| 864 |
-
#tiny-file-upload .upload-prompt,
|
| 865 |
-
#tiny-file-upload .remove-file,
|
| 866 |
-
#tiny-file-upload > label {
|
| 867 |
display: none !important;
|
| 868 |
}
|
| 869 |
|
| 870 |
-
|
| 871 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 872 |
content: "📎";
|
| 873 |
-
font-size: 20px;
|
| 874 |
position: absolute;
|
| 875 |
top: 2px;
|
| 876 |
-
left:
|
| 877 |
-
|
| 878 |
cursor: pointer;
|
| 879 |
-
z-index:
|
|
|
|
| 880 |
}
|
| 881 |
|
| 882 |
-
#
|
| 883 |
opacity: 1;
|
| 884 |
}
|
| 885 |
|
| 886 |
-
/*
|
| 887 |
-
#
|
| 888 |
-
position: absolute;
|
| 889 |
width: 32px !important;
|
| 890 |
height: 32px !important;
|
| 891 |
-
|
| 892 |
-
|
| 893 |
-
|
| 894 |
margin: 0 !important;
|
| 895 |
padding: 0 !important;
|
| 896 |
-
cursor: pointer !important;
|
| 897 |
-
z-index: 5 !important;
|
| 898 |
}
|
| 899 |
|
| 900 |
-
/*
|
| 901 |
-
|
| 902 |
-
|
| 903 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 904 |
}
|
| 905 |
|
| 906 |
/* Make description text smaller */
|
| 907 |
.description-text {
|
| 908 |
-
font-size: 0.85em;
|
| 909 |
-
color: #666;
|
| 910 |
-
margin-top: -
|
| 911 |
-
margin-bottom: 5px;
|
| 912 |
-
}
|
| 913 |
-
|
| 914 |
-
/* More compact layout */
|
| 915 |
-
#analysis-mode-label {
|
| 916 |
-
margin-bottom: 0 !important;
|
| 917 |
}
|
| 918 |
</style>
|
| 919 |
""")
|
| 920 |
|
| 921 |
return demo
|
| 922 |
-
|
| 923 |
# Setup the app with CORS middleware
|
| 924 |
def setup_app():
|
| 925 |
demo = setup_interface()
|
|
|
|
| 772 |
classifier = TextClassifier()
|
| 773 |
|
| 774 |
# Create Gradio interface with a small file upload button next to the radio buttons
|
| 775 |
+
# Modified approach - simplify by using custom HTML/CSS to achieve the exact layout
|
| 776 |
def setup_interface():
|
| 777 |
# Create analyzer functions that capture the classifier
|
| 778 |
def analyze_text_wrapper(text, mode):
|
|
|
|
| 783 |
return analyze_text_wrapper("", mode)
|
| 784 |
return handle_file_upload_and_analyze(file_obj, mode, classifier)
|
| 785 |
|
| 786 |
+
with gr.Blocks(title="AI Text Detector", css="#analyze-btn { background-color: #FF8C00 !important; }") as demo:
|
| 787 |
gr.Markdown("# AI Text Detector")
|
| 788 |
|
| 789 |
with gr.Row():
|
| 790 |
# Left column - Input
|
| 791 |
+
with gr.Column(scale=1):
|
| 792 |
text_input = gr.Textbox(
|
| 793 |
lines=8,
|
| 794 |
placeholder="Enter text to analyze...",
|
| 795 |
label="Input Text"
|
| 796 |
)
|
| 797 |
|
| 798 |
+
gr.Markdown("Analysis Mode")
|
| 799 |
+
gr.Markdown("Quick mode for faster analysis. Detailed mode for sentence-level analysis.",
|
| 800 |
+
elem_classes=["description-text"])
|
| 801 |
+
|
| 802 |
+
with gr.Row():
|
| 803 |
+
with gr.Column(scale=12):
|
|
|
|
| 804 |
mode_selection = gr.Radio(
|
| 805 |
choices=["quick", "detailed"],
|
| 806 |
value="quick",
|
| 807 |
+
label=""
|
|
|
|
| 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 |
+
analyze_button = gr.Button("Analyze Text", elem_id="analyze-btn")
|
| 820 |
|
| 821 |
# Right column - Results
|
| 822 |
+
with gr.Column(scale=1):
|
| 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)
|
|
|
|
| 837 |
outputs=[output_html, output_sentences, output_result]
|
| 838 |
)
|
| 839 |
|
| 840 |
+
# Applying extensive CSS to completely hide the file upload drop area
|
| 841 |
+
# and replace it with a small paperclip
|
| 842 |
gr.HTML("""
|
| 843 |
<style>
|
| 844 |
+
/* Make analyze button orange */
|
| 845 |
+
#analyze-btn {
|
| 846 |
+
background-color: #FF8C00 !important;
|
| 847 |
+
border-color: #FF8C00 !important;
|
|
|
|
|
|
|
|
|
|
| 848 |
}
|
| 849 |
|
| 850 |
+
/* File upload container styling */
|
| 851 |
+
#file-upload-column {
|
| 852 |
position: relative;
|
|
|
|
| 853 |
width: 32px !important;
|
| 854 |
+
padding-left: 0 !important;
|
| 855 |
+
padding-right: 0 !important;
|
| 856 |
+
margin-top: 8px;
|
| 857 |
}
|
| 858 |
|
| 859 |
+
/* Hide all default file upload elements */
|
| 860 |
+
#hidden-file-upload > * {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 861 |
display: none !important;
|
| 862 |
}
|
| 863 |
|
| 864 |
+
#hidden-file-upload {
|
| 865 |
+
position: relative;
|
| 866 |
+
width: 32px !important;
|
| 867 |
+
height: 32px !important;
|
| 868 |
+
padding: 0 !important;
|
| 869 |
+
margin: 0 !important;
|
| 870 |
+
}
|
| 871 |
+
|
| 872 |
+
/* Create our custom paperclip button */
|
| 873 |
+
#hidden-file-upload::before {
|
| 874 |
content: "📎";
|
|
|
|
| 875 |
position: absolute;
|
| 876 |
top: 2px;
|
| 877 |
+
left: 8px;
|
| 878 |
+
font-size: 20px;
|
| 879 |
cursor: pointer;
|
| 880 |
+
z-index: 999;
|
| 881 |
+
opacity: 0.7;
|
| 882 |
}
|
| 883 |
|
| 884 |
+
#hidden-file-upload::before:hover {
|
| 885 |
opacity: 1;
|
| 886 |
}
|
| 887 |
|
| 888 |
+
/* Make only the actual input button clickable but invisible */
|
| 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;
|
| 915 |
+
margin-top: -10px !important;
|
| 916 |
+
margin-bottom: 5px !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 917 |
}
|
| 918 |
</style>
|
| 919 |
""")
|
| 920 |
|
| 921 |
return demo
|
|
|
|
| 922 |
# Setup the app with CORS middleware
|
| 923 |
def setup_app():
|
| 924 |
demo = setup_interface()
|