Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -132,14 +132,13 @@ def encode_text_fragment(text):
|
|
| 132 |
|
| 133 |
def generate_citation_hash(author, year, url, fragment_text, cited_text, username, task_name, current_date, current_time):
|
| 134 |
# Normalize inputs by stripping whitespace
|
| 135 |
-
fragment_text = fragment_text.strip()
|
| 136 |
-
cited_text = cited_text.strip()
|
| 137 |
task_name = task_name.strip()
|
| 138 |
author = author.strip()
|
| 139 |
url = url.strip()
|
| 140 |
username = username.strip()
|
| 141 |
-
|
| 142 |
-
data = f"{author}, {year} | {url} | {fragment_text} | {selected_cited_text} | {username} | {task_name} | {current_date} | {current_time}"
|
| 143 |
return hashlib.sha256(data.encode('utf-8')).hexdigest()
|
| 144 |
|
| 145 |
def format_citation_html(url, fragment_text, author, year, scc_hash):
|
|
@@ -227,7 +226,7 @@ def live_clock():
|
|
| 227 |
const date = `${parts[4].value}-${parts[2].value}-${parts[0].value}`;
|
| 228 |
const time = `${parts[6].value}:${parts[8].value}:${parts[10].value}`;
|
| 229 |
const datetimeElement = document.getElementById('live_datetime');
|
| 230 |
-
if datetimeElement
|
| 231 |
datetimeElement.innerText = `${date} ${time}`;
|
| 232 |
}
|
| 233 |
}
|
|
@@ -459,16 +458,16 @@ with tabs[1]:
|
|
| 459 |
citation_fragment = citation_fragment.strip()
|
| 460 |
task_name = task_name.strip()
|
| 461 |
# Check for potential truncation
|
| 462 |
-
if len(citation_fragment) <
|
| 463 |
st.markdown("""
|
| 464 |
<div class="warning-box">
|
| 465 |
-
<strong>Warning:</strong> The citation text fragment
|
| 466 |
</div>
|
| 467 |
""", unsafe_allow_html=True)
|
| 468 |
selected_citation_fragment = select_longest_segment(citation_fragment)
|
| 469 |
# Recompute hash
|
| 470 |
recomputed_hash = generate_citation_hash(
|
| 471 |
-
author, year, citation_base_url,
|
| 472 |
)
|
| 473 |
|
| 474 |
if recomputed_hash == scc_hash:
|
|
|
|
| 132 |
|
| 133 |
def generate_citation_hash(author, year, url, fragment_text, cited_text, username, task_name, current_date, current_time):
|
| 134 |
# Normalize inputs by stripping whitespace
|
| 135 |
+
fragment_text = select_longest_segment(fragment_text.strip())
|
| 136 |
+
cited_text = select_longest_segment(cited_text.strip())
|
| 137 |
task_name = task_name.strip()
|
| 138 |
author = author.strip()
|
| 139 |
url = url.strip()
|
| 140 |
username = username.strip()
|
| 141 |
+
data = f"{author}, {year} | {url} | {fragment_text} | {cited_text} | {username} | {task_name} | {current_date} | {current_time}"
|
|
|
|
| 142 |
return hashlib.sha256(data.encode('utf-8')).hexdigest()
|
| 143 |
|
| 144 |
def format_citation_html(url, fragment_text, author, year, scc_hash):
|
|
|
|
| 226 |
const date = `${parts[4].value}-${parts[2].value}-${parts[0].value}`;
|
| 227 |
const time = `${parts[6].value}:${parts[8].value}:${parts[10].value}`;
|
| 228 |
const datetimeElement = document.getElementById('live_datetime');
|
| 229 |
+
if (datetimeElement) {
|
| 230 |
datetimeElement.innerText = `${date} ${time}`;
|
| 231 |
}
|
| 232 |
}
|
|
|
|
| 458 |
citation_fragment = citation_fragment.strip()
|
| 459 |
task_name = task_name.strip()
|
| 460 |
# Check for potential truncation
|
| 461 |
+
if len(citation_fragment) < 20:
|
| 462 |
st.markdown("""
|
| 463 |
<div class="warning-box">
|
| 464 |
+
<strong>Warning:</strong> The citation text fragment may be truncated, which could cause verification to fail.
|
| 465 |
</div>
|
| 466 |
""", unsafe_allow_html=True)
|
| 467 |
selected_citation_fragment = select_longest_segment(citation_fragment)
|
| 468 |
# Recompute hash
|
| 469 |
recomputed_hash = generate_citation_hash(
|
| 470 |
+
author, year, citation_base_url, selected_citation_fragment, selected_citation_fragment, username, task_name, date, time
|
| 471 |
)
|
| 472 |
|
| 473 |
if recomputed_hash == scc_hash:
|