freemt
commited on
Commit
Β·
9f4179f
1
Parent(s):
e4a3eb9
Update streamlit.cli
Browse files- .stignore +1 -1
- README1.md +14 -7
- litbee/__main__.py +5 -32
- litbee/__main__.py- +33 -0
- litbee/app.py +136 -0
- run1.sh +1 -0
.stignore
CHANGED
@@ -11,7 +11,7 @@ __pycache__
|
|
11 |
.Python
|
12 |
build
|
13 |
develop-eggs
|
14 |
-
dist
|
15 |
downloads
|
16 |
eggs
|
17 |
.eggs
|
|
|
11 |
.Python
|
12 |
build
|
13 |
develop-eggs
|
14 |
+
# dist
|
15 |
downloads
|
16 |
eggs
|
17 |
.eggs
|
README1.md
CHANGED
@@ -3,17 +3,23 @@
|
|
3 |
|
4 |
litbee (currently with ezbee, dzbee and debee), made with streamlit
|
5 |
|
6 |
-
## clone repo
|
7 |
-
```
|
8 |
-
git clone https://github.com/ffreemt/litbee
|
9 |
-
cd litbee
|
10 |
-
```
|
11 |
-
|
12 |
## Pre-install
|
13 |
Python 3.8 only
|
14 |
|
15 |
`pyicu`, `pycld2` and `fasttext`: refer to `debee`'s pre-install [https://github.com/ffreemt/debee/blob/main/README.md](https://github.com/ffreemt/debee/blob/main/README.md)
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
## Install it
|
18 |
```shell
|
19 |
poetry install
|
@@ -25,5 +31,6 @@ poetry install
|
|
25 |
```bash
|
26 |
python -m streamlit run app.py
|
27 |
|
28 |
-
# streamlit run app.py
|
|
|
29 |
```
|
|
|
3 |
|
4 |
litbee (currently with ezbee, dzbee and debee), made with streamlit
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
## Pre-install
|
7 |
Python 3.8 only
|
8 |
|
9 |
`pyicu`, `pycld2` and `fasttext`: refer to `debee`'s pre-install [https://github.com/ffreemt/debee/blob/main/README.md](https://github.com/ffreemt/debee/blob/main/README.md)
|
10 |
|
11 |
+
## via pip
|
12 |
+
```bash
|
13 |
+
pip install litbee
|
14 |
+
python -m litbee
|
15 |
+
```
|
16 |
+
|
17 |
+
## Or via git clone
|
18 |
+
```
|
19 |
+
git clone https://github.com/ffreemt/litbee
|
20 |
+
cd litbee
|
21 |
+
```
|
22 |
+
|
23 |
## Install it
|
24 |
```shell
|
25 |
poetry install
|
|
|
31 |
```bash
|
32 |
python -m streamlit run app.py
|
33 |
|
34 |
+
# or streamlit run app.py
|
35 |
+
# or python -m litbee
|
36 |
```
|
litbee/__main__.py
CHANGED
@@ -1,33 +1,6 @@
|
|
1 |
-
"""
|
2 |
-
|
3 |
-
import
|
4 |
-
from pathlib import Path
|
5 |
-
from types import SimpleNamespace
|
6 |
-
from typing import Optional
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
from logzero import logger
|
11 |
-
from set_loglevel import set_loglevel
|
12 |
-
from streamlit import session_state as state
|
13 |
-
|
14 |
-
from litbee import __version__, litbee
|
15 |
-
from litbee.files2df import files2df
|
16 |
-
|
17 |
-
os.environ["TZ"] = "Asia/Shanghai"
|
18 |
-
os.environ["LOGLEVEL"] = "10"
|
19 |
-
logzero.loglevel(set_loglevel())
|
20 |
-
|
21 |
-
if "ns" not in state:
|
22 |
-
state.ns = SimpleNamespace()
|
23 |
-
|
24 |
-
|
25 |
-
def main():
|
26 |
-
logger.debug("state: %s", state)
|
27 |
-
|
28 |
-
df = files2df("data/test_en.txt", "data/test_zh.txt")
|
29 |
-
state.ns.df = df
|
30 |
-
logger.debug("state: %s", state)
|
31 |
-
|
32 |
-
|
33 |
-
main()
|
|
|
1 |
+
"""Run streamlit run app.py from __main__.py."""
|
2 |
+
import sys
|
3 |
+
from streamlit import cli
|
|
|
|
|
|
|
4 |
|
5 |
+
sys.argv = ["streamlit", "run", "app.py"]
|
6 |
+
sys.exit(cli.main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
litbee/__main__.py-
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Prep __main__.py."""
|
2 |
+
# pylint: disable=invalid-name
|
3 |
+
import os
|
4 |
+
from pathlib import Path
|
5 |
+
from types import SimpleNamespace
|
6 |
+
from typing import Optional
|
7 |
+
|
8 |
+
import logzero
|
9 |
+
import streamlit as st
|
10 |
+
from logzero import logger
|
11 |
+
from set_loglevel import set_loglevel
|
12 |
+
from streamlit import session_state as state
|
13 |
+
|
14 |
+
from litbee import __version__, litbee
|
15 |
+
from litbee.files2df import files2df
|
16 |
+
|
17 |
+
os.environ["TZ"] = "Asia/Shanghai"
|
18 |
+
os.environ["LOGLEVEL"] = "10"
|
19 |
+
logzero.loglevel(set_loglevel())
|
20 |
+
|
21 |
+
if "ns" not in state:
|
22 |
+
state.ns = SimpleNamespace()
|
23 |
+
|
24 |
+
|
25 |
+
def main():
|
26 |
+
logger.debug("state: %s", state)
|
27 |
+
|
28 |
+
df = files2df("data/test_en.txt", "data/test_zh.txt")
|
29 |
+
state.ns.df = df
|
30 |
+
logger.debug("state: %s", state)
|
31 |
+
|
32 |
+
|
33 |
+
main()
|
litbee/app.py
ADDED
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Prep __main__.py.
|
2 |
+
|
3 |
+
https://share.streamlit.io/deploy
|
4 |
+
Advanced settings...
|
5 |
+
Python version
|
6 |
+
3.7
|
7 |
+
3.8
|
8 |
+
3.9*
|
9 |
+
3.10
|
10 |
+
|
11 |
+
https://docs.streamlit.io/knowledge-base/using-streamlit/hide-row-indices-displaying-dataframe
|
12 |
+
Hide row indices when displaying a dataframe
|
13 |
+
# CSS to inject contained in a string
|
14 |
+
hide_table_row_index = '''
|
15 |
+
<style>
|
16 |
+
tbody th {display:none}
|
17 |
+
.blank {display:none}
|
18 |
+
</style>
|
19 |
+
'''
|
20 |
+
# Inject CSS with Markdown
|
21 |
+
st.markdown(hide_table_row_index, unsafe_allow_html=True)
|
22 |
+
|
23 |
+
# Display a static table
|
24 |
+
st.table(df)
|
25 |
+
|
26 |
+
# Hide row indices with st.dataframe
|
27 |
+
# CSS to inject contained in a string
|
28 |
+
hide_dataframe_row_index = '''
|
29 |
+
<style>
|
30 |
+
.row_heading.level0 {display:none}
|
31 |
+
.blank {display:none}
|
32 |
+
</style>
|
33 |
+
'''
|
34 |
+
# Inject CSS with Markdown
|
35 |
+
st.markdown(hide_dataframe_row_index, unsafe_allow_html=True)
|
36 |
+
|
37 |
+
# Display an interactive table
|
38 |
+
st.dataframe(df)
|
39 |
+
|
40 |
+
https://medium.com/@avra42/streamlit-python-cool-tricks-to-make-your-web-application-look-better-8abfc3763a5b
|
41 |
+
hide_menu_style = '''
|
42 |
+
<style>
|
43 |
+
#MainMenu {visibility: hidden; }
|
44 |
+
footer {visibility: hidden;}
|
45 |
+
</style>
|
46 |
+
'''
|
47 |
+
st.markdown(hide_menu_style, unsafe_allow_html=True)
|
48 |
+
|
49 |
+
"""
|
50 |
+
# pylint: disable=invalid-name
|
51 |
+
import os
|
52 |
+
import sys
|
53 |
+
import time
|
54 |
+
from pathlib import Path
|
55 |
+
from types import SimpleNamespace
|
56 |
+
from typing import Optional
|
57 |
+
|
58 |
+
import loguru
|
59 |
+
import logzero
|
60 |
+
import pandas as pd
|
61 |
+
import streamlit as st
|
62 |
+
from loguru import logger as loggu
|
63 |
+
from logzero import logger
|
64 |
+
from set_loglevel import set_loglevel
|
65 |
+
from streamlit import session_state as state
|
66 |
+
|
67 |
+
from litbee import __version__, litbee
|
68 |
+
from litbee.options import options
|
69 |
+
|
70 |
+
# from litbee.files2df import files2df
|
71 |
+
# from litbee.utils import sb_front_cover, instructions, menu_items
|
72 |
+
# from litbee.ezbee_page import ezbee_page
|
73 |
+
# from litbee.dzbee_page import dzbee_page
|
74 |
+
# from litbee.xbee_page import xbee_page
|
75 |
+
from litbee.utils import menu_items
|
76 |
+
|
77 |
+
# from ezbee import ezbee
|
78 |
+
|
79 |
+
os.environ["TZ"] = "Asia/Shanghai"
|
80 |
+
time.tzset()
|
81 |
+
os.environ["LOGLEVEL"] = "10" # uncomment this in dev
|
82 |
+
logzero.loglevel(set_loglevel())
|
83 |
+
|
84 |
+
loggu.remove()
|
85 |
+
_ = (
|
86 |
+
"<green>{time:YY-MM-DD HH:mm:ss}</green> | "
|
87 |
+
"<level>{level: <5}</level> | <level>{message}</level> "
|
88 |
+
"<cyan>{name}</cyan>:<cyan>{line}</cyan>"
|
89 |
+
)
|
90 |
+
loggu.add(
|
91 |
+
sys.stderr,
|
92 |
+
format=_,
|
93 |
+
level=set_loglevel(),
|
94 |
+
colorize=True,
|
95 |
+
)
|
96 |
+
|
97 |
+
# from PIL import Image
|
98 |
+
# page_icon=Image.open("icon.ico"),
|
99 |
+
st.set_page_config(
|
100 |
+
page_title=f"litbee v{__version__}",
|
101 |
+
# page_icon="π§",
|
102 |
+
page_icon="π",
|
103 |
+
# layout="wide",
|
104 |
+
initial_sidebar_state="auto", # "auto" or "expanded" or "collapsed",
|
105 |
+
menu_items=menu_items,
|
106 |
+
)
|
107 |
+
|
108 |
+
# pd.set_option("precision", 2)
|
109 |
+
pd.set_option("display.precision", 2)
|
110 |
+
pd.options.display.float_format = "{:,.2f}".format
|
111 |
+
|
112 |
+
_ = dict(
|
113 |
+
beetype="ezbee",
|
114 |
+
src_filename="",
|
115 |
+
tgt_filename="",
|
116 |
+
src_fileio=b"",
|
117 |
+
tgt_fileio=b"",
|
118 |
+
src_file="",
|
119 |
+
tgt_file="",
|
120 |
+
list1=[""],
|
121 |
+
list2=[""],
|
122 |
+
df=None,
|
123 |
+
df_a=None,
|
124 |
+
df_s_a=None,
|
125 |
+
)
|
126 |
+
if "ns" not in state:
|
127 |
+
state.ns = SimpleNamespace(**_)
|
128 |
+
state.ns.list = [*_]
|
129 |
+
|
130 |
+
|
131 |
+
def main():
|
132 |
+
"""Bootstrap."""
|
133 |
+
options()
|
134 |
+
|
135 |
+
|
136 |
+
main()
|
run1.sh
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
python -c "from pathlib import Path; import debee; print(Path(debee.__name__).absolute())"
|