Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer
|
| 3 |
import torch
|
| 4 |
import io
|
|
@@ -8,6 +9,85 @@ from pdfminer.layout import LAParams
|
|
| 8 |
from pdfminer.pdfpage import PDFPage
|
| 9 |
from docx import Document
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# Functions for file processing
|
| 12 |
def extract_text_from_pdf(pdf_file):
|
| 13 |
resource_manager = PDFResourceManager()
|
|
@@ -103,48 +183,18 @@ def plagiarism_check(text_chunks, tokenizer, model):
|
|
| 103 |
|
| 104 |
# Streamlit app with styling and multiple file uploads
|
| 105 |
def main():
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
# Set page configuration and background color
|
| 107 |
st.set_page_config(page_title="AI & Plagiarism Detection", page_icon="🔍")
|
| 108 |
-
|
| 109 |
-
# Custom CSS for styling the app's appearance
|
| 110 |
-
st.markdown(
|
| 111 |
-
"""
|
| 112 |
-
<style>
|
| 113 |
-
body {
|
| 114 |
-
background-color: black;
|
| 115 |
-
color: white;
|
| 116 |
-
font-family: 'Helvetica Neue', sans-serif;
|
| 117 |
-
}
|
| 118 |
-
.title {
|
| 119 |
-
color: white;
|
| 120 |
-
font-size: 24px;
|
| 121 |
-
font-weight: bold;
|
| 122 |
-
text-align: center;
|
| 123 |
-
}
|
| 124 |
-
.red-wine {
|
| 125 |
-
background-color: #8B0000; /* Red wine color */
|
| 126 |
-
padding: 10px;
|
| 127 |
-
border-radius: 5px;
|
| 128 |
-
margin-bottom: 20px;
|
| 129 |
-
}
|
| 130 |
-
.output-box {
|
| 131 |
-
background-color: #8B0000; /* Red wine color */
|
| 132 |
-
padding: 10px;
|
| 133 |
-
border-radius: 5px;
|
| 134 |
-
margin-top: 20px;
|
| 135 |
-
}
|
| 136 |
-
.stSlider > div > div {
|
| 137 |
-
color: white !important; /* Slider text color */
|
| 138 |
-
}
|
| 139 |
-
</style>
|
| 140 |
-
""",
|
| 141 |
-
unsafe_allow_html=True,
|
| 142 |
-
)
|
| 143 |
|
| 144 |
# Title with slider effect
|
| 145 |
-
slider_value = st.slider("AI Plagiarism Detection", min_value=0, max_value=100, value=50)
|
| 146 |
|
| 147 |
-
|
|
|
|
| 148 |
|
| 149 |
# Load models
|
| 150 |
ai_detection_model = load_ai_detection_model()
|
|
@@ -187,20 +237,21 @@ def main():
|
|
| 187 |
else:
|
| 188 |
ai_percentage_avg = None
|
| 189 |
human_percentage = None
|
| 190 |
-
|
| 191 |
-
# Plagiarism Check
|
| 192 |
-
if tokenizer and plagiarism_model:
|
| 193 |
-
plagiarism_percentage = plagiarism_check(text_chunks, tokenizer, plagiarism_model)
|
| 194 |
-
else:
|
| 195 |
-
plagiarism_percentage = None
|
| 196 |
|
| 197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
st.markdown(f"<div class='output-box'><h3>{uploaded_file.name}</h3></div>", unsafe_allow_html=True)
|
| 199 |
|
| 200 |
col1, col2 = st.columns(2)
|
| 201 |
|
| 202 |
with col1:
|
| 203 |
-
st.markdown("<div class='
|
| 204 |
if ai_percentage_avg is not None:
|
| 205 |
st.metric(label="AI Content", value=f"{ai_percentage_avg:.2f}%", delta="AI Generated")
|
| 206 |
st.metric(label="Human Written", value=f"{human_percentage:.2f}%", delta="Humanized Text")
|
|
@@ -208,7 +259,7 @@ def main():
|
|
| 208 |
st.write("AI Detection not available")
|
| 209 |
|
| 210 |
with col2:
|
| 211 |
-
st.markdown("<div class='
|
| 212 |
if plagiarism_percentage is not None:
|
| 213 |
st.metric(label="Plagiarism", value=f"{plagiarism_percentage:.2f}%", delta="Plagiarized" if plagiarism_percentage > 0 else "Original")
|
| 214 |
else:
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import random
|
| 3 |
from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer
|
| 4 |
import torch
|
| 5 |
import io
|
|
|
|
| 9 |
from pdfminer.pdfpage import PDFPage
|
| 10 |
from docx import Document
|
| 11 |
|
| 12 |
+
# --- Color Themes ---
|
| 13 |
+
THEMES = {
|
| 14 |
+
"midnight": {
|
| 15 |
+
"primaryColor": "#262730",
|
| 16 |
+
"backgroundColor": "#0E0F19",
|
| 17 |
+
"secondaryBackgroundColor": "#262730",
|
| 18 |
+
"textColor": "#FAFAFA",
|
| 19 |
+
"font": "sans-serif",
|
| 20 |
+
"welcomeTextColor": "#808080",
|
| 21 |
+
"tileColor": "#404040",
|
| 22 |
+
},
|
| 23 |
+
"forest": {
|
| 24 |
+
"primaryColor": "#38761d",
|
| 25 |
+
"backgroundColor": "#228B22",
|
| 26 |
+
"secondaryBackgroundColor": "#568259",
|
| 27 |
+
"textColor": "#E0FFFF",
|
| 28 |
+
"font": "sans-serif",
|
| 29 |
+
"welcomeTextColor": "#E0FFFF",
|
| 30 |
+
"tileColor": "#3D59AB",
|
| 31 |
+
},
|
| 32 |
+
"beach": {
|
| 33 |
+
"primaryColor": "#F4D03F",
|
| 34 |
+
"backgroundColor": "#A1D1E8",
|
| 35 |
+
"secondaryBackgroundColor": "#F7CAC9",
|
| 36 |
+
"textColor": "#6A5149",
|
| 37 |
+
"font": "sans-serif",
|
| 38 |
+
"welcomeTextColor": "#795548",
|
| 39 |
+
"tileColor": "#C3B091",
|
| 40 |
+
},
|
| 41 |
+
"sunset": {
|
| 42 |
+
"primaryColor": "#FFB347",
|
| 43 |
+
"backgroundColor": "#E07A5F",
|
| 44 |
+
"secondaryBackgroundColor": "#81B29A",
|
| 45 |
+
"textColor": "#F4F1DE",
|
| 46 |
+
"font": "sans-serif",
|
| 47 |
+
"welcomeTextColor": "#F2CC8F",
|
| 48 |
+
"tileColor": "#3D405B",
|
| 49 |
+
},
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
# --- Function to Apply Theme ---
|
| 53 |
+
def apply_theme(theme):
|
| 54 |
+
st.markdown(f"""
|
| 55 |
+
<style>
|
| 56 |
+
body {{
|
| 57 |
+
color: {theme["textColor"]};
|
| 58 |
+
background-color: {theme["backgroundColor"]};
|
| 59 |
+
font-family: {theme["font"]};
|
| 60 |
+
}}
|
| 61 |
+
.welcome-text {{
|
| 62 |
+
color: {theme["welcomeTextColor"]};
|
| 63 |
+
font-size: 36px;
|
| 64 |
+
font-weight: bold;
|
| 65 |
+
text-align: center;
|
| 66 |
+
margin-bottom: 20px;
|
| 67 |
+
}}
|
| 68 |
+
.stSlider > div > div {{
|
| 69 |
+
color: {theme["textColor"]} !important;
|
| 70 |
+
}}
|
| 71 |
+
.stMetricLabel {{
|
| 72 |
+
color: {theme["textColor"]} !important;
|
| 73 |
+
}}
|
| 74 |
+
.stMetricValue {{
|
| 75 |
+
color: {theme["textColor"]} !important;
|
| 76 |
+
}}
|
| 77 |
+
.output-box {{
|
| 78 |
+
background-color: {theme["tileColor"]};
|
| 79 |
+
color: {theme["textColor"]};
|
| 80 |
+
padding: 10px;
|
| 81 |
+
border-radius: 5px;
|
| 82 |
+
margin-top: 20px;
|
| 83 |
+
}}
|
| 84 |
+
.stFileUploader > div > div:nth-child(1) > div > button {{
|
| 85 |
+
background-color: {theme["primaryColor"]};
|
| 86 |
+
color: {theme["textColor"]};
|
| 87 |
+
}}
|
| 88 |
+
</style>
|
| 89 |
+
""", unsafe_allow_html=True)
|
| 90 |
+
|
| 91 |
# Functions for file processing
|
| 92 |
def extract_text_from_pdf(pdf_file):
|
| 93 |
resource_manager = PDFResourceManager()
|
|
|
|
| 183 |
|
| 184 |
# Streamlit app with styling and multiple file uploads
|
| 185 |
def main():
|
| 186 |
+
# --- Random Theme Selection ---
|
| 187 |
+
selected_theme = random.choice(list(THEMES.values()))
|
| 188 |
+
apply_theme(selected_theme)
|
| 189 |
+
|
| 190 |
# Set page configuration and background color
|
| 191 |
st.set_page_config(page_title="AI & Plagiarism Detection", page_icon="🔍")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
# Title with slider effect
|
| 194 |
+
slider_value = st.slider("AI Plagiarism Detection Tool", min_value=0, max_value=100, value=50)
|
| 195 |
|
| 196 |
+
# Welcome style text
|
| 197 |
+
st.markdown("<h1 class='welcome-text'>Welcome to AI & Plagiarism Detection</h1>", unsafe_allow_html=True)
|
| 198 |
|
| 199 |
# Load models
|
| 200 |
ai_detection_model = load_ai_detection_model()
|
|
|
|
| 237 |
else:
|
| 238 |
ai_percentage_avg = None
|
| 239 |
human_percentage = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
|
| 241 |
+
# Plagiarism Check
|
| 242 |
+
if tokenizer and plagiarism_model:
|
| 243 |
+
plagiarism_percentage = plagiarism_check(text_chunks, tokenizer, model)
|
| 244 |
+
else:
|
| 245 |
+
plagiarism_percentage = None
|
| 246 |
+
|
| 247 |
+
# --- Tiled Output ---
|
| 248 |
+
with st.container():
|
| 249 |
st.markdown(f"<div class='output-box'><h3>{uploaded_file.name}</h3></div>", unsafe_allow_html=True)
|
| 250 |
|
| 251 |
col1, col2 = st.columns(2)
|
| 252 |
|
| 253 |
with col1:
|
| 254 |
+
st.markdown("<div class='output-box'><h4>AI Detection:</h4></div>", unsafe_allow_html=True)
|
| 255 |
if ai_percentage_avg is not None:
|
| 256 |
st.metric(label="AI Content", value=f"{ai_percentage_avg:.2f}%", delta="AI Generated")
|
| 257 |
st.metric(label="Human Written", value=f"{human_percentage:.2f}%", delta="Humanized Text")
|
|
|
|
| 259 |
st.write("AI Detection not available")
|
| 260 |
|
| 261 |
with col2:
|
| 262 |
+
st.markdown("<div class='output-box'><h4>Plagiarism Detection:</h4></div>", unsafe_allow_html=True)
|
| 263 |
if plagiarism_percentage is not None:
|
| 264 |
st.metric(label="Plagiarism", value=f"{plagiarism_percentage:.2f}%", delta="Plagiarized" if plagiarism_percentage > 0 else "Original")
|
| 265 |
else:
|