Update app.py
Browse files
app.py
CHANGED
|
@@ -814,7 +814,7 @@ def analyze_text(text: str, mode: str, classifier: TextClassifier) -> tuple:
|
|
| 814 |
# Modified Gradio interface setup function to include file upload
|
| 815 |
def setup_gradio_interface(classifier):
|
| 816 |
"""
|
| 817 |
-
Set up Gradio interface with
|
| 818 |
|
| 819 |
Args:
|
| 820 |
classifier: The TextClassifier instance
|
|
@@ -833,7 +833,6 @@ def setup_gradio_interface(classifier):
|
|
| 833 |
return analyze_text_wrapper("", mode) # Return empty analysis
|
| 834 |
return handle_file_upload_and_analyze(file_obj, mode, classifier)
|
| 835 |
|
| 836 |
-
# Create layout with side-by-side content
|
| 837 |
with gr.Blocks(title="AI Text Detector") as demo:
|
| 838 |
gr.Markdown("# AI Text Detector")
|
| 839 |
|
|
@@ -847,61 +846,81 @@ def setup_gradio_interface(classifier):
|
|
| 847 |
)
|
| 848 |
|
| 849 |
with gr.Row():
|
| 850 |
-
# Analysis mode
|
| 851 |
-
|
| 852 |
-
|
| 853 |
-
|
| 854 |
-
|
| 855 |
-
|
| 856 |
-
|
|
|
|
|
|
|
| 857 |
|
| 858 |
-
#
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
|
|
|
|
| 865 |
|
| 866 |
-
#
|
| 867 |
analyze_button = gr.Button("Analyze Text")
|
| 868 |
|
| 869 |
-
# Right column - Results
|
| 870 |
with gr.Column():
|
| 871 |
output_html = gr.HTML(label="Highlighted Analysis")
|
| 872 |
output_sentences = gr.Textbox(label="Sentence-by-Sentence Analysis", lines=10)
|
| 873 |
output_result = gr.Textbox(label="Overall Result", lines=4)
|
| 874 |
|
| 875 |
-
# Connect
|
| 876 |
analyze_button.click(
|
| 877 |
analyze_text_wrapper,
|
| 878 |
inputs=[text_input, mode_selection],
|
| 879 |
outputs=[output_html, output_sentences, output_result]
|
| 880 |
)
|
| 881 |
|
| 882 |
-
# Connect file upload
|
| 883 |
file_upload.change(
|
| 884 |
handle_file_upload_wrapper,
|
| 885 |
inputs=[file_upload, mode_selection],
|
| 886 |
outputs=[output_html, output_sentences, output_result]
|
| 887 |
)
|
| 888 |
|
| 889 |
-
# Add CSS
|
| 890 |
gr.HTML("""
|
| 891 |
<style>
|
| 892 |
-
|
| 893 |
-
|
| 894 |
-
|
| 895 |
}
|
| 896 |
-
|
| 897 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 898 |
}
|
| 899 |
-
</style>
|
| 900 |
-
""")
|
| 901 |
|
| 902 |
-
|
| 903 |
-
|
| 904 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 905 |
""")
|
| 906 |
|
| 907 |
return demo
|
|
|
|
| 814 |
# Modified Gradio interface setup function to include file upload
|
| 815 |
def setup_gradio_interface(classifier):
|
| 816 |
"""
|
| 817 |
+
Set up Gradio interface with a more aligned and compact file upload
|
| 818 |
|
| 819 |
Args:
|
| 820 |
classifier: The TextClassifier instance
|
|
|
|
| 833 |
return analyze_text_wrapper("", mode) # Return empty analysis
|
| 834 |
return handle_file_upload_and_analyze(file_obj, mode, classifier)
|
| 835 |
|
|
|
|
| 836 |
with gr.Blocks(title="AI Text Detector") as demo:
|
| 837 |
gr.Markdown("# AI Text Detector")
|
| 838 |
|
|
|
|
| 846 |
)
|
| 847 |
|
| 848 |
with gr.Row():
|
| 849 |
+
# Left side: Analysis mode radio buttons
|
| 850 |
+
with gr.Column(scale=4):
|
| 851 |
+
gr.Markdown("Analysis Mode")
|
| 852 |
+
gr.Markdown("Quick mode for faster analysis. Detailed mode for sentence-level analysis.", elem_classes=["description-text"])
|
| 853 |
+
mode_selection = gr.Radio(
|
| 854 |
+
choices=["quick", "detailed"],
|
| 855 |
+
value="quick",
|
| 856 |
+
label=""
|
| 857 |
+
)
|
| 858 |
|
| 859 |
+
# Right side: File upload (compact and aligned)
|
| 860 |
+
with gr.Column(scale=1, elem_classes=["file-upload-container"]):
|
| 861 |
+
file_upload = gr.File(
|
| 862 |
+
label="File",
|
| 863 |
+
file_types=["image", "pdf", "doc", "docx"],
|
| 864 |
+
type="binary",
|
| 865 |
+
elem_classes=["compact-file-upload"]
|
| 866 |
+
)
|
| 867 |
|
| 868 |
+
# Analyze button
|
| 869 |
analyze_button = gr.Button("Analyze Text")
|
| 870 |
|
| 871 |
+
# Right column - Results
|
| 872 |
with gr.Column():
|
| 873 |
output_html = gr.HTML(label="Highlighted Analysis")
|
| 874 |
output_sentences = gr.Textbox(label="Sentence-by-Sentence Analysis", lines=10)
|
| 875 |
output_result = gr.Textbox(label="Overall Result", lines=4)
|
| 876 |
|
| 877 |
+
# Connect buttons to functions
|
| 878 |
analyze_button.click(
|
| 879 |
analyze_text_wrapper,
|
| 880 |
inputs=[text_input, mode_selection],
|
| 881 |
outputs=[output_html, output_sentences, output_result]
|
| 882 |
)
|
| 883 |
|
| 884 |
+
# Connect file upload to automatically process when changed
|
| 885 |
file_upload.change(
|
| 886 |
handle_file_upload_wrapper,
|
| 887 |
inputs=[file_upload, mode_selection],
|
| 888 |
outputs=[output_html, output_sentences, output_result]
|
| 889 |
)
|
| 890 |
|
| 891 |
+
# Add custom CSS for alignment and styling
|
| 892 |
gr.HTML("""
|
| 893 |
<style>
|
| 894 |
+
/* Make file upload more compact */
|
| 895 |
+
.compact-file-upload {
|
| 896 |
+
max-width: 100%;
|
| 897 |
}
|
| 898 |
+
|
| 899 |
+
.compact-file-upload > .wrap {
|
| 900 |
+
margin: 0;
|
| 901 |
+
padding: 0;
|
| 902 |
+
}
|
| 903 |
+
|
| 904 |
+
.compact-file-upload .file-preview {
|
| 905 |
+
min-height: 0;
|
| 906 |
}
|
|
|
|
|
|
|
| 907 |
|
| 908 |
+
/* Align file upload with radio buttons */
|
| 909 |
+
.file-upload-container {
|
| 910 |
+
display: flex;
|
| 911 |
+
align-items: flex-end;
|
| 912 |
+
justify-content: center;
|
| 913 |
+
padding-bottom: 10px;
|
| 914 |
+
}
|
| 915 |
+
|
| 916 |
+
/* Make description text smaller */
|
| 917 |
+
.description-text {
|
| 918 |
+
font-size: 0.85em;
|
| 919 |
+
color: #666;
|
| 920 |
+
margin-top: -5px;
|
| 921 |
+
margin-bottom: 5px;
|
| 922 |
+
}
|
| 923 |
+
</style>
|
| 924 |
""")
|
| 925 |
|
| 926 |
return demo
|