splitbill/annotation-tool
0
1import streamlit as st2from streamlit_option_menu import option_menu3from tools.utilities import load_css4import json5 6from views.dashboard import Dashboard7from views.data_annotation import DataAnnotation8from views.model_training import ModelTraining9from views.model_tuning import ModelTuning10from views.data_inference import DataInference11from views.setup import Setup12from views.data_review import DataReview13from views.about import About14 15import streamlit_javascript as st_js16 17st.set_page_config(page_title="Sparrow", page_icon="favicon.ico", layout="wide")18 19load_css()20 21 22class Model:23 menuTitle = "Sparrow"24 # option1 = "Dashboard"25 option2 = "Data Annotation"26 option3 = "Model Training"27 option4 = "Model Tuning"28 # option5 = "Inference"29 # option6 = "Data Review"30 option7 = "Setup"31 # option8 = "About"32 33 menuIcon = "menu-up"34 icon1 = "speedometer"35 icon2 = "activity"36 icon3 = "motherboard"37 icon4 = "graph-up-arrow"38 icon5 = "journal-arrow-down"39 icon6 = "droplet"40 icon7 = "clipboard-data"41 icon8 = "chat"42 43 44def view(model):45 with st.sidebar:46 menuItem = option_menu(47 model.menuTitle,48 [49 # model.option1,50 model.option2,51 # model.option5,52 # model.option6,53 model.option7,54 # model.option8,55 ],56 icons=[57 # model.icon1,58 model.icon2,59 # model.icon5,60 # model.icon6,61 model.icon7,62 # model.icon8,63 ],64 menu_icon=model.menuIcon,65 default_index=0,66 styles={67 "container": {"padding": "5!important", "background-color": "#fafafa"},68 "icon": {"color": "black", "font-size": "25px"},69 "nav-link": {70 "font-size": "16px",71 "text-align": "left",72 "margin": "0px",73 "--hover-color": "#eee",74 },75 "nav-link-selected": {"background-color": "#037ffc"},76 },77 )78 79 # if menuItem == model.option1:80 # Dashboard().view(Dashboard.Model())81 # logout_widget()82 83 if menuItem == model.option2:84 if (85 "ui_width" not in st.session_state86 or "device_type" not in st.session_state87 or "device_width" not in st.session_state88 ):89 # Get UI width90 ui_width = st_js.st_javascript("window.innerWidth", key="ui_width_comp")91 device_width = st_js.st_javascript(92 "window.screen.width", key="device_width_comp"93 )94 95 if ui_width > 0 and device_width > 0:96 # Add 20% of current screen width to compensate for the sidebar97 ui_width = round(ui_width + (20 * ui_width / 100))98 99 if device_width > 768:100 device_type = "desktop"101 else:102 device_type = "mobile"103 104 st.session_state["ui_width"] = ui_width105 st.session_state["device_type"] = device_type106 st.session_state["device_width"] = device_width107 108 st.experimental_rerun()109 else:110 DataAnnotation().view(111 DataAnnotation.Model(),112 st.session_state["ui_width"],113 st.session_state["device_type"],114 st.session_state["device_width"],115 )116 logout_widget()117 118 if menuItem == model.option3:119 ModelTraining().view(ModelTraining.Model())120 logout_widget()121 122 if menuItem == model.option4:123 ModelTuning().view(ModelTuning.Model())124 logout_widget()125 126 # if menuItem == model.option5:127 # if (128 # "ui_width" not in st.session_state129 # or "device_type" not in st.session_state130 # or "device_width" not in st.session_state131 # ):132 # # Get UI width133 # ui_width = st_js.st_javascript("window.innerWidth", key="ui_width_comp")134 # device_width = st_js.st_javascript(135 # "window.screen.width", key="device_width_comp"136 # )137 138 # if ui_width > 0 and device_width > 0:139 # # Add 20% of current screen width to compensate for the sidebar140 # ui_width = round(ui_width + (20 * ui_width / 100))141 142 # if device_width > 768:143 # device_type = "desktop"144 # else:145 # device_type = "mobile"146 147 # st.session_state["ui_width"] = ui_width148 # st.session_state["device_type"] = device_type149 # st.session_state["device_width"] = device_width150 151 # st.experimental_rerun()152 # else:153 # DataInference().view(154 # DataInference.Model(),155 # st.session_state["ui_width"],156 # st.session_state["device_type"],157 # st.session_state["device_width"],158 # )159 160 # logout_widget()161 162 # if menuItem == model.option6:163 # if (164 # "ui_width" not in st.session_state165 # or "device_type" not in st.session_state166 # or "device_width" not in st.session_state167 # ):168 # # Get UI width169 # ui_width = st_js.st_javascript("window.innerWidth", key="ui_width_comp")170 # device_width = st_js.st_javascript(171 # "window.screen.width", key="device_width_comp"172 # )173 174 # if ui_width > 0 and device_width > 0:175 # # Add 20% of current screen width to compensate for the sidebar176 # ui_width = round(ui_width + (20 * ui_width / 100))177 178 # if device_width > 768:179 # device_type = "desktop"180 # else:181 # device_type = "mobile"182 183 # st.session_state["ui_width"] = ui_width184 # st.session_state["device_type"] = device_type185 # st.session_state["device_width"] = device_width186 187 # st.experimental_rerun()188 # else:189 # DataReview().view(190 # DataReview.Model(),191 # st.session_state["ui_width"],192 # st.session_state["device_type"],193 # st.session_state["device_width"],194 # )195 196 # logout_widget()197 198 if menuItem == model.option7:199 Setup().view(Setup.Model())200 logout_widget()201 202 # if menuItem == model.option8:203 # About().view(About.Model())204 # logout_widget()205 206 207def logout_widget():208 with st.sidebar:209 st.markdown("---")210 # st.write("User:", "John Doe")211 st.write("Version:", "2.0.0")212 # st.button("Logout")213 # st.markdown("---")214 215 if "visitors" not in st.session_state:216 with open("docs/visitors.json", "r") as f:217 visitors_json = json.load(f)218 visitors = visitors_json["meta"]["visitors"]219 220 visitors += 1221 visitors_json["meta"]["visitors"] = visitors222 223 with open("docs/visitors.json", "w") as f:224 json.dump(visitors_json, f)225 226 st.session_state["visitors"] = visitors227 else:228 visitors = st.session_state["visitors"]229 230 st.write("Counter:", visitors)231 232 233view(Model())234 