Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -454,8 +454,12 @@ if fetch_data:
|
|
454 |
# --- Suggested Metadata Enhancements Section ---
|
455 |
st.subheader("Suggested Metadata Enhancements")
|
456 |
|
457 |
-
#
|
458 |
-
|
|
|
|
|
|
|
|
|
459 |
|
460 |
# Check if records exist
|
461 |
incomplete_with_desc = metadata_df[
|
@@ -463,59 +467,75 @@ incomplete_with_desc = metadata_df[
|
|
463 |
(metadata_df['subject'].isnull())
|
464 |
]
|
465 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
466 |
if not incomplete_with_desc.empty:
|
467 |
if use_ai:
|
468 |
suggestions = []
|
469 |
records_to_process = min(10, len(incomplete_with_desc))
|
470 |
-
|
471 |
progress = st.progress(0)
|
472 |
status = st.empty()
|
473 |
-
|
474 |
for i, (idx, row) in enumerate(incomplete_with_desc.iterrows()):
|
475 |
if i >= records_to_process:
|
476 |
break
|
477 |
-
|
478 |
title = row['title'] if pd.notna(row['title']) else ""
|
479 |
description = row['description'] if pd.notna(row['description']) else ""
|
480 |
-
|
481 |
status.text(f"Analyzing {i+1}/{records_to_process}: {title[:30]}...")
|
482 |
-
|
483 |
suggested_subject = get_huggingface_suggestions(title, description)
|
484 |
-
|
485 |
if suggested_subject:
|
486 |
suggestions.append((title, suggested_subject))
|
487 |
-
|
488 |
progress.progress((i + 1) / records_to_process)
|
489 |
-
|
490 |
status.empty()
|
491 |
-
|
|
|
492 |
if suggestions:
|
493 |
suggestions_df = pd.DataFrame(suggestions, columns=["Title", "Suggested Subject"])
|
494 |
-
|
495 |
-
#
|
496 |
st.markdown("""
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
504 |
""", unsafe_allow_html=True)
|
505 |
-
|
506 |
-
#
|
507 |
st.table(suggestions_df.style
|
508 |
-
.background_gradient(cmap="Greens", subset=["Suggested Subject"])
|
|
|
509 |
.hide(axis="index")
|
|
|
510 |
)
|
511 |
-
|
512 |
-
st.markdown("</div>", unsafe_allow_html=True)
|
513 |
-
|
514 |
else:
|
515 |
st.info("No metadata enhancement suggestions available.")
|
516 |
-
|
517 |
else:
|
518 |
st.info("Enable AI Suggestions to view recommendations.")
|
519 |
else:
|
520 |
st.success("All records already have subjects or no usable text available.")
|
521 |
|
|
|
|
|
|
454 |
# --- Suggested Metadata Enhancements Section ---
|
455 |
st.subheader("Suggested Metadata Enhancements")
|
456 |
|
457 |
+
# Create a row with checkbox for AI suggestions
|
458 |
+
col1, col2 = st.columns([1, 7])
|
459 |
+
with col1:
|
460 |
+
use_ai = st.checkbox("", value=True)
|
461 |
+
with col2:
|
462 |
+
st.markdown("🤖 Use AI Suggestions (Hugging Face)")
|
463 |
|
464 |
# Check if records exist
|
465 |
incomplete_with_desc = metadata_df[
|
|
|
467 |
(metadata_df['subject'].isnull())
|
468 |
]
|
469 |
|
470 |
+
# Create a consistent container for the results
|
471 |
+
st.markdown("""
|
472 |
+
<div style='
|
473 |
+
background-color: #1e1e1e;
|
474 |
+
border-radius: 10px;
|
475 |
+
padding: 1rem;
|
476 |
+
margin-top: 1rem;
|
477 |
+
'>
|
478 |
+
""", unsafe_allow_html=True)
|
479 |
+
|
480 |
if not incomplete_with_desc.empty:
|
481 |
if use_ai:
|
482 |
suggestions = []
|
483 |
records_to_process = min(10, len(incomplete_with_desc))
|
|
|
484 |
progress = st.progress(0)
|
485 |
status = st.empty()
|
486 |
+
|
487 |
for i, (idx, row) in enumerate(incomplete_with_desc.iterrows()):
|
488 |
if i >= records_to_process:
|
489 |
break
|
|
|
490 |
title = row['title'] if pd.notna(row['title']) else ""
|
491 |
description = row['description'] if pd.notna(row['description']) else ""
|
|
|
492 |
status.text(f"Analyzing {i+1}/{records_to_process}: {title[:30]}...")
|
|
|
493 |
suggested_subject = get_huggingface_suggestions(title, description)
|
|
|
494 |
if suggested_subject:
|
495 |
suggestions.append((title, suggested_subject))
|
|
|
496 |
progress.progress((i + 1) / records_to_process)
|
497 |
+
|
498 |
status.empty()
|
499 |
+
progress.empty()
|
500 |
+
|
501 |
if suggestions:
|
502 |
suggestions_df = pd.DataFrame(suggestions, columns=["Title", "Suggested Subject"])
|
503 |
+
|
504 |
+
# Apply custom CSS for table styling to match the others
|
505 |
st.markdown("""
|
506 |
+
<style>
|
507 |
+
table {
|
508 |
+
width: 100%;
|
509 |
+
border-collapse: collapse;
|
510 |
+
color: #e0e0e0;
|
511 |
+
}
|
512 |
+
thead tr {
|
513 |
+
border-bottom: 1px solid #444;
|
514 |
+
}
|
515 |
+
th, td {
|
516 |
+
padding: 12px;
|
517 |
+
text-align: left;
|
518 |
+
border-bottom: 1px solid #444;
|
519 |
+
}
|
520 |
+
tr:hover {
|
521 |
+
background-color: #2c2c2c;
|
522 |
+
}
|
523 |
+
</style>
|
524 |
""", unsafe_allow_html=True)
|
525 |
+
|
526 |
+
# Use st.table for consistent styling
|
527 |
st.table(suggestions_df.style
|
528 |
+
.background_gradient(cmap="Greens", subset=["Suggested Subject"], vmin=0, vmax=1)
|
529 |
+
.format({"Title": lambda x: x[:50] + "..." if len(x) > 50 else x})
|
530 |
.hide(axis="index")
|
531 |
+
.set_properties(**{'text-align': 'left'})
|
532 |
)
|
|
|
|
|
|
|
533 |
else:
|
534 |
st.info("No metadata enhancement suggestions available.")
|
|
|
535 |
else:
|
536 |
st.info("Enable AI Suggestions to view recommendations.")
|
537 |
else:
|
538 |
st.success("All records already have subjects or no usable text available.")
|
539 |
|
540 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
541 |
+
|