epitope / utils /loading.py
yunuk0's picture
Create loading.py
f216a25 verified
import streamlit as st
import base64
from pathlib import Path
def _img_to_base64(path: str) -> str:
"""둜컬 이미지 νŒŒμΌμ„ base64 λ¬Έμžμ—΄λ‘œ λ³€ν™˜"""
with open(path, "rb") as f:
return base64.b64encode(f.read()).decode()
def show_loading(
logo_path: str = "assets/team_icon.png",
size: int = 120,
height_vh: int = 60,
speed: float = 1.2,
):
"""
νšŒμ „ν•˜λŠ” λ‘œλ”© 둜고 ν‘œμ‹œ
Returns
-------
placeholder : st.empty()
loading.empty()둜 제거 κ°€λŠ₯
"""
# 경둜 μ•ˆμ •ν™” (pages/μ—μ„œλ„ λ™μΌν•˜κ²Œ λ™μž‘)
logo_path = Path(logo_path).as_posix()
logo_base64 = _img_to_base64(logo_path)
placeholder = st.empty()
placeholder.markdown(
f"""
<div style="
display:flex;
justify-content:center;
align-items:center;
height:{height_vh}vh;
">
<img
src="data:image/png;base64,{logo_base64}"
width="{size}"
style="animation: spin {speed}s linear infinite;"
/>
</div>
<style>
@keyframes spin {{
from {{ transform: rotate(0deg); }}
to {{ transform: rotate(360deg); }}
}}
</style>
""",
unsafe_allow_html=True,
)
return placeholder