Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,8 @@ import urllib.parse
|
|
| 4 |
from datetime import datetime
|
| 5 |
import pytz
|
| 6 |
import re
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# --- Constants ---
|
| 9 |
MELBOURNE_TIMEZONE = 'Australia/Melbourne'
|
|
@@ -88,6 +90,23 @@ def load_css():
|
|
| 88 |
margin: 0.5rem 0;
|
| 89 |
font-size: 1.4rem;
|
| 90 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
</style>
|
| 92 |
""", unsafe_allow_html=True)
|
| 93 |
|
|
@@ -165,6 +184,12 @@ def parse_metadata(fragment_text):
|
|
| 165 |
except:
|
| 166 |
return None, None, None, None
|
| 167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
# --- Live Clock JavaScript ---
|
| 169 |
def live_clock():
|
| 170 |
return """
|
|
@@ -431,6 +456,26 @@ with tabs[1]:
|
|
| 431 |
<strong>Authentic citation!</strong>
|
| 432 |
</div>
|
| 433 |
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 434 |
else:
|
| 435 |
st.markdown("""
|
| 436 |
<div class="warning-box">
|
|
|
|
| 4 |
from datetime import datetime
|
| 5 |
import pytz
|
| 6 |
import re
|
| 7 |
+
import pandas as pd
|
| 8 |
+
import base64
|
| 9 |
|
| 10 |
# --- Constants ---
|
| 11 |
MELBOURNE_TIMEZONE = 'Australia/Melbourne'
|
|
|
|
| 90 |
margin: 0.5rem 0;
|
| 91 |
font-size: 1.4rem;
|
| 92 |
}
|
| 93 |
+
|
| 94 |
+
.citation-table {
|
| 95 |
+
margin: 1rem 0;
|
| 96 |
+
width: 100%;
|
| 97 |
+
border-collapse: collapse;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
.citation-table th, .citation-table td {
|
| 101 |
+
border: 1px solid #e0e0e0;
|
| 102 |
+
padding: 0.5rem;
|
| 103 |
+
text-align: left;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
.citation-table th {
|
| 107 |
+
background: #f8f8f8;
|
| 108 |
+
font-weight: bold;
|
| 109 |
+
}
|
| 110 |
</style>
|
| 111 |
""", unsafe_allow_html=True)
|
| 112 |
|
|
|
|
| 184 |
except:
|
| 185 |
return None, None, None, None
|
| 186 |
|
| 187 |
+
def get_table_download_link(df, filename="citation_data.csv"):
|
| 188 |
+
csv = df.to_csv(index=False)
|
| 189 |
+
b64 = base64.b64encode(csv.encode()).decode()
|
| 190 |
+
href = f'<a href="data:file/csv;base64,{b64}" download="{filename}">Download Citation Data as CSV</a>'
|
| 191 |
+
return href
|
| 192 |
+
|
| 193 |
# --- Live Clock JavaScript ---
|
| 194 |
def live_clock():
|
| 195 |
return """
|
|
|
|
| 456 |
<strong>Authentic citation!</strong>
|
| 457 |
</div>
|
| 458 |
""", unsafe_allow_html=True)
|
| 459 |
+
|
| 460 |
+
# Create DataFrame for citation details
|
| 461 |
+
citation_data = {
|
| 462 |
+
"Username": [username],
|
| 463 |
+
"Task Name": [task_name],
|
| 464 |
+
"Time": [time],
|
| 465 |
+
"Date": [date],
|
| 466 |
+
"URL": [citation_base_url],
|
| 467 |
+
"Author(s) Name": [author],
|
| 468 |
+
"Year": [year],
|
| 469 |
+
"Annotated Text": [citation_fragment]
|
| 470 |
+
}
|
| 471 |
+
df = pd.DataFrame(citation_data)
|
| 472 |
+
|
| 473 |
+
# Display table
|
| 474 |
+
st.markdown("### Citation Details")
|
| 475 |
+
st.markdown(df.to_html(classes="citation-table", index=False), unsafe_allow_html=True)
|
| 476 |
+
|
| 477 |
+
# Provide download link
|
| 478 |
+
st.markdown(get_table_download_link(df), unsafe_allow_html=True)
|
| 479 |
else:
|
| 480 |
st.markdown("""
|
| 481 |
<div class="warning-box">
|