mabuseif commited on
Commit
44c2693
·
verified ·
1 Parent(s): b2b9458

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -31
app.py CHANGED
@@ -196,21 +196,27 @@ with tabs[0]:
196
  st.markdown('<div class="tab-content">', unsafe_allow_html=True)
197
  st.header("Generate New Citation")
198
 
 
 
199
  col1, col2 = st.columns(2)
200
-
201
  with col1:
202
  username = st.text_input("Username", help="Your username for tracking purposes", placeholder="e.g., john_doe")
203
- task_name = st.text_input("Task Name", help="The name of the task or project", placeholder="e.g., Literature Review Assignment")
204
- author_name = st.text_input("Author Name", help="The author(s) of the source", placeholder="e.g., Smith or Smith et al.")
205
-
206
  with col2:
 
 
 
 
 
 
 
 
207
  publication_year = st.text_input("Publication Year", help="The year of publication", placeholder="e.g., 2023")
208
- source_url = st.text_input("Source URL", help="The full URL of the source", placeholder="https://example.com/article")
209
 
210
- cited_text = st.text_area("Quoted or Paraphrased Text",
211
- help="The exact text quoted or paraphrased from the source",
212
- placeholder="e.g., Thermal comfort thresholds are exceeded frequently in Australian schools",
213
- height=100)
 
214
 
215
  # Get current date and time in Melbourne timezone
216
  melbourne_tz = pytz.timezone(MELBOURNE_TIMEZONE)
@@ -220,16 +226,14 @@ with tabs[0]:
220
 
221
  st.markdown(f"""
222
  <div class="datetime-display">
223
- <strong>Current Date & Time (Melbourne, Australia):</strong><br>
224
- Date: {current_date}<br>
225
- Time: {current_time}
226
  </div>
227
  """, unsafe_allow_html=True)
228
 
229
  generate_button = st.button("Generate Citation", type="primary", use_container_width=True)
230
 
231
  if generate_button:
232
- if not all([username, task_name, author_name, publication_year, source_url, cited_text]):
233
  st.error("Please fill in all fields before generating a citation.")
234
  elif check_for_fragment(source_url):
235
  st.markdown("""
@@ -240,13 +244,13 @@ with tabs[0]:
240
  </div>
241
  """, unsafe_allow_html=True)
242
  else:
243
- scc_hash = generate_citation_hash(author_name, publication_year, source_url, cited_text, cited_text, username, task_name, current_date, current_time)
244
 
245
  st.markdown("## Generated Citations")
246
 
247
  # HTML Citation - Start of text
248
  st.markdown("### HTML Citation (Start of Text)")
249
- html_citation_start = f'"{cited_text}" ' + format_citation_html(source_url, cited_text, author_name, publication_year, scc_hash)
250
 
251
  st.markdown('<div class="citation-output">', unsafe_allow_html=True)
252
  st.code(html_citation_start, language='html')
@@ -255,7 +259,7 @@ with tabs[0]:
255
 
256
  # HTML Citation - End of text
257
  st.markdown("### HTML Citation (End of Text)")
258
- html_citation_end = format_citation_html(source_url, cited_text, author_name, publication_year, scc_hash) + f' "{cited_text}"'
259
 
260
  st.markdown('<div class="citation-output">', unsafe_allow_html=True)
261
  st.code(html_citation_end, language='html')
@@ -277,8 +281,8 @@ with tabs[0]:
277
  "author": author_name,
278
  "year": publication_year,
279
  "url": source_url,
280
- "fragment_text": cited_text,
281
- "cited_text": cited_text,
282
  "username": username,
283
  "task_name": task_name,
284
  "date": current_date,
@@ -329,34 +333,46 @@ with tabs[1]:
329
  if 'verified_hashes' not in st.session_state:
330
  st.session_state.verified_hashes = []
331
 
 
 
332
  col1, col2 = st.columns(2)
333
-
334
  with col1:
335
  verify_username = st.text_input("Username (for verification)", placeholder="e.g., john_doe")
 
336
  verify_task_name = st.text_input("Task Name (for verification)", placeholder="e.g., Literature Review Assignment")
337
- verify_author_name = st.text_input("Author Name (for verification)", placeholder="e.g., Smith or Smith et al.")
 
 
 
 
 
 
338
  verify_publication_year = st.text_input("Publication Year (for verification)", placeholder="e.g., 2023")
339
 
340
- with col2:
 
341
  verify_source_url = st.text_input("Source URL (for verification)", placeholder="https://example.com/article")
 
 
 
 
 
342
  verify_date = st.text_input("Date (YYYY-MM-DD) (for verification)", placeholder="e.g., 2025-01-08")
 
343
  verify_time = st.text_input("Time (HH:MM:SS) (for verification)", placeholder="e.g., 14:30:25")
344
- expected_hash = st.text_input("Expected Hash (from the citation)", placeholder="Enter the full hash from the citation")
345
 
346
- verify_cited_text = st.text_area("Quoted or Paraphrased Text (for verification)",
347
- placeholder="e.g., Thermal comfort thresholds are exceeded frequently in Australian schools",
348
- height=100)
349
 
350
  verify_button = st.button("Verify Hash", type="primary", use_container_width=True)
351
 
352
  if verify_button:
353
  if not all([verify_username, verify_task_name, verify_author_name, verify_publication_year,
354
- verify_source_url, verify_cited_text, verify_date, verify_time, expected_hash]):
355
  st.error("Please fill in all fields before verifying the hash.")
356
  else:
357
  recomputed_hash = generate_citation_hash(
358
  verify_author_name, verify_publication_year, verify_source_url,
359
- verify_cited_text, verify_cited_text, verify_username, verify_task_name,
360
  verify_date, verify_time
361
  )
362
 
@@ -371,8 +387,8 @@ with tabs[1]:
371
  "Author": verify_author_name,
372
  "Year": verify_publication_year,
373
  "URL": verify_source_url,
374
- "Fragment text": verify_cited_text,
375
- "Cited text": verify_cited_text,
376
  "Username": verify_username,
377
  "Task name": verify_task_name,
378
  "Date": verify_date,
@@ -392,8 +408,8 @@ with tabs[1]:
392
  "Author": verify_author_name,
393
  "Year": verify_publication_year,
394
  "URL": verify_source_url,
395
- "Fragment text": verify_cited_text,
396
- "Cited text": verify_cited_text,
397
  "Username": verify_username,
398
  "Task name": verify_task_name,
399
  "Date": verify_date,
 
196
  st.markdown('<div class="tab-content">', unsafe_allow_html=True)
197
  st.header("Generate New Citation")
198
 
199
+ # User Information Section
200
+ st.subheader("User Information")
201
  col1, col2 = st.columns(2)
 
202
  with col1:
203
  username = st.text_input("Username", help="Your username for tracking purposes", placeholder="e.g., john_doe")
 
 
 
204
  with col2:
205
+ task_name = st.text_input("Task Name", help="The name of the task or project", placeholder="e.g., Literature Review Assignment")
206
+
207
+ # Citation Info Section
208
+ st.subheader("Citation Info")
209
+ col3, col4 = st.columns(2)
210
+ with col3:
211
+ author_name = st.text_input("Author(s) Name", help="The author(s) of the source", placeholder="e.g., Smith or Smith et al.")
212
+ with col4:
213
  publication_year = st.text_input("Publication Year", help="The year of publication", placeholder="e.g., 2023")
 
214
 
215
+ col5, col6 = st.columns(2)
216
+ with col5:
217
+ source_url = st.text_input("Source URL", help="The full URL of the source", placeholder="https://example.com/article")
218
+ with col6:
219
+ annotated_text = st.text_input("Annotated Text", help="The text quoted or paraphrased from the source", placeholder="e.g., Thermal comfort thresholds...")
220
 
221
  # Get current date and time in Melbourne timezone
222
  melbourne_tz = pytz.timezone(MELBOURNE_TIMEZONE)
 
226
 
227
  st.markdown(f"""
228
  <div class="datetime-display">
229
+ {current_date} {current_time}
 
 
230
  </div>
231
  """, unsafe_allow_html=True)
232
 
233
  generate_button = st.button("Generate Citation", type="primary", use_container_width=True)
234
 
235
  if generate_button:
236
+ if not all([username, task_name, author_name, publication_year, source_url, annotated_text]):
237
  st.error("Please fill in all fields before generating a citation.")
238
  elif check_for_fragment(source_url):
239
  st.markdown("""
 
244
  </div>
245
  """, unsafe_allow_html=True)
246
  else:
247
+ scc_hash = generate_citation_hash(author_name, publication_year, source_url, annotated_text, annotated_text, username, task_name, current_date, current_time)
248
 
249
  st.markdown("## Generated Citations")
250
 
251
  # HTML Citation - Start of text
252
  st.markdown("### HTML Citation (Start of Text)")
253
+ html_citation_start = f'"{annotated_text}" ' + format_citation_html(source_url, annotated_text, author_name, publication_year, scc_hash)
254
 
255
  st.markdown('<div class="citation-output">', unsafe_allow_html=True)
256
  st.code(html_citation_start, language='html')
 
259
 
260
  # HTML Citation - End of text
261
  st.markdown("### HTML Citation (End of Text)")
262
+ html_citation_end = format_citation_html(source_url, annotated_text, author_name, publication_year, scc_hash) + f' "{annotated_text}"'
263
 
264
  st.markdown('<div class="citation-output">', unsafe_allow_html=True)
265
  st.code(html_citation_end, language='html')
 
281
  "author": author_name,
282
  "year": publication_year,
283
  "url": source_url,
284
+ "fragment_text": annotated_text,
285
+ "cited_text": annotated_text,
286
  "username": username,
287
  "task_name": task_name,
288
  "date": current_date,
 
333
  if 'verified_hashes' not in st.session_state:
334
  st.session_state.verified_hashes = []
335
 
336
+ # User Information Section
337
+ st.subheader("User Information")
338
  col1, col2 = st.columns(2)
 
339
  with col1:
340
  verify_username = st.text_input("Username (for verification)", placeholder="e.g., john_doe")
341
+ with col2:
342
  verify_task_name = st.text_input("Task Name (for verification)", placeholder="e.g., Literature Review Assignment")
343
+
344
+ # Citation Info Section
345
+ st.subheader("Citation Info")
346
+ col3, col4 = st.columns(2)
347
+ with col3:
348
+ verify_author_name = st.text_input("Author(s) Name (for verification)", placeholder="e.g., Smith or Smith et al.")
349
+ with col4:
350
  verify_publication_year = st.text_input("Publication Year (for verification)", placeholder="e.g., 2023")
351
 
352
+ col5, col6 = st.columns(2)
353
+ with col5:
354
  verify_source_url = st.text_input("Source URL (for verification)", placeholder="https://example.com/article")
355
+ with col6:
356
+ verify_annotated_text = st.text_input("Annotated Text (for verification)", placeholder="e.g., Thermal comfort thresholds...")
357
+
358
+ col7, col8 = st.columns(2)
359
+ with col7:
360
  verify_date = st.text_input("Date (YYYY-MM-DD) (for verification)", placeholder="e.g., 2025-01-08")
361
+ with col8:
362
  verify_time = st.text_input("Time (HH:MM:SS) (for verification)", placeholder="e.g., 14:30:25")
 
363
 
364
+ expected_hash = st.text_input("Expected Hash (from the citation)", placeholder="Enter the full hash from the citation")
 
 
365
 
366
  verify_button = st.button("Verify Hash", type="primary", use_container_width=True)
367
 
368
  if verify_button:
369
  if not all([verify_username, verify_task_name, verify_author_name, verify_publication_year,
370
+ verify_source_url, verify_annotated_text, verify_date, verify_time, expected_hash]):
371
  st.error("Please fill in all fields before verifying the hash.")
372
  else:
373
  recomputed_hash = generate_citation_hash(
374
  verify_author_name, verify_publication_year, verify_source_url,
375
+ verify_annotated_text, verify_annotated_text, verify_username, verify_task_name,
376
  verify_date, verify_time
377
  )
378
 
 
387
  "Author": verify_author_name,
388
  "Year": verify_publication_year,
389
  "URL": verify_source_url,
390
+ "Fragment text": verify_annotated_text,
391
+ "Cited text": verify_annotated_text,
392
  "Username": verify_username,
393
  "Task name": verify_task_name,
394
  "Date": verify_date,
 
408
  "Author": verify_author_name,
409
  "Year": verify_publication_year,
410
  "URL": verify_source_url,
411
+ "Fragment text": verify_annotated_text,
412
+ "Cited text": verify_annotated_text,
413
  "Username": verify_username,
414
  "Task name": verify_task_name,
415
  "Date": verify_date,