Spaces:
Sleeping
Sleeping
| #!/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() | |