File size: 1,339 Bytes
f216a25 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
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 |