Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -127,7 +127,7 @@ def parse_metadata_hash(metadata_html):
|
|
| 127 |
return scc_hash, username, task_name, date, time
|
| 128 |
return None, None, None, None, None
|
| 129 |
|
| 130 |
-
# --- JavaScript for
|
| 131 |
def verification_js():
|
| 132 |
return """
|
| 133 |
<script>
|
|
@@ -138,20 +138,28 @@ def verification_js():
|
|
| 138 |
const hashOutput = document.getElementById('hash_output');
|
| 139 |
|
| 140 |
if (citationInput && hashInput && citationOutput && hashOutput) {
|
| 141 |
-
const citationLink = citationInput.
|
| 142 |
-
const hashLink = hashInput.
|
| 143 |
|
| 144 |
citationOutput.value = citationLink ? citationLink.outerHTML : '';
|
| 145 |
hashOutput.value = hashLink ? hashLink.outerHTML : '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
}
|
| 147 |
}
|
| 148 |
|
| 149 |
document.getElementById('citation_input').addEventListener('paste', function(e) {
|
| 150 |
-
setTimeout(updateCitationData,
|
| 151 |
});
|
| 152 |
|
| 153 |
document.getElementById('hash_input').addEventListener('paste', function(e) {
|
| 154 |
-
setTimeout(updateCitationData,
|
| 155 |
});
|
| 156 |
</script>
|
| 157 |
"""
|
|
@@ -328,68 +336,47 @@ with tabs[1]:
|
|
| 328 |
st.header("Verify Citation")
|
| 329 |
st.markdown("""
|
| 330 |
<div class="info-card">
|
| 331 |
-
Paste the
|
| 332 |
-
</div>
|
| 333 |
-
""", unsafe_allow_html=True)
|
| 334 |
-
|
| 335 |
-
# Input fields for citation and hash
|
| 336 |
-
st.markdown("""
|
| 337 |
-
<div>
|
| 338 |
-
<label>Paste Citation (with embedded link)</label>
|
| 339 |
-
<div id="citation_input" contenteditable="true" style="border: 1px solid #e0e0e0; border-radius: 4px; padding: 0.5rem; min-height: 50px; margin-bottom: 1rem;"></div>
|
| 340 |
-
<input type="hidden" id="citation_output" name="citation_output">
|
| 341 |
-
<label>Paste Hash (with embedded link)</label>
|
| 342 |
-
<div id="hash_input" contenteditable="true" style="border: 1px solid #e0e0e0; border-radius: 4px; padding: 0.5rem; min-height: 50px; margin-bottom: 1rem;"></div>
|
| 343 |
-
<input type="hidden" id="hash_output" name="hash_output">
|
| 344 |
</div>
|
| 345 |
""", unsafe_allow_html=True)
|
| 346 |
|
| 347 |
-
#
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
if 'citation_html' not in st.session_state:
|
| 352 |
st.session_state.citation_html = ''
|
| 353 |
if 'hash_html' not in st.session_state:
|
| 354 |
st.session_state.hash_html = ''
|
| 355 |
|
| 356 |
-
#
|
| 357 |
-
st.markdown("""
|
| 358 |
-
<script>
|
| 359 |
-
function updateSessionState() {
|
| 360 |
-
const citationOutput = document.getElementById('citation_output').value;
|
| 361 |
-
const hashOutput = document.getElementById('hash_output').value;
|
| 362 |
-
const params = new URLSearchParams(window.location.search);
|
| 363 |
-
params.set('citation_html', encodeURIComponent(citationOutput));
|
| 364 |
-
params.set('hash_html', encodeURIComponent(hashOutput));
|
| 365 |
-
window.history.replaceState({}, '', `${window.location.pathname}?${params}`);
|
| 366 |
-
}
|
| 367 |
-
document.getElementById('citation_input').addEventListener('paste', function() {
|
| 368 |
-
setTimeout(updateCitationData, 0);
|
| 369 |
-
setTimeout(updateSessionState, 100);
|
| 370 |
-
});
|
| 371 |
-
document.getElementById('hash_input').addEventListener('paste', function() {
|
| 372 |
-
setTimeout(updateCitationData, 0);
|
| 373 |
-
setTimeout(updateSessionState, 100);
|
| 374 |
-
});
|
| 375 |
-
</script>
|
| 376 |
-
""", unsafe_allow_html=True)
|
| 377 |
-
|
| 378 |
-
# Retrieve data from URL parameters
|
| 379 |
-
query_params = st.experimental_get_query_params()
|
| 380 |
-
st.session_state.citation_html = query_params.get('citation_html', [''])[0]
|
| 381 |
-
st.session_state.hash_html = query_params.get('hash_html', [''])[0]
|
| 382 |
-
|
| 383 |
-
verify_button = st.button("Verify Citation", type="primary", use_container_width=True)
|
| 384 |
-
|
| 385 |
if verify_button:
|
| 386 |
-
|
|
|
|
|
|
|
|
|
|
| 387 |
st.error("Please paste both the citation and hash links before verifying.")
|
| 388 |
else:
|
| 389 |
# Parse citation
|
| 390 |
-
author, year, url, fragment_text, citation_hash = parse_citation(
|
| 391 |
# Parse hash and metadata
|
| 392 |
-
scc_hash, username, task_name, date, time = parse_metadata_hash(
|
| 393 |
|
| 394 |
if not all([author, year, url, fragment_text, scc_hash, username, task_name, date, time]):
|
| 395 |
st.error("Invalid citation or hash format. Please ensure both inputs are correctly pasted links from the generated output.")
|
|
|
|
| 127 |
return scc_hash, username, task_name, date, time
|
| 128 |
return None, None, None, None, None
|
| 129 |
|
| 130 |
+
# --- JavaScript for capturing pasted links ---
|
| 131 |
def verification_js():
|
| 132 |
return """
|
| 133 |
<script>
|
|
|
|
| 138 |
const hashOutput = document.getElementById('hash_output');
|
| 139 |
|
| 140 |
if (citationInput && hashInput && citationOutput && hashOutput) {
|
| 141 |
+
const citationLink = citationInput.querySelector('a');
|
| 142 |
+
const hashLink = hashInput.querySelector('a');
|
| 143 |
|
| 144 |
citationOutput.value = citationLink ? citationLink.outerHTML : '';
|
| 145 |
hashOutput.value = hashLink ? hashLink.outerHTML : '';
|
| 146 |
+
|
| 147 |
+
// Trigger form submission to update Streamlit
|
| 148 |
+
if (citationLink || hashLink) {
|
| 149 |
+
const form = document.getElementById('verify_form');
|
| 150 |
+
if (form) {
|
| 151 |
+
form.dispatchEvent(new Event('submit'));
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
}
|
| 155 |
}
|
| 156 |
|
| 157 |
document.getElementById('citation_input').addEventListener('paste', function(e) {
|
| 158 |
+
setTimeout(updateCitationData, 100);
|
| 159 |
});
|
| 160 |
|
| 161 |
document.getElementById('hash_input').addEventListener('paste', function(e) {
|
| 162 |
+
setTimeout(updateCitationData, 100);
|
| 163 |
});
|
| 164 |
</script>
|
| 165 |
"""
|
|
|
|
| 336 |
st.header("Verify Citation")
|
| 337 |
st.markdown("""
|
| 338 |
<div class="info-card">
|
| 339 |
+
Paste the rendered citation and hash links (e.g., "Author (Year)" and "Author (Year). Hash") directly from the 'Citation Generator' tab to verify the citation's authenticity.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 340 |
</div>
|
| 341 |
""", unsafe_allow_html=True)
|
| 342 |
|
| 343 |
+
# Form to handle submission
|
| 344 |
+
with st.form(key="verify_form"):
|
| 345 |
+
st.markdown("""
|
| 346 |
+
<div>
|
| 347 |
+
<label>Paste Citation (with embedded link)</label>
|
| 348 |
+
<div id="citation_input" contenteditable="true" style="border: 1px solid #e0e0e0; border-radius: 4px; padding: 0.5rem; min-height: 50px; margin-bottom: 1rem;"></div>
|
| 349 |
+
<input type="hidden" id="citation_output" name="citation_output">
|
| 350 |
+
<label>Paste Hash (with embedded link)</label>
|
| 351 |
+
<div id="hash_input" contenteditable="true" style="border: 1px solid #e0e0e0; border-radius: 4px; padding: 0.5rem; min-height: 50px; margin-bottom: 1rem;"></div>
|
| 352 |
+
<input type="hidden" id="hash_output" name="hash_output">
|
| 353 |
+
</div>
|
| 354 |
+
""", unsafe_allow_html=True)
|
| 355 |
+
|
| 356 |
+
# Add JavaScript to capture pasted link data
|
| 357 |
+
components.html(verification_js(), height=0)
|
| 358 |
+
|
| 359 |
+
# Submit button for the form
|
| 360 |
+
verify_button = st.form_submit_button("Verify Citation", type="primary", use_container_width=True)
|
| 361 |
+
|
| 362 |
+
# Initialize session state
|
| 363 |
if 'citation_html' not in st.session_state:
|
| 364 |
st.session_state.citation_html = ''
|
| 365 |
if 'hash_html' not in st.session_state:
|
| 366 |
st.session_state.hash_html = ''
|
| 367 |
|
| 368 |
+
# Update session state with form data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
if verify_button:
|
| 370 |
+
citation_html = st.session_state.get('citation_output', '')
|
| 371 |
+
hash_html = st.session_state.get('hash_output', '')
|
| 372 |
+
|
| 373 |
+
if not (citation_html and hash_html):
|
| 374 |
st.error("Please paste both the citation and hash links before verifying.")
|
| 375 |
else:
|
| 376 |
# Parse citation
|
| 377 |
+
author, year, url, fragment_text, citation_hash = parse_citation(citation_html)
|
| 378 |
# Parse hash and metadata
|
| 379 |
+
scc_hash, username, task_name, date, time = parse_metadata_hash(hash_html)
|
| 380 |
|
| 381 |
if not all([author, year, url, fragment_text, scc_hash, username, task_name, date, time]):
|
| 382 |
st.error("Invalid citation or hash format. Please ensure both inputs are correctly pasted links from the generated output.")
|