Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,7 +34,7 @@ def load_css():
|
|
| 34 |
color: black;
|
| 35 |
border: none;
|
| 36 |
padding: 0.5rem 1rem;
|
| 37 |
-
|
| 38 |
cursor: pointer;
|
| 39 |
font-size: 0.9rem;
|
| 40 |
margin-top: 0.5rem;
|
|
@@ -115,10 +115,7 @@ def generate_citation_hash(author, year, url, fragment_text, cited_text, usernam
|
|
| 115 |
def format_citation_html(url, fragment_text, author, year, scc_hash):
|
| 116 |
encoded_fragment = urllib.parse.quote(fragment_text)
|
| 117 |
full_url = f"{url}#:~:text={encoded_fragment}"
|
| 118 |
-
return f'<a href="{full_url}" data-hash="{scc_hash}">
|
| 119 |
-
|
| 120 |
-
def format_citation_plaintext(author, year, scc_hash):
|
| 121 |
-
return f'({author}, {year}) [hash: {scc_hash[:12]}...]'
|
| 122 |
|
| 123 |
def check_for_fragment(url):
|
| 124 |
return '#:~:text=' in url
|
|
@@ -215,11 +212,11 @@ with st.expander("About SCC and Example Citation"):
|
|
| 215 |
- Author: <code>Abuseif et al.</code><br>
|
| 216 |
- Year: <code>2025</code><br>
|
| 217 |
- URL: <code>https://www.sciencedirect.com/science/article/pii/S2772411523000046</code><br>
|
| 218 |
-
- Text: <code>A proposed design framework for green roof settings in general and trees on buildings</code
|
| 219 |
|
| 220 |
-
<strong>Output (HTML
|
| 221 |
<div class="hash-display">
|
| 222 |
-
<a href="https://www.sciencedirect.com/science/article/pii/S2772411523000046#:~:text=A%20proposed%20design%20framework%20for%20green%20roof%20settings%20in%20general%20and%20trees%20on%20buildings" data-hash="[GENERATED_HASH]">
|
| 223 |
</div>
|
| 224 |
</div>
|
| 225 |
""", unsafe_allow_html=True)
|
|
@@ -279,33 +276,27 @@ with tabs[0]:
|
|
| 279 |
scc_hash = generate_citation_hash(author_name, publication_year, source_url, annotated_text, annotated_text, username, task_name, current_date, current_time)
|
| 280 |
|
| 281 |
st.markdown("## Generated Citations")
|
|
|
|
| 282 |
|
| 283 |
-
# HTML Citation - Start of
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
st.markdown("### Plaintext Citation")
|
| 303 |
-
plaintext_citation = format_citation_plaintext(author_name, publication_year, scc_hash)
|
| 304 |
-
|
| 305 |
-
st.markdown('<div class="citation-output">', unsafe_allow_html=True)
|
| 306 |
-
st.code(plaintext_citation)
|
| 307 |
-
st.markdown(copy_to_clipboard_js(plaintext_citation, "plaintext"), unsafe_allow_html=True)
|
| 308 |
-
st.markdown('</div>', unsafe_allow_html=True)
|
| 309 |
|
| 310 |
# Citation Hash Details
|
| 311 |
st.markdown("### Citation Hash Details (for Verification)")
|
|
|
|
| 34 |
color: black;
|
| 35 |
border: none;
|
| 36 |
padding: 0.5rem 1rem;
|
| 37 |
+
border-radius: 4px;
|
| 38 |
cursor: pointer;
|
| 39 |
font-size: 0.9rem;
|
| 40 |
margin-top: 0.5rem;
|
|
|
|
| 115 |
def format_citation_html(url, fragment_text, author, year, scc_hash):
|
| 116 |
encoded_fragment = urllib.parse.quote(fragment_text)
|
| 117 |
full_url = f"{url}#:~:text={encoded_fragment}"
|
| 118 |
+
return f'<a href="{full_url}" data-hash="{scc_hash}">{author}, {year}</a>'
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
def check_for_fragment(url):
|
| 121 |
return '#:~:text=' in url
|
|
|
|
| 212 |
- Author: <code>Abuseif et al.</code><br>
|
| 213 |
- Year: <code>2025</code><br>
|
| 214 |
- URL: <code>https://www.sciencedirect.com/science/article/pii/S2772411523000046</code><br>
|
| 215 |
+
- Text: <code>A proposed design framework for green roof settings in general and trees on buildings</code><br>
|
| 216 |
|
| 217 |
+
<strong>Output (HTML):</strong><br>
|
| 218 |
<div class="hash-display">
|
| 219 |
+
<a href="https://www.sciencedirect.com/science/article/pii/S2772411523000046#:~:text=A%20proposed%20design%20framework%20for%20green%20roof%20settings%20in%20general%20and%20trees%20on%20buildings" data-hash="[GENERATED_HASH]">Abuseif et al., 2025</a>
|
| 220 |
</div>
|
| 221 |
</div>
|
| 222 |
""", unsafe_allow_html=True)
|
|
|
|
| 276 |
scc_hash = generate_citation_hash(author_name, publication_year, source_url, annotated_text, annotated_text, username, task_name, current_date, current_time)
|
| 277 |
|
| 278 |
st.markdown("## Generated Citations")
|
| 279 |
+
col_html1, col_html2 = st.columns(2)
|
| 280 |
|
| 281 |
+
# HTML Citation - Start of Text
|
| 282 |
+
with col_html1:
|
| 283 |
+
st.markdown("### HTML Citation (Start of Text)")
|
| 284 |
+
html_citation_start = f'"{annotated_text}" (<a href="{source_url}#:~:text={urllib.parse.quote(annotated_text)}" data-hash="{scc_hash}">{author_name}, {publication_year}</a>)'
|
| 285 |
+
|
| 286 |
+
st.markdown('<div class="citation-output">', unsafe_allow_html=True)
|
| 287 |
+
st.code(html_citation_start, language='html')
|
| 288 |
+
st.markdown(copy_to_clipboard_js(html_citation_start.replace('`', '\\`'), "html_start"), unsafe_allow_html=True)
|
| 289 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 290 |
+
|
| 291 |
+
# HTML Citation - End of Text
|
| 292 |
+
with col_html2:
|
| 293 |
+
st.markdown("### HTML Citation (End of Text)")
|
| 294 |
+
html_citation_end = f'(<a href="{source_url}#:~:text={urllib.parse.quote(annotated_text)}" data-hash="{scc_hash}">{author_name}, {publication_year}</a>) "{annotated_text}"'
|
| 295 |
+
|
| 296 |
+
st.markdown('<div class="citation-output">', unsafe_allow_html=True)
|
| 297 |
+
st.code(html_citation_end, language='html')
|
| 298 |
+
st.markdown(copy_to_clipboard_js(html_citation_end.replace('`', '\\`'), "html_end"), unsafe_allow_html=True)
|
| 299 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
|
| 301 |
# Citation Hash Details
|
| 302 |
st.markdown("### Citation Hash Details (for Verification)")
|