Spaces:
Runtime error
Runtime error
| 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 | |