-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
81 lines (63 loc) · 2.38 KB
/
app.py
File metadata and controls
81 lines (63 loc) · 2.38 KB
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
import logging
import os
import sys
from pathlib import Path
# before colour first import
os.environ["COLOUR_SCIENCE__DEFAULT_FLOAT_DTYPE"] = "float32"
# must be executed before cv2 first import
os.environ["OPENCV_IO_ENABLE_OPENEXR"] = "1"
# to enable on cloud but to disable locally
# os.environ["STCP_ENABLE_SIZE_LIMITATIONS"] = "1"
THIS_DIR = Path(__file__).parent
if THIS_DIR not in sys.path:
sys.path.append(str(THIS_DIR))
import colour.utilities
import psutil
import streamlit
import streamlit_colourplotting
APP_LOG_LEVEL_KEY = "APP_LOG_LEVEL"
def _configure_logging():
logging.basicConfig(
level=logging.INFO,
format="{levelname: <7} | {asctime} [{name: >30}]{message}",
style="{",
)
if APP_LOG_LEVEL_KEY not in streamlit.session_state:
APP_LOG_LEVEL = os.getenv("STCP_APP_LOG_LEVEL", "INFO").upper()
streamlit.session_state[APP_LOG_LEVEL_KEY] = APP_LOG_LEVEL
ROOT_LOGGER = logging.getLogger(streamlit_colourplotting.__name__)
ROOT_LOGGER.setLevel(streamlit.session_state[APP_LOG_LEVEL_KEY])
_configure_logging()
LOGGER = logging.getLogger("streamlit_colourplotting.app")
streamlit.set_page_config(
page_title="Colour-science Plotting",
page_icon="📊",
layout="centered",
initial_sidebar_state="expanded",
menu_items={
"Report a bug": "https://github.com/MrLixm/streamlit-colour-plotting/issues",
},
)
colour.utilities.filter_warnings(colour_usage_warnings=True, python_warnings=True)
# we create a first instance of the config at startup
streamlit_colourplotting.ui.config(force_instance=True)
streamlit_colourplotting.create_main_ui()
LOGGER.debug(
f"Final app RAM={psutil.Process(os.getpid()).memory_info().rss / 1024**2}MB"
)
@streamlit_colourplotting.widgetify
def widget_log_level(key):
log_level = streamlit.session_state[key]
streamlit.session_state[APP_LOG_LEVEL_KEY] = log_level
with streamlit.sidebar:
with streamlit.expander(" "):
streamlit.caption("Please do not modify options here :)")
_options = ["DEBUG", "INFO", "WARNING", "ERROR"]
streamlit.selectbox(
label="log level",
help="Only useful for the developer of the application.",
index=_options.index(streamlit.session_state[APP_LOG_LEVEL_KEY]),
options=_options,
key=str(widget_log_level),
on_change=widget_log_level,
)