Spaces:
Build error
Build error
File size: 1,702 Bytes
4398510 |
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 |
import streamlit as st
from ..form import form_controller
from typing import Dict, List, Union
from .options import PIPELINE_OPTIONS, CKIP_VISUALIZERS, CWN_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:
st.image(
"https://avatars.githubusercontent.com/u/21136511?s=200&v=4", 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}
active_visualizers = form_controller(
control="multi-select",
title="功能:",
options=visualizers[pipeline_options],
format_func=format_option,
)
return model_options, pipeline_options, active_visualizers
|