File size: 2,420 Bytes
21e639d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import streamlit as st
from ..form import form_controller
from typing import Dict, List, Union
from .options import PIPELINE_OPTIONS, CKIP_VISUALIZERS, CWN_VISUALIZERS
# from .options import JEFF_VISUALIZERS


def remove_input_data():
    if "input_data" in st.session_state:
        del st.session_state["input_data"]


def format_option(option: Union[str, Dict[str, str]]) -> str:
    """The format_options function formats each option in a list of options.
    If `option` is a dict, the function will extract the value from the dict.

    Args:
        option (str or dict)
    Returns:
        a str
    """

    if isinstance(option, dict):
        return list(option.values())[0]

    return option


def visualize_side_bar(ckip_nlp_models: List[str]):
    with st.sidebar:
        cols = st.columns(1)
        cols[0].image(image=[
                "https://avatars.githubusercontent.com/u/21136511?s=200&v=4",
                "https://ckip.iis.sinica.edu.tw/files/ckip_logo.png",
                "https://cool.ntu.edu.tw/images/thumbnails/1026478/4b4hIhKX9yZPOlnar6J5c3LItwwDlj9FhCw1kRzc",
            ],
            width=100,
        )

        pipeline_options = form_controller(
            control="select-box",
            title="中文 NLP 管線處理:",
            options=PIPELINE_OPTIONS,
            on_change=remove_input_data,
        )

        model_options = None

        if pipeline_options == "CKIP":
            model_options = form_controller(
                control="select-box",
                title="NLP 模型:",
                options=ckip_nlp_models,
                key="model",
            )

        visualizers = {
            "CKIP": CKIP_VISUALIZERS, 
            "CWN": CWN_VISUALIZERS,
            # "JEFF": JEFF_VISUALIZERS,
        }

        active_visualizers = form_controller(
            control="multi-select",
            title="功能:",
            options=visualizers[pipeline_options],
            format_func=format_option,
        )
        
        st.markdown(
            "## 📝  TODO  😢  ##"'\n'
            "1. [ ] 自動爬文章  "'\n'
            "    (自動更新,登入問題?)"'\n'
            "2. [ ] 分析不同語意並 cluster"'\n'
            "3. [ ] 新的 NLP pipeline (用別的套件)"'\n'
            "4. [ ] 語音和多模態"'\n'
        )

        return model_options, pipeline_options, active_visualizers