Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -126,36 +126,40 @@ collection_url = f"https://www.loc.gov/search/?q={search_query}&fo=json"
|
|
126 |
# Create an empty placeholder for Quick Stats
|
127 |
stats_placeholder = st.sidebar.empty()
|
128 |
|
|
|
|
|
|
|
129 |
# Helpful Resources (styled and moved below dropdown)
|
130 |
st.sidebar.markdown("### Helpful Resources", unsafe_allow_html=True)
|
131 |
# Helpful Resources styled section
|
|
|
132 |
st.sidebar.markdown("""
|
133 |
-
<style>
|
134 |
-
.sidebar-section h3 {
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
}
|
139 |
-
.sidebar-links a {
|
140 |
-
|
141 |
-
|
142 |
-
}
|
143 |
-
.sidebar-links a:hover {
|
144 |
-
|
145 |
-
}
|
146 |
-
</style>
|
147 |
-
<div class="sidebar-section">
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
</div>
|
159 |
""", unsafe_allow_html=True)
|
160 |
|
161 |
|
@@ -265,21 +269,42 @@ if fetch_data:
|
|
265 |
|
266 |
# Metadata completeness analysis (enhanced)
|
267 |
st.subheader("Metadata Completeness Analysis")
|
|
|
268 |
completeness = metadata_df.map(lambda x: not is_incomplete(x)).mean() * 100
|
269 |
-
|
270 |
completeness_df = pd.DataFrame({
|
271 |
"Field": completeness.index,
|
272 |
"Completeness (%)": completeness.values
|
273 |
})
|
274 |
-
|
275 |
-
# β Add this line to create the table used in the sidebar:
|
276 |
completeness_table = completeness_df.set_index("Field")
|
|
|
|
|
277 |
|
278 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
279 |
fig = px.bar(completeness_df, x="Field", y="Completeness (%)", title="Metadata Completeness by Field")
|
280 |
st.plotly_chart(fig)
|
281 |
|
282 |
|
|
|
283 |
# Identify incomplete records
|
284 |
incomplete_mask = metadata_df.map(is_incomplete).any(axis=1)
|
285 |
incomplete_records = metadata_df[incomplete_mask]
|
|
|
126 |
# Create an empty placeholder for Quick Stats
|
127 |
stats_placeholder = st.sidebar.empty()
|
128 |
|
129 |
+
# Create placeholder for Field Completeness Breakdown
|
130 |
+
completeness_placeholder = st.sidebar.empty()
|
131 |
+
|
132 |
# Helpful Resources (styled and moved below dropdown)
|
133 |
st.sidebar.markdown("### Helpful Resources", unsafe_allow_html=True)
|
134 |
# Helpful Resources styled section
|
135 |
+
# 3. Helpful Resources Section (Fixed, under Completeness)
|
136 |
st.sidebar.markdown("""
|
137 |
+
<style>
|
138 |
+
.sidebar-section h3 {
|
139 |
+
color: lightgray !important;
|
140 |
+
font-size: 1.1rem !important;
|
141 |
+
margin-top: 1.5rem;
|
142 |
+
}
|
143 |
+
.sidebar-links a {
|
144 |
+
color: lightgray !important;
|
145 |
+
text-decoration: none !important;
|
146 |
+
}
|
147 |
+
.sidebar-links a:hover {
|
148 |
+
text-decoration: underline !important;
|
149 |
+
}
|
150 |
+
</style>
|
151 |
+
<div class="sidebar-section">
|
152 |
+
<h3>π Helpful Resources</h3>
|
153 |
+
<div class="sidebar-links">
|
154 |
+
<ul style='padding-left: 1em'>
|
155 |
+
<li><a href="https://www.loc.gov/apis/" target="_blank">LOC API Info</a></li>
|
156 |
+
<li><a href="https://www.loc.gov/" target="_blank">Library of Congress Homepage</a></li>
|
157 |
+
<li><a href="https://www.loc.gov/collections/" target="_blank">LOC Digital Collections</a></li>
|
158 |
+
<li><a href="https://www.loc.gov/marc/" target="_blank">MARC Metadata Standards</a></li>
|
159 |
+
<li><a href="https://labs.loc.gov/about-labs/digital-strategy/" target="_blank">LOC Digital Strategy</a></li>
|
160 |
+
</ul>
|
161 |
+
</div>
|
162 |
+
</div>
|
163 |
""", unsafe_allow_html=True)
|
164 |
|
165 |
|
|
|
269 |
|
270 |
# Metadata completeness analysis (enhanced)
|
271 |
st.subheader("Metadata Completeness Analysis")
|
272 |
+
# Create the completeness table
|
273 |
completeness = metadata_df.map(lambda x: not is_incomplete(x)).mean() * 100
|
|
|
274 |
completeness_df = pd.DataFrame({
|
275 |
"Field": completeness.index,
|
276 |
"Completeness (%)": completeness.values
|
277 |
})
|
|
|
|
|
278 |
completeness_table = completeness_df.set_index("Field")
|
279 |
+
|
280 |
+
# FILL THE PLACEHOLDER created earlier
|
281 |
|
282 |
+
with completeness_placeholder:
|
283 |
+
st.markdown("""
|
284 |
+
<div style='
|
285 |
+
background-color: #2e2e2e;
|
286 |
+
padding: 1.2rem;
|
287 |
+
border-radius: 10px;
|
288 |
+
margin-top: 1.5rem;
|
289 |
+
color: lightgray;
|
290 |
+
'>
|
291 |
+
<h4 style='margin-bottom: 1rem;'>π Field Completeness Breakdown</h4>
|
292 |
+
""", unsafe_allow_html=True)
|
293 |
+
|
294 |
+
st.dataframe(
|
295 |
+
completeness_table.style.background_gradient(cmap="Greens").format("{:.1f}%"),
|
296 |
+
use_container_width=True,
|
297 |
+
height=240
|
298 |
+
)
|
299 |
+
|
300 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
301 |
+
|
302 |
+
# Then continue plotting in main panel
|
303 |
fig = px.bar(completeness_df, x="Field", y="Completeness (%)", title="Metadata Completeness by Field")
|
304 |
st.plotly_chart(fig)
|
305 |
|
306 |
|
307 |
+
|
308 |
# Identify incomplete records
|
309 |
incomplete_mask = metadata_df.map(is_incomplete).any(axis=1)
|
310 |
incomplete_records = metadata_df[incomplete_mask]
|