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