|
| 1 | +""" |
| 2 | +Copyright (c) 2024, 2025, Oracle and/or its affiliates. |
| 3 | +Licensed under the Universal Permissive License v1.0 as shown at http://oss.oracle.com/licenses/upl. |
| 4 | +""" |
| 5 | +# spell-checker:ignore streamlit, selectbox, mult, iloc, selectai, isin |
| 6 | + |
| 7 | +import streamlit as st |
| 8 | +import streamlit.components.v1 as components |
| 9 | + |
| 10 | +FOOTER_STYLE = """ |
| 11 | +<style> |
| 12 | + .footer-container, .footer { |
| 13 | + text-align: center !important; |
| 14 | + } |
| 15 | + .footer-container { |
| 16 | + padding-top: 0.5rem !important; |
| 17 | + } |
| 18 | + .footer { |
| 19 | + padding: 2rem 0 0.5rem 0 !important; |
| 20 | + } |
| 21 | + .footer-container p, .footer p { |
| 22 | + font-size: 12px !important; |
| 23 | + color: #8E8E93 !important; |
| 24 | + margin: 0 !important; |
| 25 | + padding: 0 !important; |
| 26 | + } |
| 27 | + .footer-container a, .footer a { |
| 28 | + color: #8E8E93 !important; |
| 29 | + text-decoration: underline !important; |
| 30 | + } |
| 31 | +</style> |
| 32 | +""" |
| 33 | + |
| 34 | +# --- SHARED LOGIC --- |
| 35 | +def _inject_footer(selector, insertion_method, footer_html, cleanup_styles=True): |
| 36 | + """ |
| 37 | + Shared footer injection logic with optional style cleanup. |
| 38 | + |
| 39 | + Args: |
| 40 | + selector: CSS selector to find the injection target |
| 41 | + insertion_method: 'afterend' or 'beforebegin' |
| 42 | + footer_html: Complete HTML content to inject |
| 43 | + cleanup_styles: Whether to apply padding/margin cleanup to target element |
| 44 | + """ |
| 45 | + js_safe_html = footer_html.replace("`", "\\`").replace("\n", "") |
| 46 | + cleanup_js = """ |
| 47 | + target.style.paddingBottom = '0'; |
| 48 | + target.style.marginBottom = '0';""" if cleanup_styles else "" |
| 49 | + js_code = f""" |
| 50 | + <script> |
| 51 | + const checkReady = setInterval(() => {{ |
| 52 | + const target = parent.document.querySelector('{selector}'); |
| 53 | + if (target && !parent.document.getElementById('page-footer')) {{ |
| 54 | + clearInterval(checkReady); |
| 55 | + {cleanup_js} |
| 56 | + target.insertAdjacentHTML('{insertion_method}', `{js_safe_html}`); |
| 57 | + }} |
| 58 | + }}, 100); |
| 59 | + setTimeout(() => clearInterval(checkReady), 3000); |
| 60 | + </script> |
| 61 | + """ |
| 62 | + components.html(js_code, height=0) |
| 63 | + |
| 64 | + |
| 65 | +# --- FUNCTION 1: The Cleanup Crew --- |
| 66 | +def remove_footer(): |
| 67 | + """ |
| 68 | + Injects simple JavaScript to find and remove any existing footer. |
| 69 | + This MUST be called at the TOP of every page in your app. |
| 70 | + """ |
| 71 | + js_code = """ |
| 72 | + <script> |
| 73 | + const footer = parent.document.getElementById('page-footer'); |
| 74 | + if (footer) { |
| 75 | + footer.remove(); |
| 76 | + } |
| 77 | + </script> |
| 78 | + """ |
| 79 | + components.html(js_code, height=0) |
| 80 | + |
| 81 | + |
| 82 | +# --- FUNCTION 2: The Chat Page Footer --- |
| 83 | +def render_chat_footer(): |
| 84 | + """ |
| 85 | + Standardized footer for chat pages. |
| 86 | + """ |
| 87 | + footer_html = f""" |
| 88 | + {FOOTER_STYLE} |
| 89 | + <div class="footer-container" id="page-footer"> |
| 90 | + <p>LLMs can make mistakes. Always verify important information.</p> |
| 91 | + </div> |
| 92 | + """ |
| 93 | + _inject_footer( |
| 94 | + selector='[data-testid="stBottomBlockContainer"]', |
| 95 | + insertion_method='afterend', |
| 96 | + footer_html=footer_html |
| 97 | + ) |
| 98 | + |
| 99 | + |
| 100 | +# --- FUNCTION 3: The Models Page Footer --- |
| 101 | +def render_models_footer(): |
| 102 | + """ |
| 103 | + Standardized footer for models pages. |
| 104 | + """ |
| 105 | + footer_html = f""" |
| 106 | + {FOOTER_STYLE} |
| 107 | + <div class="footer" id="page-footer"> |
| 108 | + <p>LLMs can make mistakes. Always verify important information.</p> |
| 109 | + </div> |
| 110 | + """ |
| 111 | + _inject_footer( |
| 112 | + selector='[data-testid="stAppIframeResizerAnchor"]', |
| 113 | + insertion_method='beforebegin', |
| 114 | + footer_html=footer_html, |
| 115 | + cleanup_styles=False |
| 116 | + ) |
0 commit comments