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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Prep for streamlit run app_mlbee.py.
|
| 2 |
+
|
| 3 |
+
Based on app.py in lit-bee
|
| 4 |
+
|
| 5 |
+
https://docs.streamlit.io/knowledge-base/using-streamlit/hide-row-indices-displaying-dataframe
|
| 6 |
+
Hide row indices when displaying a dataframe
|
| 7 |
+
# CSS to inject contained in a string
|
| 8 |
+
hide_table_row_index = '''
|
| 9 |
+
<style>
|
| 10 |
+
tbody th {display:none}
|
| 11 |
+
.blank {display:none}
|
| 12 |
+
</style>
|
| 13 |
+
'''
|
| 14 |
+
# Inject CSS with Markdown
|
| 15 |
+
st.markdown(hide_table_row_index, unsafe_allow_html=True)
|
| 16 |
+
|
| 17 |
+
# Display a static table
|
| 18 |
+
st.table(df)
|
| 19 |
+
|
| 20 |
+
# Hide row indices with st.dataframe
|
| 21 |
+
# CSS to inject contained in a string
|
| 22 |
+
hide_dataframe_row_index = '''
|
| 23 |
+
<style>
|
| 24 |
+
.row_heading.level0 {display:none}
|
| 25 |
+
.blank {display:none}
|
| 26 |
+
</style>
|
| 27 |
+
'''
|
| 28 |
+
# Inject CSS with Markdown
|
| 29 |
+
st.markdown(hide_dataframe_row_index, unsafe_allow_html=True)
|
| 30 |
+
|
| 31 |
+
# Display an interactive table
|
| 32 |
+
st.dataframe(df)
|
| 33 |
+
|
| 34 |
+
https://medium.com/@avra42/streamlit-python-cool-tricks-to-make-your-web-application-look-better-8abfc3763a5b
|
| 35 |
+
hide_menu_style = '''
|
| 36 |
+
<style>
|
| 37 |
+
#MainMenu {visibility: hidden; }
|
| 38 |
+
footer {visibility: hidden;}
|
| 39 |
+
</style>
|
| 40 |
+
'''
|
| 41 |
+
st.markdown(hide_menu_style, unsafe_allow_html=True)
|
| 42 |
+
"""
|
| 43 |
+
# pylint: disable=invalid-name
|
| 44 |
+
import os
|
| 45 |
+
import sys
|
| 46 |
+
import time
|
| 47 |
+
from pathlib import Path
|
| 48 |
+
from types import SimpleNamespace
|
| 49 |
+
from typing import Optional
|
| 50 |
+
|
| 51 |
+
import loguru
|
| 52 |
+
import logzero
|
| 53 |
+
import pandas as pd
|
| 54 |
+
|
| 55 |
+
import streamlit as st
|
| 56 |
+
from loguru import logger as loggu
|
| 57 |
+
from logzero import logger
|
| 58 |
+
from set_loglevel import set_loglevel
|
| 59 |
+
from streamlit import session_state as state
|
| 60 |
+
|
| 61 |
+
from st_mlbee import __version__
|
| 62 |
+
from st_mlbee.utils import menu_items
|
| 63 |
+
from st_mlbee.multipage import Multipage
|
| 64 |
+
|
| 65 |
+
from st_mlbee.home import home
|
| 66 |
+
from st_mlbee.settings import settings
|
| 67 |
+
from st_mlbee.info import info
|
| 68 |
+
from st_mlbee.utils import style_css
|
| 69 |
+
|
| 70 |
+
# curr_py = sys.version[:3]
|
| 71 |
+
# msg = f"Some packages st-mlbee depends on can only run with Python 3.8, current python is **{curr_py}**, sorry..."
|
| 72 |
+
# assert curr_py == "3.8", msg
|
| 73 |
+
|
| 74 |
+
os.environ["TZ"] = "Asia/Shanghai"
|
| 75 |
+
try:
|
| 76 |
+
time.tzset() # type: ignore
|
| 77 |
+
except Exception as _:
|
| 78 |
+
logger.warning("time.tzset() error: %s. Probably running Windows, we let it pass.", _)
|
| 79 |
+
|
| 80 |
+
# uncomment this in dev oe set/export LOGLEVEL=10
|
| 81 |
+
# os.environ["LOGLEVEL"] = "10"
|
| 82 |
+
|
| 83 |
+
logzero.loglevel(set_loglevel())
|
| 84 |
+
|
| 85 |
+
loggu.remove()
|
| 86 |
+
_ = (
|
| 87 |
+
"<green>{time:YY-MM-DD HH:mm:ss}</green> | "
|
| 88 |
+
"<level>{level: <5}</level> | <level>{message}</level> "
|
| 89 |
+
"<cyan>{module}.{name}</cyan>:<cyan>{line}</cyan>"
|
| 90 |
+
)
|
| 91 |
+
loggu.add(
|
| 92 |
+
sys.stderr,
|
| 93 |
+
format=_,
|
| 94 |
+
level=set_loglevel(),
|
| 95 |
+
colorize=True,
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
# from PIL import Image
|
| 99 |
+
# page_icon=Image.open("icon.ico"),
|
| 100 |
+
st.set_page_config( # type: ignore
|
| 101 |
+
page_title=f"st-mlbee v{__version__}",
|
| 102 |
+
# page_icon="π§",
|
| 103 |
+
page_icon="π",
|
| 104 |
+
# layout="wide",
|
| 105 |
+
initial_sidebar_state="auto", # "auto" or "expanded" or "collapsed",
|
| 106 |
+
menu_items=menu_items,
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
# pd.set_option("precision", 2)
|
| 110 |
+
pd.set_option("display.precision", 2)
|
| 111 |
+
pd.options.display.float_format = "{:,.2f}".format
|
| 112 |
+
|
| 113 |
+
beetype = "mlbee"
|
| 114 |
+
sourcetype = "upload"
|
| 115 |
+
if set_loglevel() <= 10:
|
| 116 |
+
sourcetype = "urls"
|
| 117 |
+
|
| 118 |
+
_ = dict(
|
| 119 |
+
beetype=beetype,
|
| 120 |
+
sourcetype=sourcetype,
|
| 121 |
+
sourcecount=2,
|
| 122 |
+
sentali=None,
|
| 123 |
+
src_filename="",
|
| 124 |
+
tgt_filename="",
|
| 125 |
+
src_fileio=b"",
|
| 126 |
+
tgt_fileio=b"",
|
| 127 |
+
src_file="",
|
| 128 |
+
tgt_file="",
|
| 129 |
+
list1=[""],
|
| 130 |
+
list2=[""],
|
| 131 |
+
df=None,
|
| 132 |
+
df_a=None,
|
| 133 |
+
df_s_a=None,
|
| 134 |
+
count=1,
|
| 135 |
+
updated=False,
|
| 136 |
+
)
|
| 137 |
+
if "ns" not in state:
|
| 138 |
+
state.ns = SimpleNamespace(**_)
|
| 139 |
+
|
| 140 |
+
try:
|
| 141 |
+
state.ns.list = [*_]
|
| 142 |
+
except Exception as exc:
|
| 143 |
+
logger.warning(exc)
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def main():
|
| 147 |
+
"""Bootstrap."""
|
| 148 |
+
# options()
|
| 149 |
+
|
| 150 |
+
st.markdown(f"<style>{style_css}</style>", unsafe_allow_html=True)
|
| 151 |
+
|
| 152 |
+
app = Multipage()
|
| 153 |
+
|
| 154 |
+
app.add_page("Home", "house", home)
|
| 155 |
+
# app.add_page("Settings", "gear", settings)
|
| 156 |
+
# app.add_page("Setup", "gear", settings)
|
| 157 |
+
app.add_page("Config", "gear", settings)
|
| 158 |
+
app.add_page("Info", "info", info)
|
| 159 |
+
|
| 160 |
+
app.run()
|
| 161 |
+
|
| 162 |
+
if set_loglevel() <= 10:
|
| 163 |
+
st.markdown(state.ns.count)
|
| 164 |
+
logger.debug(" run: %s", state.ns.count)
|
| 165 |
+
state.ns.count += 1
|
| 166 |
+
state.ns.updated = False
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
main()
|