Spaces:
Running
Running
revert visual document (streamlit deprications)
Browse files
src/ui_components/visual_documents.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
"""
|
| 2 |
Visual Document Display Components
|
| 3 |
-
|
| 4 |
UI components for displaying visual search results with enhanced metadata.
|
| 5 |
Includes saliency map visualization for tile-aware ColPali embeddings.
|
| 6 |
"""
|
|
@@ -185,6 +184,27 @@ def display_visual_document_details(
|
|
| 185 |
"""
|
| 186 |
st.markdown("### π Document Details")
|
| 187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
# Compute max score for normalization (display only)
|
| 189 |
all_scores = [getattr(doc, 'score', 0.0) for doc in sources]
|
| 190 |
max_score = max(all_scores) if all_scores else 1.0
|
|
@@ -366,7 +386,7 @@ def display_visual_document_details(
|
|
| 366 |
st.markdown("**π Original**")
|
| 367 |
if image_url and isinstance(image_url, str) and image_url.startswith('http'):
|
| 368 |
try:
|
| 369 |
-
st.image(image_url,
|
| 370 |
except Exception as e:
|
| 371 |
st.error(f"Failed to load image: {e}")
|
| 372 |
else:
|
|
@@ -478,7 +498,7 @@ def display_visual_document_details(
|
|
| 478 |
pass
|
| 479 |
|
| 480 |
if saliency_img:
|
| 481 |
-
st.image(saliency_img,
|
| 482 |
logger.info(f"β
Saliency map displayed for doc {i+1}")
|
| 483 |
else:
|
| 484 |
logger.warning(f"Saliency generation returned None for doc {i+1}")
|
|
@@ -492,7 +512,7 @@ def display_visual_document_details(
|
|
| 492 |
# Can't generate saliency - just show original image (full width)
|
| 493 |
if image_url and isinstance(image_url, str) and image_url.startswith('http'):
|
| 494 |
try:
|
| 495 |
-
st.image(image_url, width=
|
| 496 |
except Exception as e:
|
| 497 |
st.error(f"Failed to load image: {e}")
|
| 498 |
|
|
@@ -505,7 +525,7 @@ def display_visual_document_details(
|
|
| 505 |
elif show_images:
|
| 506 |
if image_url and isinstance(image_url, str) and image_url.startswith('http'):
|
| 507 |
try:
|
| 508 |
-
st.image(image_url, width=
|
| 509 |
except Exception as e:
|
| 510 |
st.error(f"Failed to load image: {e}")
|
| 511 |
else:
|
|
@@ -590,4 +610,3 @@ def display_visual_search_results(
|
|
| 590 |
|
| 591 |
if len(sources) > max_display:
|
| 592 |
st.info(f"π‘ {len(sources) - max_display} more results not shown")
|
| 593 |
-
|
|
|
|
| 1 |
"""
|
| 2 |
Visual Document Display Components
|
|
|
|
| 3 |
UI components for displaying visual search results with enhanced metadata.
|
| 4 |
Includes saliency map visualization for tile-aware ColPali embeddings.
|
| 5 |
"""
|
|
|
|
| 184 |
"""
|
| 185 |
st.markdown("### π Document Details")
|
| 186 |
|
| 187 |
+
# CSS to stabilize layout and prevent reflow loops on HF Spaces
|
| 188 |
+
# The key issues: proportional columns + responsive images = infinite resize loop
|
| 189 |
+
st.markdown("""
|
| 190 |
+
<style>
|
| 191 |
+
/* Stabilize image containers - fixed aspect ratio prevents reflow */
|
| 192 |
+
[data-testid="stImage"] {
|
| 193 |
+
min-height: 200px;
|
| 194 |
+
max-height: 600px;
|
| 195 |
+
}
|
| 196 |
+
/* Prevent column width oscillation */
|
| 197 |
+
[data-testid="column"] {
|
| 198 |
+
min-width: 0;
|
| 199 |
+
overflow: hidden;
|
| 200 |
+
}
|
| 201 |
+
/* Stabilize expander content */
|
| 202 |
+
[data-testid="stExpander"] > div {
|
| 203 |
+
overflow: hidden;
|
| 204 |
+
}
|
| 205 |
+
</style>
|
| 206 |
+
""", unsafe_allow_html=True)
|
| 207 |
+
|
| 208 |
# Compute max score for normalization (display only)
|
| 209 |
all_scores = [getattr(doc, 'score', 0.0) for doc in sources]
|
| 210 |
max_score = max(all_scores) if all_scores else 1.0
|
|
|
|
| 386 |
st.markdown("**π Original**")
|
| 387 |
if image_url and isinstance(image_url, str) and image_url.startswith('http'):
|
| 388 |
try:
|
| 389 |
+
st.image(image_url, width=599, caption=f"Page {page_number}")
|
| 390 |
except Exception as e:
|
| 391 |
st.error(f"Failed to load image: {e}")
|
| 392 |
else:
|
|
|
|
| 498 |
pass
|
| 499 |
|
| 500 |
if saliency_img:
|
| 501 |
+
st.image(saliency_img, width=599, caption=f"Relevance heatmap")
|
| 502 |
logger.info(f"β
Saliency map displayed for doc {i+1}")
|
| 503 |
else:
|
| 504 |
logger.warning(f"Saliency generation returned None for doc {i+1}")
|
|
|
|
| 512 |
# Can't generate saliency - just show original image (full width)
|
| 513 |
if image_url and isinstance(image_url, str) and image_url.startswith('http'):
|
| 514 |
try:
|
| 515 |
+
st.image(image_url, width=599, caption=f"Page {page_number}")
|
| 516 |
except Exception as e:
|
| 517 |
st.error(f"Failed to load image: {e}")
|
| 518 |
|
|
|
|
| 525 |
elif show_images:
|
| 526 |
if image_url and isinstance(image_url, str) and image_url.startswith('http'):
|
| 527 |
try:
|
| 528 |
+
st.image(image_url, width=599, caption=f"Page {page_number}")
|
| 529 |
except Exception as e:
|
| 530 |
st.error(f"Failed to load image: {e}")
|
| 531 |
else:
|
|
|
|
| 610 |
|
| 611 |
if len(sources) > max_display:
|
| 612 |
st.info(f"π‘ {len(sources) - max_display} more results not shown")
|
|
|