Spaces:
Sleeping
Sleeping
abraham9486937737 commited on
Commit ·
68ff299
1
Parent(s): 819cf2c
Improve logo loading with PIL Image
Browse files- streamlit_app/app.py +22 -8
streamlit_app/app.py
CHANGED
|
@@ -245,33 +245,47 @@ def load_kpi_summary():
|
|
| 245 |
with st.sidebar:
|
| 246 |
# Display logo
|
| 247 |
try:
|
|
|
|
|
|
|
| 248 |
logo_candidates = [
|
| 249 |
-
Path(
|
| 250 |
-
Path(
|
| 251 |
-
Path.cwd() / "mypace-logo.png",
|
| 252 |
]
|
|
|
|
|
|
|
| 253 |
for parent in Path(__file__).resolve().parents:
|
| 254 |
logo_candidates.append(parent / "mypace-logo.png")
|
| 255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
if logo_path:
|
| 257 |
try:
|
| 258 |
-
|
| 259 |
-
except Exception:
|
| 260 |
-
from PIL import Image
|
| 261 |
logo_img = Image.open(logo_path)
|
| 262 |
st.image(logo_img, use_container_width=True)
|
|
|
|
|
|
|
|
|
|
| 263 |
else:
|
| 264 |
-
#
|
| 265 |
hf_logo_url = "https://huggingface.co/spaces/abrahamcbe/myspace-ooty-analytics/resolve/main/mypace-logo.png"
|
| 266 |
try:
|
| 267 |
st.image(hf_logo_url, use_container_width=True)
|
| 268 |
except Exception:
|
|
|
|
| 269 |
try:
|
| 270 |
logo_b64 = "".join(LOGO_B64.split())
|
| 271 |
st.image(f"data:image/png;base64,{logo_b64}", use_container_width=True)
|
| 272 |
except Exception:
|
| 273 |
st.markdown("<h1 style='text-align: center; font-size: 80px;'>🏨</h1>", unsafe_allow_html=True)
|
| 274 |
except Exception as e:
|
|
|
|
| 275 |
st.markdown("<h1 style='text-align: center; font-size: 80px;'>🏨</h1>", unsafe_allow_html=True)
|
| 276 |
|
| 277 |
st.title("🏨 MySpace Ooty Holiday Inn")
|
|
|
|
| 245 |
with st.sidebar:
|
| 246 |
# Display logo
|
| 247 |
try:
|
| 248 |
+
from PIL import Image
|
| 249 |
+
|
| 250 |
logo_candidates = [
|
| 251 |
+
Path(__file__).parent / "mypace-logo.png", # streamlit_app/mypace-logo.png
|
| 252 |
+
Path(project_root) / "mypace-logo.png", # root/mypace-logo.png
|
| 253 |
+
Path.cwd() / "mypace-logo.png", # cwd/mypace-logo.png
|
| 254 |
]
|
| 255 |
+
|
| 256 |
+
# Add all parent directories
|
| 257 |
for parent in Path(__file__).resolve().parents:
|
| 258 |
logo_candidates.append(parent / "mypace-logo.png")
|
| 259 |
+
|
| 260 |
+
# Try to find and load the logo
|
| 261 |
+
logo_path = None
|
| 262 |
+
for candidate in logo_candidates:
|
| 263 |
+
if candidate.exists():
|
| 264 |
+
logo_path = candidate
|
| 265 |
+
break
|
| 266 |
+
|
| 267 |
if logo_path:
|
| 268 |
try:
|
| 269 |
+
# Use PIL to open and display the image
|
|
|
|
|
|
|
| 270 |
logo_img = Image.open(logo_path)
|
| 271 |
st.image(logo_img, use_container_width=True)
|
| 272 |
+
except Exception as e:
|
| 273 |
+
# Fallback to string path
|
| 274 |
+
st.image(str(logo_path), use_container_width=True)
|
| 275 |
else:
|
| 276 |
+
# File not found, try URL
|
| 277 |
hf_logo_url = "https://huggingface.co/spaces/abrahamcbe/myspace-ooty-analytics/resolve/main/mypace-logo.png"
|
| 278 |
try:
|
| 279 |
st.image(hf_logo_url, use_container_width=True)
|
| 280 |
except Exception:
|
| 281 |
+
# Use base64 embedded image
|
| 282 |
try:
|
| 283 |
logo_b64 = "".join(LOGO_B64.split())
|
| 284 |
st.image(f"data:image/png;base64,{logo_b64}", use_container_width=True)
|
| 285 |
except Exception:
|
| 286 |
st.markdown("<h1 style='text-align: center; font-size: 80px;'>🏨</h1>", unsafe_allow_html=True)
|
| 287 |
except Exception as e:
|
| 288 |
+
# Last resort: emoji
|
| 289 |
st.markdown("<h1 style='text-align: center; font-size: 80px;'>🏨</h1>", unsafe_allow_html=True)
|
| 290 |
|
| 291 |
st.title("🏨 MySpace Ooty Holiday Inn")
|