freemt
commited on
Commit
Β·
4c2f391
1
Parent(s):
487e563
Fix fastlid.set_languages = ["de/en", "zh"]
Browse files- litbee/fetch_upload.py +20 -3
- main_example.py +0 -124
litbee/fetch_upload.py
CHANGED
@@ -12,6 +12,7 @@ import streamlit as st
|
|
12 |
from dzbee import dzbee
|
13 |
from ezbee import ezbee
|
14 |
from ezbee.gen_pairs import gen_pairs # aset2pairs?
|
|
|
15 |
from icecream import ic
|
16 |
from loguru import logger as loggu
|
17 |
from logzero import logger
|
@@ -53,11 +54,17 @@ def fetch_upload():
|
|
53 |
|
54 |
if src_fileio:
|
55 |
logger.debug(" type(src_fileio): %s", type(src_fileio))
|
|
|
|
|
56 |
if isinstance(src_fileio, list):
|
57 |
logger.debug(" len(src_fileio): %s", len(src_fileio))
|
58 |
-
logger.debug("src_fileio[-1].name: [%s]", src_fileio[-1].name)
|
59 |
-
filenames = [
|
60 |
-
|
|
|
|
|
|
|
|
|
61 |
|
62 |
# state.ns.src_fileio = src_fileio
|
63 |
state.ns.src_file = src_fileio[-1].getvalue().decode()
|
@@ -142,6 +149,16 @@ def fetch_upload():
|
|
142 |
|
143 |
logger.info("Processing data... %s", state.ns.beetype)
|
144 |
if state.ns.beetype in ["ezbee", "dzbee"]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
try:
|
146 |
# aset = ezbee(
|
147 |
aset = globals()[state.ns.beetype](
|
|
|
12 |
from dzbee import dzbee
|
13 |
from ezbee import ezbee
|
14 |
from ezbee.gen_pairs import gen_pairs # aset2pairs?
|
15 |
+
from fastlid import fastlid
|
16 |
from icecream import ic
|
17 |
from loguru import logger as loggu
|
18 |
from logzero import logger
|
|
|
54 |
|
55 |
if src_fileio:
|
56 |
logger.debug(" type(src_fileio): %s", type(src_fileio))
|
57 |
+
|
58 |
+
# for st.file_uploade accept_multiple_files=True
|
59 |
if isinstance(src_fileio, list):
|
60 |
logger.debug(" len(src_fileio): %s", len(src_fileio))
|
61 |
+
# logger.debug("src_fileio[-1].name: [%s]", src_fileio[-1].name)
|
62 |
+
filenames = []
|
63 |
+
try:
|
64 |
+
filenames = [elm.name for elm in src_fileio]
|
65 |
+
except Exception as exc:
|
66 |
+
logger.error(exc)
|
67 |
+
logger.debug("src_fileio names: *%s*", filenames) # type: ignore
|
68 |
|
69 |
# state.ns.src_fileio = src_fileio
|
70 |
state.ns.src_file = src_fileio[-1].getvalue().decode()
|
|
|
149 |
|
150 |
logger.info("Processing data... %s", state.ns.beetype)
|
151 |
if state.ns.beetype in ["ezbee", "dzbee"]:
|
152 |
+
# bug in json_de2zh.gen_cmat for dzbee and
|
153 |
+
# fast_scores.gen_cmat for ezbee
|
154 |
+
# temp fix:
|
155 |
+
if state.ns.beetype in ["dzbee"]:
|
156 |
+
fastlid.set_languages = ["de", "zh"]
|
157 |
+
elif state.ns.beetype in ["ezbee"]:
|
158 |
+
fastlid.set_languages = ["en", "zh"]
|
159 |
+
else:
|
160 |
+
fastlid.set_languages = None
|
161 |
+
|
162 |
try:
|
163 |
# aset = ezbee(
|
164 |
aset = globals()[state.ns.beetype](
|
main_example.py
DELETED
@@ -1,124 +0,0 @@
|
|
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 |
-
from pathlib import Path
|
54 |
-
from types import SimpleNamespace
|
55 |
-
from typing import Optional
|
56 |
-
|
57 |
-
import loguru
|
58 |
-
import logzero
|
59 |
-
import pandas as pd
|
60 |
-
import streamlit as st
|
61 |
-
from loguru import logger as loggu
|
62 |
-
from logzero import logger
|
63 |
-
from set_loglevel import set_loglevel
|
64 |
-
from streamlit import session_state as state
|
65 |
-
|
66 |
-
from litbee import __version__, litbee
|
67 |
-
from litbee.options import options
|
68 |
-
|
69 |
-
# from litbee.files2df import files2df
|
70 |
-
# from litbee.utils import sb_front_cover, instructions, menu_items
|
71 |
-
# from litbee.ezbee_page import ezbee_page
|
72 |
-
# from litbee.dzbee_page import dzbee_page
|
73 |
-
# from litbee.xbee_page import xbee_page
|
74 |
-
from litbee.utils import menu_items
|
75 |
-
|
76 |
-
# from ezbee import ezbee
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
os.environ["TZ"] = "Asia/Shanghai"
|
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 |
-
|
113 |
-
_ = dict(beetype="ezbee", src_filename="", tgt_filename="", src_fileio=b"", tgt_fileio=b"", src_file="", tgt_file="", list1=[], list2=[], df=None, df_a=None, df_s_a=None,)
|
114 |
-
if "ns" not in state:
|
115 |
-
state.ns = SimpleNamespace(**_)
|
116 |
-
state.ns.list = [*_]
|
117 |
-
|
118 |
-
|
119 |
-
def main():
|
120 |
-
"""Bootstrap."""
|
121 |
-
options()
|
122 |
-
|
123 |
-
|
124 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|