File size: 6,833 Bytes
6a4662b
 
 
 
 
 
 
 
 
486e73d
e97acf0
486e73d
6a4662b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
486e73d
 
 
e97acf0
6a4662b
 
 
 
 
 
486e73d
 
 
e97acf0
6a4662b
 
 
 
 
486e73d
 
6a4662b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
486e73d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6a4662b
 
 
486e73d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6a4662b
 
 
486e73d
e97acf0
 
 
6a4662b
 
 
 
 
 
 
 
486e73d
6a4662b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import streamlit as st
from streamlit_option_menu import option_menu
from tools.utilities import load_css
import json

from views.dashboard import Dashboard
from views.data_annotation import DataAnnotation
from views.model_training import ModelTraining
from views.model_tuning import ModelTuning
from views.data_inference import DataInference
from views.setup import Setup
from views.data_review import DataReview
from views.about import About

import streamlit_javascript as st_js

st.set_page_config(
    page_title="Sparrow",
    page_icon="favicon.ico",
    layout="wide"
)

load_css()


class Model:
    menuTitle = "Sparrow"
    option1 = "Dashboard"
    option2 = "Data Annotation"
    option3 = "Model Training"
    option4 = "Model Tuning"
    option5 = "Inference"
    option6 = "Data Review"
    option7 = "Setup"
    option8 = "About"

    menuIcon = "menu-up"
    icon1 = "speedometer"
    icon2 = "activity"
    icon3 = "motherboard"
    icon4 = "graph-up-arrow"
    icon5 = "journal-arrow-down"
    icon6 = "droplet"
    icon7 = "clipboard-data"
    icon8 = "chat"


def view(model):
    with st.sidebar:
        menuItem = option_menu(model.menuTitle,
                               [model.option1, model.option2, model.option5, model.option6, model.option7, model.option8],
                               icons=[model.icon1, model.icon2, model.icon5, model.icon6, model.icon7, model.icon8],
                               menu_icon=model.menuIcon,
                               default_index=0,
                               styles={
                                   "container": {"padding": "5!important", "background-color": "#fafafa"},
                                   "icon": {"color": "black", "font-size": "25px"},
                                   "nav-link": {"font-size": "16px", "text-align": "left", "margin": "0px",
                                                "--hover-color": "#eee"},
                                   "nav-link-selected": {"background-color": "#037ffc"},
                               })

    if menuItem == model.option1:
        Dashboard().view(Dashboard.Model())
        logout_widget()

    if menuItem == model.option2:
        if 'ui_width' not in st.session_state or 'device_type' not in st.session_state or 'device_width' not in st.session_state:
            # Get UI width
            ui_width = st_js.st_javascript("window.innerWidth", key="ui_width_comp")
            device_width = st_js.st_javascript("window.screen.width", key="device_width_comp")

            if ui_width > 0 and device_width > 0:
                # Add 20% of current screen width to compensate for the sidebar
                ui_width = round(ui_width + (20 * ui_width / 100))

                if device_width > 768:
                    device_type = 'desktop'
                else:
                    device_type = 'mobile'

                st.session_state['ui_width'] = ui_width
                st.session_state['device_type'] = device_type
                st.session_state['device_width'] = device_width

                st.experimental_rerun()
        else:
            DataAnnotation().view(DataAnnotation.Model(), st.session_state['ui_width'], st.session_state['device_type'],
                                  st.session_state['device_width'])
        logout_widget()

    if menuItem == model.option3:
        ModelTraining().view(ModelTraining.Model())
        logout_widget()

    if menuItem == model.option4:
        ModelTuning().view(ModelTuning.Model())
        logout_widget()

    if menuItem == model.option5:
        if 'ui_width' not in st.session_state or 'device_type' not in st.session_state or 'device_width' not in st.session_state:
            # Get UI width
            ui_width = st_js.st_javascript("window.innerWidth", key="ui_width_comp")
            device_width = st_js.st_javascript("window.screen.width", key="device_width_comp")

            if ui_width > 0 and device_width > 0:
                # Add 20% of current screen width to compensate for the sidebar
                ui_width = round(ui_width + (20 * ui_width / 100))

                if device_width > 768:
                    device_type = 'desktop'
                else:
                    device_type = 'mobile'

                st.session_state['ui_width'] = ui_width
                st.session_state['device_type'] = device_type
                st.session_state['device_width'] = device_width

                st.experimental_rerun()
        else:
            DataInference().view(DataInference.Model(), st.session_state['ui_width'], st.session_state['device_type'],
                                 st.session_state['device_width'])

        logout_widget()

    if menuItem == model.option6:
        if 'ui_width' not in st.session_state or 'device_type' not in st.session_state or 'device_width' not in st.session_state:
            # Get UI width
            ui_width = st_js.st_javascript("window.innerWidth", key="ui_width_comp")
            device_width = st_js.st_javascript("window.screen.width", key="device_width_comp")

            if ui_width > 0 and device_width > 0:
                # Add 20% of current screen width to compensate for the sidebar
                ui_width = round(ui_width + (20 * ui_width / 100))

                if device_width > 768:
                    device_type = 'desktop'
                else:
                    device_type = 'mobile'

                st.session_state['ui_width'] = ui_width
                st.session_state['device_type'] = device_type
                st.session_state['device_width'] = device_width

                st.experimental_rerun()
        else:
            DataReview().view(DataReview.Model(), st.session_state['ui_width'], st.session_state['device_type'],
                              st.session_state['device_width'])

        logout_widget()

    if menuItem == model.option7:
        Setup().view(Setup.Model())
        logout_widget()

    if menuItem == model.option8:
        About().view(About.Model())
        logout_widget()


def logout_widget():
    with st.sidebar:
        st.markdown("---")
        # st.write("User:", "John Doe")
        st.write("Version:", "2.0.0")
        # st.button("Logout")
        # st.markdown("---")

        if 'visitors' not in st.session_state:
            with open("docs/visitors.json", "r") as f:
                visitors_json = json.load(f)
                visitors = visitors_json["meta"]["visitors"]

            visitors += 1
            visitors_json["meta"]["visitors"] = visitors

            with open("docs/visitors.json", "w") as f:
                json.dump(visitors_json, f)

            st.session_state['visitors'] = visitors
        else:
            visitors = st.session_state['visitors']

        st.write("Counter:", visitors)


view(Model())