Spaces:
Running
Running
| """ | |
| Acknowledgement: | |
| The Smart Context Citation (SCC) system was developed by Dr. Majed Abuseif. | |
| The text fragments scroll functionality in the HTML environment is based on Burris and Bokan (2023). | |
| Conceptualisation, primary coding, integration, project management, and finalisation were undertaken by Dr. Majed Abuseif. | |
| Project planning, execution plan, and review were conducted by Dr. Majed Abuseif in collaboration with ChatGPT. | |
| Formatting and design were contributed by Dr. Majed Abuseif and Manus. | |
| Programming contributions were provided by Dr. Majed Abuseif and Grok, with hosting on Hugging Face. | |
| The code is implemented in Python. | |
| """ | |
| import streamlit as st | |
| import hashlib | |
| import urllib.parse | |
| from datetime import datetime | |
| import pytz | |
| import re | |
| import pandas as pd | |
| import base64 | |
| import io | |
| import openpyxl | |
| from openpyxl.utils.dataframe import dataframe_to_rows | |
| from openpyxl.worksheet.hyperlink import Hyperlink | |
| # --- Constants --- | |
| MELBOURNE_TIMEZONE = 'Australia/Melbourne' | |
| # --- Custom CSS for simplified UI --- | |
| def load_css(): | |
| st.markdown(""" | |
| <style> | |
| .main-header { | |
| padding: 0.5rem 0; | |
| text-align: center; | |
| margin: 0.5rem 0; | |
| } | |
| .citation-output { | |
| background: #f8f8f8; | |
| border: 1px solid #e0e0e0; | |
| border-radius: 4px; | |
| padding: 1rem; | |
| margin: 1rem 0; | |
| font-family: 'Courier New', monospace; | |
| } | |
| .warning-box { | |
| background: #fff3f3; | |
| border: 1px solid #e0e0e0; | |
| border-radius: 4px; | |
| padding: 1rem; | |
| margin: 1rem 0; | |
| color: #d32f2f; | |
| } | |
| .success-box { | |
| background: #e8f5e9; | |
| border: 1px solid #e0e0e0; | |
| border-radius: 4px; | |
| padding: 1rem; | |
| margin: 1rem 0; | |
| color: #2e7d32; | |
| } | |
| .info-card { | |
| background: white; | |
| border-radius: 4px; | |
| padding: 1rem; | |
| margin: 0.5rem 0; | |
| border-left: 1px solid #e0e0e0; | |
| } | |
| .footer { | |
| text-align: center; | |
| padding: 1rem; | |
| margin-top: 1rem; | |
| border-top: 1px solid #e0e0e0; | |
| font-size: 0.9rem; | |
| } | |
| .hash-display { | |
| background: #f8f8f8; | |
| border: 1px solid #e0e0e0; | |
| border-radius: 4px; | |
| padding: 1rem; | |
| font-family: 'Courier New', monospace; | |
| font-size: 0.85rem; | |
| word-break: break-all; | |
| margin: 0.5rem 0; | |
| } | |
| .tab-content { | |
| padding: 0.5rem 0; | |
| } | |
| .datetime-display { | |
| background: #f8f8f8; | |
| border-radius: 4px; | |
| padding: 0.8rem; | |
| margin: 0.5rem 0; | |
| border-left: 1px solid #e0e0e0; | |
| } | |
| .rendered-citation { | |
| margin: 0.5rem 0; | |
| font-size: 1.4rem; | |
| } | |
| .citation-table { | |
| margin: 1rem 0; | |
| width: 100%; | |
| border-collapse: collapse; | |
| } | |
| .citation-table th, .citation-table td { | |
| border: 1px solid #e0e0e0; | |
| padding: 0.5rem; | |
| text-align: left; | |
| } | |
| .citation-table th { | |
| background: #f8f8f8; | |
| font-weight: bold; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| # --- Helper Functions --- | |
| def select_longest_segment(text): | |
| # Split text by various dashes (hyphen, non-breaking hyphen, en dash, em dash) | |
| dash_variants = ['\u002D', '\u2011', '\u2013', '\u2014'] | |
| segments = [text] | |
| for dash in dash_variants: | |
| new_segments = [] | |
| for segment in segments: | |
| new_segments.extend(segment.split(dash)) | |
| segments = new_segments | |
| # Return the longest segment, or original text if no dashes | |
| return max(segments, key=len, default=text).strip() | |
| def encode_text_fragment(text): | |
| # Encode text for W3C Text Fragments, preserving only regular hyphens (U+002D) | |
| # Non-breaking hyphens (U+2011) are encoded as %E2%80%91 | |
| # En dashes (U+2013) are encoded as %E2%80%93 | |
| # Em dashes (U+2014) are encoded as %E2%80%94 | |
| return urllib.parse.quote(text, safe='-') | |
| def generate_citation_hash(author, year, url, fragment_text, cited_text, username, task_name, current_date, current_time): | |
| # Normalize inputs by stripping whitespace | |
| fragment_text = select_longest_segment(fragment_text.strip()) | |
| cited_text = select_longest_segment(cited_text.strip()) | |
| task_name = task_name.strip() | |
| author = author.strip() | |
| url = url.strip() | |
| username = username.strip() | |
| data = f"{author}, {year} | {url} | {fragment_text} | {cited_text} | {username} | {task_name} | {current_date} | {current_time}" | |
| return hashlib.sha256(data.encode('utf-8')).hexdigest() | |
| def format_citation_html(url, fragment_text, author, year, scc_hash): | |
| # Select the longest segment for the text fragment to avoid breaking the link | |
| selected_fragment = select_longest_segment(fragment_text) | |
| encoded_fragment = encode_text_fragment(selected_fragment) | |
| full_url = f"{url}#:~:text={encoded_fragment}" | |
| return f'<a href="{full_url}" data-hash="{scc_hash}">{author} ({year})</a>' | |
| def format_metadata_html(url, author, year, scc_hash, username, task_name, current_date, current_time): | |
| # Use original task_name with em dashes for text fragment URL | |
| metadata = f"{username}β{task_name}β{current_date}β{current_time}" | |
| encoded_metadata = encode_text_fragment(metadata) | |
| full_url = f"{url}#:~:text={encoded_metadata}" | |
| return f'<a href="{full_url}" data-hash="{scc_hash}">{author} ({year}). {scc_hash}</a>' | |
| def check_for_fragment(url): | |
| return '#:~:text=' in url | |
| def parse_citation_text(citation_text): | |
| match = re.match(r'^(?:(\w[\w\s.,&et al]+)\s*\((\d{4})\)|\((\w[\w\s.,&et al]+),\s*(\d{4})\))$', citation_text.strip()) | |
| if match: | |
| author = match.group(1) or match.group(3) | |
| year = match.group(2) or match.group(4) | |
| author = author.strip() | |
| return author, year | |
| return None, None | |
| def parse_url(url): | |
| if not url: | |
| return None, None | |
| try: | |
| match = re.search(r'#:~:text=([^&]+)', url) | |
| fragment_text = urllib.parse.unquote(match.group(1)) if match else None | |
| base_url = url.split('#')[0] | |
| return base_url, fragment_text | |
| except: | |
| return None, None | |
| def parse_hash_text(hash_text): | |
| match = re.match(r'.*?\(\d{4}\)\.\s*([0-9a-f]{64})', hash_text.strip()) | |
| if match: | |
| return match.group(1) | |
| return None | |
| def parse_metadata(fragment_text): | |
| if not fragment_text: | |
| return None, None, None, None | |
| try: | |
| metadata_parts = fragment_text.split('β') | |
| if len(metadata_parts) == 4: | |
| username, task_name, date, time = metadata_parts | |
| return username, task_name, date, time | |
| return None, None, None, None | |
| except: | |
| return None, None, None, None | |
| def get_table_download_link(df, filename="citation_data.csv"): | |
| csv = df.to_csv(index=False) | |
| b64 = base64.b64encode(csv.encode()).decode() | |
| href = f'<a href="data:file/csv;base64,{b64}" download="{filename}">Download Citation Data as CSV</a>' | |
| return href | |
| def get_excel_download_link(df, filename="citation_data.xlsx"): | |
| output = io.BytesIO() | |
| wb = openpyxl.Workbook() | |
| ws = wb.active | |
| # Write headers | |
| headers = df.columns.tolist() | |
| ws.append(headers) | |
| # Write data rows | |
| for index, row in df.iterrows(): | |
| row_data = [] | |
| cell_positions = {} # track cell positions for hyperlink assignment | |
| urls = {} # store URLs per column | |
| for col_idx, col in enumerate(headers): | |
| value = row[col] | |
| if col in ["Citation", "SCC Index"]: | |
| # Extract URL and display text from HTML anchor tag | |
| match = re.search(r'<a href="([^"]+)"[^>]*>([^<]+)</a>', str(value)) | |
| if match: | |
| link_url, display_text = match.groups() | |
| row_data.append(display_text) | |
| # Position where this cell will be written (next row after append) | |
| cell_positions[col] = (ws.max_row + 1, col_idx + 1) | |
| urls[col] = link_url | |
| else: | |
| row_data.append(value) | |
| else: | |
| row_data.append(value) | |
| ws.append(row_data) | |
| # Apply hyperlinks after appending row | |
| for col, (r, c) in cell_positions.items(): | |
| cell = ws.cell(row=r, column=c) | |
| cell.hyperlink = urls[col] | |
| cell.hyperlink.tooltip = "Click to visit source" | |
| cell.style = "Hyperlink" | |
| wb.save(output) | |
| b64 = base64.b64encode(output.getvalue()).decode() | |
| href = f'<a href="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,{b64}" download="{filename}">Download citation data as Excel</a>' | |
| return href | |
| # --- Live Clock JavaScript --- | |
| def live_clock(): | |
| return """ | |
| <div class="datetime-display"> | |
| <span id="live_datetime"></span> | |
| </div> | |
| <script> | |
| function updateClock() { | |
| const options = { | |
| timeZone: 'Australia/Melbourne', | |
| year: 'numeric', | |
| month: '2-digit', | |
| day: '2-digit', | |
| hour: '2-digit', | |
| minute: '2-digit', | |
| second: '2-digit', | |
| hour12: false | |
| }; | |
| const formatter = new Intl.DateTimeFormat('en-AU', options); | |
| const now = new Date(); | |
| const parts = formatter.formatToParts(now); | |
| const date = `${parts[4].value}-${parts[2].value}-${parts[0].value}`; | |
| const time = `${parts[6].value}:${parts[8].value}:${parts[10].value}`; | |
| const datetimeElement = document.getElementById('live_datetime'); | |
| if (datetimeElement) { | |
| datetimeElement.innerText = `${date} ${time}`; | |
| } | |
| } | |
| updateClock(); | |
| setInterval(updateClock, 1000); | |
| </script> | |
| """ | |
| # --- Streamlit App --- | |
| st.set_page_config(layout="wide", page_title="Smart Context Citation Tool") | |
| # Load custom CSS | |
| load_css() | |
| # Main header | |
| st.markdown(""" | |
| <div class="main-header"> | |
| <h1>Smart Context Citation (SCC) Tool</h1> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| # Expandable section for About SCC and Example Citation | |
| with st.expander("About SCC and Example Citation"): | |
| st.markdown(""" | |
| <div class="info-card"> | |
| <p>The Smart Context Citation (SCC) style is a modern referencing system designed to enhance transparency and integrity in academic citations, particularly in the era of generative AI. It integrates context directly into citations, uses cryptographic hashes for verification, and replaces the traditional reference list with an SCC Index that includes an Authenticated Citation Identifier (ACI).</p> | |
| <h4>Key Features</h4> | |
| <ul> | |
| <li><strong>Inline Citations:</strong> Uses author-year format, either "Author (Year)" or "(Author, Year)", hyperlinked to the source with a text fragment.</li> | |
| <li><strong>SCC Index:</strong> A unique SHA-256 hash ensures citation authenticity, linked to metadata including username, task, date, and time.</li> | |
| <li><strong>Benefits:</strong> Promotes digital fluency, ensures source traceability, prevents fabrication, and simplifies referencing.</li> | |
| </ul> | |
| <h4>Technical Legitimacy</h4> | |
| The SCC style uses the W3C Text Fragments specification by <a href="https://wicg.github.io/scroll-to-text-fragment/#:~:text=Editors%3A" target="_blank">Burris and Bokan (2023)</a> to enable precise linking to specific sections of digital content. This ensures that citations are contextually accurate, verifiable, and aligned with modern digital standards. | |
| <h4>Acknowledgement</h4> | |
| Smart Context Citation (SCC) developed by Dr. Majed Abuseif, with contributions from ChatGPT, Manus-AI, and Grok, hosted on Hugging Face. | |
| <h4>Example Citation</h4> | |
| <p><strong>Inputs:</strong></p> | |
| <ul> | |
| <li><strong>Username:</strong> Majed</li> | |
| <li><strong>Task Name:</strong> Design Strategies for Trees on Buildings</li> | |
| <li><strong>Author:</strong> Abuseif et al.</li> | |
| <li><strong>Year:</strong> 2023</li> | |
| <li><strong>URL:</strong> https://www.sciencedirect.com/science/article/pii/S2772411523000046</li> | |
| <li><strong>Annotated Text:</strong> Fig. 3. A proposed design framework for green roof settings in general and trees on buildings in particular. The framework consists of four categories that are required to be followed in order from outside to inside.</li> | |
| </ul> | |
| <p><strong>Outputs:</strong></p> | |
| <ul> | |
| <li><strong>Citation (Start of Text):</strong> <span style="font-size: 1.2rem;"><a href="https://www.sciencedirect.com/science/article/pii/S2772411523000046#:~:text=Fig.%203.%20A%20proposed%20design%20framework%20for%20green%20roof%20settings%20in%20general%20and%20trees%20on%20buildings%20in%20particular.%20The%20framework%20consists%20of%20four%20categories%20that%20are%20required%20to%20be%20followed%20in%20order%20from%20outside%20to%20inside.">Abuseif et al. (2023)</a></span></li> | |
| <li><strong>Citation (End of Text):</strong> <span style="font-size: 1.2rem;"><a href="https://www.sciencedirect.com/science/article/pii/S2772411523000046#:~:text=Fig.%203.%20A%20proposed%20design%20framework%20for%20green%20roof%20settings%20in%20general%20and%20trees%20on%20buildings%20in%20particular.%20The%20framework%20consists%20of%20four%20categories%20that%20are%20required%20to%20be%20followed%20in%20order%20from%20outside%20to%20inside.">(Abuseif et al., 2023)</a></span></li> | |
| <li><strong>SCC Index:</strong> <span style="font-size: 0.85rem;"><a href="https://www.sciencedirect.com/science/article/pii/S2772411523000046#:~:text=Majed%E2%80%94Design%20Strategies%20for%20Trees%20on%20Buildings%E2%80%942025-08-07%E2%80%9422%3A53%3A15">Abuseif et al. (2023). dd344cfa83eeaec090c1b957900af960a2ea9993eef6a3fc1aca2d9881a03ea4</a></span></li> | |
| </ul> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| # Expandable section for SCC Style Guidelines | |
| with st.expander("SCC Style Guidelines"): | |
| st.markdown(""" | |
| <div class="info-card"> | |
| <p>The Smart Context Citation (SCC) style ensures accurate, transparent, and verifiable citations. Follow these steps to generate and verify citations using the SCC Tool.</p> | |
| <h4>Generating Citations</h4> | |
| <ol> | |
| <li><strong>Access the Tool:</strong> Open the "Citation Generator" tab.</li> | |
| <li><strong>Enter User Information:</strong> | |
| <ul> | |
| <li><strong>Username:</strong> Your unique identifier (e.g., Majed).</li> | |
| <li><strong>Task Name:</strong> The project or assignment name (e.g., Design Strategies for Trees on Buildings).</li> | |
| </ul> | |
| </li> | |
| <li><strong>Enter Citation Information:</strong> | |
| <ul> | |
| <li><strong>Author(s) Name:</strong> The author(s) of the source (e.g., Abuseif et al.).</li> | |
| <li><strong>Publication Year:</strong> The year of publication (e.g., 2023).</li> | |
| <li><strong>Source URL:</strong> The full URL of the source, without text fragments (e.g., https://www.sciencedirect.com/science/article/pii/S2772411523000046).</li> | |
| <li><strong>Annotated Text:</strong> The sentence or paragraph containing the information you are referencing from the source (e.g., A proposed design framework for green roof settings in general and trees on buildings in particular).</li> | |
| </ul> | |
| </li> | |
| <li><strong>Generate Citation:</strong> Click the "Generate Citation" button.</li> | |
| <li><strong>Copy Outputs:</strong> | |
| <ul> | |
| <li><strong>Citation (Start of Text):</strong> Use "Author (Year)" for the start of a sentence (e.g., Abuseif et al. (2023)).</li> | |
| <li><strong>Citation (End of Text):</strong> Use "(Author, Year)" for in-text citations (e.g., (Abuseif et al., 2023)).</li> | |
| <li><strong>SCC Index:</strong> Copy the index link (e.g., Abuseif et al. (2023). cda7ba19e51e430107e58696758fdf79b8f016d8f27e8f8691ad713e7c8bc668) for verification.</li> | |
| <li>If you would like to test the reference before using it, click on it to check whether it is suitable and captures the information you need.</li> | |
| </ul> | |
| </li> | |
| </ol> | |
| <h4>Using References and the SCC Index in Your Document</h4> | |
| <ol> | |
| <li>Paste the reference directly in the appropriate place within your document.</li> | |
| <li>Create an SCC Index (instead of a traditional reference list), and paste the corresponding SCC Index entry for each reference youβve used.</li> | |
| </ol> | |
| <h4>Verifying Citations (for Markers and Reviewers)</h4> | |
| <ol> | |
| <li><strong>Access the Tool:</strong> Open the "Verify Citation" tab.</li> | |
| <li><strong>Enter Citation Information:</strong> | |
| <ul> | |
| <li><strong>Citation Text:</strong> Paste the citation text (e.g., Abuseif et al. (2023) or (Abuseif et al., 2023)).</li> | |
| <li><strong>Citation URL:</strong> Paste the hyperlink URL from the citation (right-click and select "Copy Link Address").</li> | |
| </ul> | |
| </li> | |
| <li><strong>Enter SCC Index Information:</strong> | |
| <ul> | |
| <li><strong>SCC Index Text:</strong> Paste the index text (e.g., Abuseif et al. (2023). cda7ba19e51e430107e58696758fdf79b8f016d8f27e8f8691ad713e7c8bc668).</li> | |
| <li><strong>SCC Index URL:</strong> Paste the hyperlink URL from the index (right-click and select "Copy Link Address").</li> | |
| </ul> | |
| </li> | |
| <li><strong>Verify Citation:</strong> Click the "Verify Citation" button.</li> | |
| <li><strong>Review Result:</strong> | |
| <ul> | |
| <li><strong>Authentic Citation:</strong> Displayed in green if the hash matches, confirming integrity.</li> | |
| <li><strong>Unauthentic Citation:</strong> Displayed in red if the hash does not match, indicating potential tampering.</li> | |
| </ul> | |
| </li> | |
| </ol> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| tabs = st.tabs(["Citation Generator", "Verify Citation"]) | |
| with tabs[0]: | |
| st.markdown('<div class="tab-content">', unsafe_allow_html=True) | |
| # User Information Section | |
| st.subheader("User Information") | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| username = st.text_input("Username", help="Your username for tracking purposes", placeholder="e.g., Majed") | |
| with col2: | |
| task_name = st.text_input("Task Name", help="The name of the task or project", placeholder="e.g., Design Strategies for Trees on Buildings") | |
| # Citation Info Section | |
| st.subheader("Citation Info") | |
| col3, col4 = st.columns(2) | |
| with col3: | |
| author_name = st.text_input("Author(s) Name", help="The author(s) of the source", placeholder="e.g., Abuseif et al.") | |
| with col4: | |
| publication_year = st.text_input("Publication Year", help="The year of publication", placeholder="e.g., 2023") | |
| col5, col6 = st.columns(2) | |
| with col5: | |
| source_url = st.text_input("Source URL", help="The full URL of the source", placeholder="https://www.sciencedirect.com/science/article/pii/S2772411523000046") | |
| with col6: | |
| annotated_text = st.text_input("Annotated Text", help="The sentence or paragraph containing the information you are referencing from the source", placeholder="e.g., A proposed design framework for green roof settings...") | |
| # Live date and time display | |
| st.markdown("### Current Date and Time (AEST)") | |
| st.components.v1.html(live_clock(), height=50) | |
| # Get current date and time in Melbourne timezone for hash generation | |
| melbourne_tz = pytz.timezone(MELBOURNE_TIMEZONE) | |
| current_datetime_melbourne = datetime.now(melbourne_tz) | |
| current_date = current_datetime_melbourne.strftime("%Y-%m-%d") | |
| current_time = current_datetime_melbourne.strftime("%H:%M:%S") | |
| generate_button = st.button("Generate Citation", type="primary", use_container_width=True) | |
| if generate_button: | |
| if not all([username, task_name, author_name, publication_year, source_url, annotated_text]): | |
| st.error("Please fill in all fields before generating a citation.") | |
| elif check_for_fragment(source_url): | |
| st.markdown(""" | |
| <div class="warning-box"> | |
| <strong>Warning:</strong> Your URL already contains a text fragment, which suggests you may have used AI assistance in your research. Please revisit the source, review the context carefully, and copy the source link againβensuring it does not include any existing fragments. | |
| </div> | |
| """, unsafe_allow_html=True) | |
| else: | |
| # Generate hash using normalized inputs | |
| scc_hash = generate_citation_hash(author_name, publication_year, source_url, annotated_text, annotated_text, username, task_name, current_date, current_time) | |
| citation_link_start = format_citation_html(source_url, annotated_text, author_name, publication_year, scc_hash) | |
| # Use the longest segment for the end-of-text citation link | |
| selected_fragment = select_longest_segment(annotated_text) | |
| citation_link_end = f'<a href="{source_url}#:~:text={encode_text_fragment(selected_fragment)}" data-hash="{scc_hash}">({author_name}, {publication_year})</a>' | |
| metadata_link = format_metadata_html(source_url, author_name, publication_year, scc_hash, username, task_name, current_date, current_time) | |
| # --- Persistent Table with Clickable SCC Hash --- | |
| # First, ensure session state is initialized for the citation DataFrame | |
| if 'citation_df' not in st.session_state: | |
| st.session_state.citation_df = pd.DataFrame(columns=[ | |
| "Username", "Task Name", "Time", "Date", | |
| "Citation", "SCC Index", "Annotated Text" | |
| ]) | |
| # Create clickable HTML for SCC Index (full metadata link) | |
| clickable_index = metadata_link | |
| # Create new row data | |
| new_row = { | |
| "Username": username, | |
| "Task Name": task_name, | |
| "Time": current_time, | |
| "Date": current_date, | |
| "Citation": citation_link_start, | |
| "SCC Index": clickable_index, | |
| "Annotated Text": annotated_text | |
| } | |
| # Append the new row to the session state DataFrame | |
| new_df = pd.DataFrame([new_row]) | |
| st.session_state.citation_df = pd.concat([st.session_state.citation_df, new_df], ignore_index=True) | |
| # Get the accumulated DataFrame for display and download | |
| df = st.session_state.citation_df | |
| col_html1, col_html2 = st.columns(2) | |
| # HTML Citation - Start of Text | |
| with col_html1: | |
| st.markdown("### Citation (Start of Text)") | |
| st.markdown('<div class="rendered-citation">', unsafe_allow_html=True) | |
| st.markdown(citation_link_start, unsafe_allow_html=True) | |
| st.markdown('</div>', unsafe_allow_html=True) | |
| # HTML Citation - End of Text | |
| with col_html2: | |
| st.markdown("### Citation (End of Text)") | |
| st.markdown('<div class="rendered-citation">', unsafe_allow_html=True) | |
| st.markdown(citation_link_end, unsafe_allow_html=True) | |
| st.markdown('</div>', unsafe_allow_html=True) | |
| # SCC Index | |
| st.markdown("### SCC Index") | |
| st.markdown(metadata_link, unsafe_allow_html=True) | |
| # Display table after SCC Index | |
| st.markdown("### Citation Table") | |
| st.markdown(get_excel_download_link(df), unsafe_allow_html=True) | |
| st.markdown(df.to_html(classes="citation-table", index=False, escape=False), unsafe_allow_html=True) | |
| st.markdown('</div>', unsafe_allow_html=True) | |
| with tabs[1]: | |
| st.markdown('<div class="tab-content">', unsafe_allow_html=True) | |
| st.subheader("Citation Information") | |
| citation_text = st.text_input("Citation Text", help="Paste the citation text, e.g., 'Abuseif et al. (2023)' or '(Abuseif et al., 2023)'", placeholder="e.g., Abuseif et al. (2023)") | |
| citation_url = st.text_input("Citation URL", help="Paste the hyperlink URL from the citation, e.g., 'https://www.sciencedirect.com/science/article/pii/S2772411523000046#:~:text=fragment'", placeholder="e.g., https://www.sciencedirect.com/science/article/pii/S2772411523000046#:~:text=fragment") | |
| st.subheader("SCC Index") | |
| hash_text = st.text_input("SCC Index Text", help="Paste the index text, e.g., 'Abuseif et al. (2023). <hash>'", placeholder="e.g., Abuseif et al. (2023). <hash>") | |
| hash_url = st.text_input("SCC Index URL", help="Paste the hyperlink URL from the index, e.g., 'https://www.sciencedirect.com/science/article/pii/S2772411523000046#:~:text=metadata'", placeholder="e.g., https://www.sciencedirect.com/science/article/pii/S2772411523000046#:~:text=metadata") | |
| verify_button = st.button("Verify Citation", type="primary", use_container_width=True) | |
| if verify_button: | |
| if not all([citation_text, citation_url, hash_text, hash_url]): | |
| st.error("Please provide all fields (citation text, citation URL, SCC index text, SCC index URL) before verifying.") | |
| else: | |
| # Parse citation text | |
| author, year = parse_citation_text(citation_text) | |
| # Parse citation URL | |
| citation_base_url, citation_fragment = parse_url(citation_url) | |
| # Parse hash text | |
| scc_hash = parse_hash_text(hash_text) | |
| # Parse hash URL | |
| hash_base_url, hash_fragment = parse_url(hash_url) | |
| # Parse metadata from hash URL fragment | |
| username, task_name, date, time = parse_metadata(hash_fragment) | |
| if not all([author, year, citation_base_url, citation_fragment, scc_hash, hash_base_url, username, task_name, date, time]): | |
| st.error("Invalid input format. Ensure the citation text, URLs, and SCC index text are correctly pasted from the generated output.") | |
| elif citation_base_url != hash_base_url: | |
| st.error("The citation URL and SCC index URL must point to the same base URL.") | |
| else: | |
| # Normalize inputs by stripping whitespace | |
| citation_fragment = citation_fragment.strip() | |
| task_name = task_name.strip() | |
| # Check for potential truncation | |
| if len(citation_fragment) < 20: | |
| st.markdown(""" | |
| <div class="warning-box"> | |
| <strong>Warning:</strong> The citation text fragment may be truncated, which could cause verification to fail. | |
| </div> | |
| """, unsafe_allow_html=True) | |
| selected_citation_fragment = select_longest_segment(citation_fragment) | |
| # Recompute hash | |
| recomputed_hash = generate_citation_hash( | |
| author, year, citation_base_url, selected_citation_fragment, selected_citation_fragment, username, task_name, date, time | |
| ) | |
| if recomputed_hash == scc_hash: | |
| st.markdown(""" | |
| <div class="success-box"> | |
| <strong>Authentic citation!</strong> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| # Create DataFrame for citation details | |
| citation_data = { | |
| "Username": [username], | |
| "Task Name": [task_name], | |
| "Time": [time], | |
| "Date": [date], | |
| "URL": [citation_base_url], | |
| "Author(s) Name": [author], | |
| "Year": [year], | |
| "Annotated Text": [citation_fragment] | |
| } | |
| df = pd.DataFrame(citation_data) | |
| # Display table | |
| st.markdown("### Citation Details") | |
| st.markdown(df.to_html(classes="citation-table", index=False), unsafe_allow_html=True) | |
| # Provide download link | |
| st.markdown(get_table_download_link(df), unsafe_allow_html=True) | |
| else: | |
| st.markdown(""" | |
| <div class="warning-box"> | |
| <strong>Unauthentic citation</strong> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| st.markdown('</div>', unsafe_allow_html=True) | |
| # Footer | |
| st.markdown(""" | |
| <div class="footer"> | |
| Developed by: Dr Majed Abuseif<br> | |
| School of Architecture and Built Environment<br> | |
| Deakin University<br> | |
| Β© 2025 | |
| </div> | |
| """, unsafe_allow_html=True) |