File size: 4,881 Bytes
6a4662b
 
 
e97acf0
 
 
 
6a4662b
 
 
 
 
 
e97acf0
6a4662b
 
 
e97acf0
6a4662b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e97acf0
 
 
 
6a4662b
 
e97acf0
6a4662b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e97acf0
6a4662b
 
 
e97acf0
 
 
6a4662b
e97acf0
6a4662b
e97acf0
 
 
 
 
6a4662b
 
e97acf0
6a4662b
e97acf0
6a4662b
e97acf0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import numpy as np
import pandas as pd
import os
import json
import altair as alt
from pathlib import Path


class Dashboard:
    class Model:
        pageTitle = "Dashboard"

        documentsTitle = "Pages"
        documentsCount = "10.5K"
        documentsDelta = "125"

        annotationsTitle = "Documents"
        annotationsCount = "510"
        annotationsDelta = "-2"

        accuracyTitle = "Accuracy"
        accuracyCount = "87.9%"
        accuracyDelta = "0.1%"

        trainingTitle = "Training Time"
        trainingCount = "1.5 hrs"
        trainingDelta = "10 mins"

        processingTitle = "Processing Time"
        processingCount = "3 secs"
        processingDelta = "-0.1 secs"

        titleDataExtraction = "## Data Extraction"
        titleModelTraining = "## Model Training"
        titleDataAnnotation = "## Data Annotation"
        titleDocumentTypes = "## Document Types"

        status_file = "docs/status.json"
        annotation_files_dir = "docs/json"

    def view(self, model):
        # st.title(model.pageTitle)

        with st.container():
            col1, col2, col3, col4, col5 = st.columns(5)

            with col1:
                st.metric(label=model.documentsTitle, value=model.documentsCount, delta=model.documentsDelta)

            with col2:
                st.metric(label=model.annotationsTitle, value=model.annotationsCount, delta=model.annotationsDelta)

            with col3:
                st.metric(label=model.accuracyTitle, value=model.accuracyCount, delta=model.accuracyDelta)

            with col4:
                st.metric(label=model.trainingTitle, value=model.trainingCount, delta=model.trainingDelta, delta_color="inverse")

            with col5:
                st.metric(label=model.processingTitle, value=model.processingCount, delta=model.processingDelta, delta_color="inverse")

            st.markdown("---")


        with st.container():
            st.write(model.titleDataExtraction)
            chart_data = pd.DataFrame(
                np.random.randn(20, 3),
                columns=['a', 'b', 'c'])

            st.line_chart(chart_data)

        st.markdown("---")

        with st.container():
            col1, col2, col3 = st.columns(3)

            with col1:
                with st.container():
                    st.write(model.titleDataAnnotation)

                    total, completed, in_progress = self.calculate_annotation_stats(model)

                    source = pd.DataFrame({"Status": ["Completed", "In Progress"], "value": [completed, in_progress]})

                    c = alt.Chart(source).mark_arc(innerRadius=50).encode(
                        theta=alt.Theta(field="value", type="quantitative"),
                        color=alt.Color(field="Status", type="nominal"),
                    )
                    st.altair_chart(c, use_container_width=True)
            with col2:
                with st.container():
                    st.write(model.titleModelTraining)

                    source = pd.DataFrame({"Status": ["Running", "Failed", "Successful"], "value": [2, 10, 14]})

                    c = alt.Chart(source).mark_arc(innerRadius=50).encode(
                        theta=alt.Theta(field="value", type="quantitative"),
                        color=alt.Color(field="Status", type="nominal"),
                    )
                    st.altair_chart(c, use_container_width=True)
            with col3:
                with st.container():
                    st.write(model.titleDocumentTypes)

                    source = pd.DataFrame({"Types": ["Receipt", "Invoice", "General Form", "Claim"], "value": [22, 130, 5, 44]})

                    c = alt.Chart(source).mark_arc(innerRadius=50).encode(
                        theta=alt.Theta(field="value", type="quantitative"),
                        color=alt.Color(field="Types", type="nominal"),
                    )
                    st.altair_chart(c, use_container_width=True)


    def calculate_annotation_stats(self, model):
        completed = 0
        in_progress = 0
        data_dir_path = Path(model.annotation_files_dir)

        for file_name in data_dir_path.glob("*.json"):
            with open(file_name, "r") as f:
                data = json.load(f)
                v = data['meta']['version']
                if v == 'v0.1':
                    in_progress += 1
                else:
                    completed += 1
        total = completed + in_progress

        status_json = {
            "annotations": [
                {
                    "completed": completed,
                    "in_progress": in_progress,
                    "total": total
                }
            ]
        }

        with open(model.status_file, "w") as f:
            json.dump(status_json, f, indent=2)

        return total, completed, in_progress