File size: 3,952 Bytes
519b419
 
 
 
 
74e2066
 
 
 
 
 
 
 
7068cae
74e2066
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
519b419
74e2066
 
 
519b419
 
74e2066
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c99444
74e2066
8c99444
74e2066
 
 
 
 
 
 
 
8c99444
74e2066
 
 
 
519b419
 
74e2066
 
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
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import streamlit as st

from n4a_analytics_lib.constants import DESCRIPTION

from n4a_analytics_lib.st_components import (check_login,
                                             init_session_statistics,
                                             init_session_iaa,
                                             display_data)



def n4a_analytics_dashboard() -> None:
    """Main function to manage dashboard app frontend
    -------------------------------------------------
    * General architecture:
    *
    *                            metrics_utils.py (collection of statistics calculation)
    *                                                     ↓
    *  project.py (features extraction from XMI) β†’ analytics.py
    *                             ↑               (project analyzer: computation/visualisation)
    *                             ↑                       ↓
    *      st_components.py (manage data input/output and pipelines with streamlit snippets)
    *                                        ↑ ↓
    *                               app.py (manage frontend)
    *
    ---------------------------------------------------
    """
    # Set window application
    st.set_page_config(layout="wide")

    # Sidebar: metadata, inputs etc.
    sidebar = st.sidebar
    # Cols: display results
    col1, col2 = st.columns(2)

    # Set general description
    sidebar.markdown(DESCRIPTION)

    # Level to analyze
    option = sidebar.selectbox('Which statistics level?', ('Inter-Annotator Agreement results',
                                                           'Global project statistics'))

    # IAA results view
    if option == "Inter-Annotator Agreement results":
        annotations = sidebar.file_uploader(
            "Upload IAA annotations (.zip format only): ",
            type='zip'
        )
        baseline_text = sidebar.file_uploader(
            "Upload baseline text (.txt format only): ",
            type='txt'
        )

        if baseline_text is not None and annotations is not None:
            init_session_iaa(data=annotations, baseline=baseline_text, col=col2)

    # Global statistics
    if option == "Global project statistics":
        # User input controllers
        mode = sidebar.radio("Choose mode to retrieve curated data: ", (
            "Local directory", "INCEpTION API Host remote"
        ))
        data = None
        if mode == "Local directory":
            project = sidebar.file_uploader(
                "Folder that contains curated annotations in XMI 1.1 (.zip format only): ",
                type="zip"
            )
            data = project
        if mode == "INCEpTION API Host remote":
            username = sidebar.text_input("Username: ")
            password = sidebar.text_input("Password: ", type='password')
            data = (username, password)

        # Validate inputs
        btn_process = sidebar.button('Process', key='process')

        # Access data with local ressources
        if btn_process and mode == "Local directory":
            if data is not None:
                # create a new session
                init_session_statistics(remote=False, local=True, data=data)

        # Access data with remote ressources
        if btn_process and mode == "INCEpTION API Host remote":
            if data is not None:
                if check_login(username=data[0], password=data[1]):
                    # create a new session
                    init_session_statistics(remote=True, local=False, data=data)
                else:
                    st.error("Username or Password is empty, please check and retry.")

        # Change data values and visualize new plot
        if "gs_obj" in st.session_state:
            if st.session_state["gs_local"] or st.session_state["gs_remote"]:
                display_data(col1)


if __name__ == "__main__":
    n4a_analytics_dashboard()