Update utils_layout.py
Browse files- utils_layout.py +79 -29
utils_layout.py
CHANGED
|
@@ -1,29 +1,79 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
logo
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# utils_layout.py
|
| 2 |
+
import os
|
| 3 |
+
import streamlit as st
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def _resolve_logo_path():
|
| 8 |
+
"""
|
| 9 |
+
Resolve automaticamente o caminho da logo:
|
| 10 |
+
1. Variável de ambiente LOGO_PATH (opcional, via Secrets)
|
| 11 |
+
2. logo.png na raiz
|
| 12 |
+
3. assets/logo.png
|
| 13 |
+
4. images/logo.png
|
| 14 |
+
5. static/logo.png
|
| 15 |
+
|
| 16 |
+
Retorna o caminho absoluto se existir, caso contrário None.
|
| 17 |
+
"""
|
| 18 |
+
candidates = []
|
| 19 |
+
|
| 20 |
+
# 1) Caminho definido via Secrets → LOGO_PATH
|
| 21 |
+
env_path = os.getenv("LOGO_PATH")
|
| 22 |
+
if env_path:
|
| 23 |
+
candidates.append(env_path)
|
| 24 |
+
|
| 25 |
+
# 2) Candidatos fixos
|
| 26 |
+
candidates += [
|
| 27 |
+
"logo.png",
|
| 28 |
+
os.path.join("assets", "logo.png"),
|
| 29 |
+
os.path.join("images", "logo.png"),
|
| 30 |
+
os.path.join("static", "logo.png"),
|
| 31 |
+
]
|
| 32 |
+
|
| 33 |
+
base = os.path.abspath(os.getcwd())
|
| 34 |
+
|
| 35 |
+
for p in candidates:
|
| 36 |
+
full = p if os.path.isabs(p) else os.path.join(base, p)
|
| 37 |
+
if os.path.exists(full):
|
| 38 |
+
return full
|
| 39 |
+
|
| 40 |
+
return None
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def exibir_logo(top=True, sidebar=True):
|
| 44 |
+
"""
|
| 45 |
+
Exibe a logo na parte superior (top) e/ou na sidebar.
|
| 46 |
+
Se a logo não existir, mostra texto fallback limpo sem quebrar a execução.
|
| 47 |
+
"""
|
| 48 |
+
logo_path = _resolve_logo_path()
|
| 49 |
+
|
| 50 |
+
if not logo_path:
|
| 51 |
+
# Fallback seguro
|
| 52 |
+
if top:
|
| 53 |
+
st.markdown("### IOI‑RUN")
|
| 54 |
+
if sidebar:
|
| 55 |
+
st.sidebar.markdown("### IOI‑RUN")
|
| 56 |
+
return
|
| 57 |
+
|
| 58 |
+
try:
|
| 59 |
+
logo = Image.open(logo_path)
|
| 60 |
+
except Exception as e:
|
| 61 |
+
if top:
|
| 62 |
+
st.markdown(f"### IOI‑RUN (logo indisponível: {e})")
|
| 63 |
+
if sidebar:
|
| 64 |
+
st.sidebar.markdown("### IOI‑RUN")
|
| 65 |
+
return
|
| 66 |
+
|
| 67 |
+
# -----------------------
|
| 68 |
+
# LOGO NO TOPO (CENTRADA)
|
| 69 |
+
# -----------------------
|
| 70 |
+
if top:
|
| 71 |
+
col1, col2, col3 = st.columns([2, 3, 2])
|
| 72 |
+
with col2:
|
| 73 |
+
st.image(logo, use_column_width=True)
|
| 74 |
+
|
| 75 |
+
# -----------------------
|
| 76 |
+
# LOGO NO SIDEBAR
|
| 77 |
+
# -----------------------
|
| 78 |
+
if sidebar:
|
| 79 |
+
st.sidebar.image(logo, use_column_width=True)
|