Alishbah commited on
Commit
170516a
Β·
verified Β·
1 Parent(s): 818a18d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +86 -34
app.py CHANGED
@@ -12,14 +12,44 @@ from docx import Document
12
  # --- Streamlit Page Configuration ---
13
  st.set_page_config(page_title="AI & Plagiarism Detection", page_icon="πŸ”")
14
 
15
- # --- ChatGPT Theme ---
16
- CHATGPT_THEME = {
17
- "backgroundColor": "#343541",
18
- "textColor": "#D1D5DB",
19
- "tileColor": "#444654",
20
- "inputAreaColor": "#40414F",
21
- "accentColor": "#10a37f",
22
- "font": "sans-serif",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  }
24
 
25
  # --- Function to Apply Theme ---
@@ -32,7 +62,7 @@ def apply_theme(theme):
32
  font-family: {theme["font"]};
33
  }}
34
  .welcome-text {{
35
- color: {theme["textColor"]};
36
  font-size: 36px;
37
  font-weight: bold;
38
  text-align: center;
@@ -46,12 +76,27 @@ def apply_theme(theme):
46
  margin-top: 20px;
47
  }}
48
  .stTextArea textarea {{
49
- background-color: {theme["inputAreaColor"]};
50
  color: {theme["textColor"]};
 
 
51
  }}
52
  .stFileUploader > div > div:nth-child(1) > div > button {{
53
- background-color: {theme["accentColor"]};
54
- color: {theme["backgroundColor"]};
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  }}
56
  </style>
57
  """, unsafe_allow_html=True)
@@ -145,15 +190,16 @@ def plagiarism_check(text_chunks, tokenizer, model):
145
 
146
  # --- Main Function ---
147
  def main():
148
- # --- Apply ChatGPT Theme ---
149
- apply_theme(CHATGPT_THEME)
 
 
150
 
151
  # --- Title and Welcome ---
152
- st.markdown("<h1 class='welcome-text'>AI & Plagiarism Detection</h1>", unsafe_allow_html=True)
153
 
154
- # --- Combined Input Area ---
155
- input_text = st.text_area("Enter text here or attach a document:", height=200)
156
-
157
  uploaded_files = st.file_uploader("Attach documents (PDF or DOCX)", type=["pdf", "docx"], accept_multiple_files=True)
158
 
159
  # --- Load models ---
@@ -165,24 +211,29 @@ def main():
165
 
166
  # --- Process Uploaded Files ---
167
  if uploaded_files:
168
- for uploaded_file in uploaded_files:
169
- file_size = len(uploaded_file.getvalue())
170
- if file_size > 1000000000:
171
- st.error(f"{uploaded_file.name}: File size exceeds the 1GB limit.")
172
- continue
173
-
174
- try:
175
- if uploaded_file.type == "application/pdf":
176
- raw_text += extract_text_from_pdf(uploaded_file) + "\n"
177
- elif uploaded_file.type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
178
- raw_text += extract_text_from_docx(uploaded_file) + "\n"
179
- else:
180
- st.error(f"{uploaded_file.name}: Unsupported file type")
181
  continue
182
 
183
- except Exception as e:
184
- st.error(f"Error processing {uploaded_file.name}: {e}")
185
- continue
 
 
 
 
 
 
 
 
 
 
 
 
 
186
 
187
  # --- Append Manual Text ---
188
  raw_text += input_text.strip()
@@ -239,4 +290,5 @@ def load_models():
239
 
240
  # --- Call Main ---
241
  if __name__ == "__main__":
 
242
  main()
 
12
  # --- Streamlit Page Configuration ---
13
  st.set_page_config(page_title="AI & Plagiarism Detection", page_icon="πŸ”")
14
 
15
+ # --- Color Themes ---
16
+ THEMES = {
17
+ "cyberpunk": {
18
+ "primaryColor": "#9C27B0",
19
+ "backgroundColor": "#1E1E1E",
20
+ "tileColor": "#303030",
21
+ "textColor": "#FFFFFF",
22
+ "accentColor": "#FF4081",
23
+ "font": "monospace",
24
+ "welcomeTextColor": "#FFD700"
25
+ },
26
+ "retro": {
27
+ "primaryColor": "#FF5733",
28
+ "backgroundColor": "#F0F0F0",
29
+ "tileColor": "#E0E0E0",
30
+ "textColor": "#333333",
31
+ "accentColor": "#64B5F6",
32
+ "font": "sans-serif",
33
+ "welcomeTextColor": "#4CAF50"
34
+ },
35
+ "darkmode": {
36
+ "primaryColor": "#2979FF",
37
+ "backgroundColor": "#212121",
38
+ "tileColor": "#424242",
39
+ "textColor": "#FFFFFF",
40
+ "accentColor": "#FFAB40",
41
+ "font": "sans-serif",
42
+ "welcomeTextColor": "#BBDEFB"
43
+ },
44
+ "bluelagoon": {
45
+ "primaryColor": "#03A9F4",
46
+ "backgroundColor": "#E1F5FE",
47
+ "tileColor": "#B3E5FC",
48
+ "textColor": "#333333",
49
+ "accentColor": "#FFCDD2",
50
+ "font": "sans-serif",
51
+ "welcomeTextColor": "#0277BD"
52
+ }
53
  }
54
 
55
  # --- Function to Apply Theme ---
 
62
  font-family: {theme["font"]};
63
  }}
64
  .welcome-text {{
65
+ color: {theme["welcomeTextColor"]};
66
  font-size: 36px;
67
  font-weight: bold;
68
  text-align: center;
 
76
  margin-top: 20px;
77
  }}
78
  .stTextArea textarea {{
79
+ background-color: {theme["backgroundColor"]};
80
  color: {theme["textColor"]};
81
+ border: 1px solid {theme["primaryColor"]};
82
+ border-radius: 5px;
83
  }}
84
  .stFileUploader > div > div:nth-child(1) > div > button {{
85
+ background-color: {theme["primaryColor"]};
86
+ color: {theme["textColor"]};
87
+ border-radius: 5px;
88
+ }}
89
+ .stMetricLabel {{
90
+ color: {theme["textColor"]} !important;
91
+ }}
92
+ .stMetricValue {{
93
+ color: {theme["textColor"]} !important;
94
+ }}
95
+ .streamlit-expanderHeader {{
96
+ color: {theme["textColor"]};
97
+ }}
98
+ .streamlit-expanderContent {{
99
+ color: {theme["textColor"]};
100
  }}
101
  </style>
102
  """, unsafe_allow_html=True)
 
190
 
191
  # --- Main Function ---
192
  def main():
193
+ # --- Theme Selection ---
194
+ theme_name = st.sidebar.selectbox("Select Theme", list(THEMES.keys()), index=0)
195
+ selected_theme = THEMES[theme_name]
196
+ apply_theme(selected_theme)
197
 
198
  # --- Title and Welcome ---
199
+ st.markdown(f"<h1 class='welcome-text'>AI & Plagiarism Detection</h1>", unsafe_allow_html=True)
200
 
201
+ # --- Input Area: Text Area and File Upload ---
202
+ input_text = st.text_area("Enter text or attach a document:", height=200)
 
203
  uploaded_files = st.file_uploader("Attach documents (PDF or DOCX)", type=["pdf", "docx"], accept_multiple_files=True)
204
 
205
  # --- Load models ---
 
211
 
212
  # --- Process Uploaded Files ---
213
  if uploaded_files:
214
+ with st.expander("Uploaded Files", expanded=False):
215
+ for uploaded_file in uploaded_files:
216
+ file_size = len(uploaded_file.getvalue())
217
+ if file_size > 1000000000:
218
+ st.error(f"{uploaded_file.name}: File size exceeds the 1GB limit.")
 
 
 
 
 
 
 
 
219
  continue
220
 
221
+ try:
222
+ if uploaded_file.type == "application/pdf":
223
+ extracted_text = extract_text_from_pdf(uploaded_file)
224
+ raw_text += extracted_text + "\n"
225
+ st.write(f"Extracted text from {uploaded_file.name}")
226
+ elif uploaded_file.type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
227
+ extracted_text = extract_text_from_docx(uploaded_file)
228
+ raw_text += extracted_text + "\n"
229
+ st.write(f"Extracted text from {uploaded_file.name}")
230
+ else:
231
+ st.error(f"{uploaded_file.name}: Unsupported file type")
232
+ continue
233
+
234
+ except Exception as e:
235
+ st.error(f"Error processing {uploaded_file.name}: {e}")
236
+ continue
237
 
238
  # --- Append Manual Text ---
239
  raw_text += input_text.strip()
 
290
 
291
  # --- Call Main ---
292
  if __name__ == "__main__":
293
+ ai_detection_model, tokenizer, plagiarism_model = load_models()
294
  main()