freemt commited on
Commit
aea5589
·
1 Parent(s): ca97d48

Update ezbee pypi added

Browse files
.stignore ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .git
2
+ # Byte-compiled / optimized / DLL files
3
+ __pycache__
4
+ *.py[cod]
5
+ *$py.class
6
+
7
+ # C extensions
8
+ *.so
9
+
10
+ # Distribution / packaging
11
+ .Python
12
+ build
13
+ develop-eggs
14
+ dist
15
+ downloads
16
+ eggs
17
+ .eggs
18
+ lib
19
+ lib64
20
+ parts
21
+ sdist
22
+ var
23
+ wheels
24
+ pip-wheel-metadata
25
+ share/python-wheels
26
+ *.egg-info
27
+ .installed.cfg
28
+ *.egg
29
+ MANIFEST
30
+
31
+ # PyInstaller
32
+ # Usually these files are written by a python script from a template
33
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
34
+ *.manifest
35
+ *.spec
36
+
37
+ # Installer logs
38
+ pip-log.txt
39
+ pip-delete-this-directory.txt
40
+
41
+ # Translations
42
+ *.mo
43
+ *.pot
44
+
45
+ # Django stuff:
46
+ *.log
47
+ local_settings.py
48
+ db.sqlite3
49
+
50
+ # Flask stuff:
51
+ instance
52
+ .webassets-cache
53
+
54
+ # Scrapy stuff:
55
+ .scrapy
56
+
57
+ # Sphinx documentation
58
+ docs/_build
59
+
60
+ # PyBuilder
61
+ target
62
+
63
+ # Jupyter Notebook
64
+ .ipynb_checkpoints
65
+
66
+ # IPython
67
+ profile_default
68
+ ipython_config.py
69
+
70
+ # pyenv
71
+ .python-version
72
+
73
+ # celery beat schedule file
74
+ celerybeat-schedule
75
+
76
+ # SageMath parsed files
77
+ *.sage.py
78
+
79
+ # Environments
80
+ .env
81
+ .venv
82
+ env
83
+ venv
84
+ ENV
85
+ env.bak
86
+ venv.bak
87
+
88
+ # Spyder project settings
89
+ .spyderproject
90
+ .spyproject
91
+
92
+ # Rope project settings
93
+ .ropeproject
94
+
95
+ # mypy
96
+ .mypy_cache
97
+ .dmypy.json
98
+ dmypy.json
99
+
100
+ # Pyre type checker
101
+ .pyre
app.py CHANGED
@@ -1,11 +1,82 @@
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
- from install import install
 
3
 
4
- # install("logzero")
5
  from logzero import logger
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- logger.info("streamlit version: %s", st.__version__)
8
 
9
- x = st.slider('Select a value')
10
- st.write(x, 'squared is', x * x)
11
- st.write(" streamlit version", st.__version__)
 
1
+ """Prep __main__.py."""
2
+ # pylint: disable=invalid-name
3
+ import os
4
+ from pathlib import Path
5
+ from typing import Optional
6
+
7
+ import pandas as pd
8
+
9
  import streamlit as st
10
+ from streamlit import session_state as state
11
+ from types import SimpleNamespace
12
 
13
+ import logzero
14
  from logzero import logger
15
+ from set_loglevel import set_loglevel
16
+
17
+ from litbee import __version__, litbee
18
+ from litbee.files2df import files2df
19
+ from litbee.utils import sb_front_cover, instructions, menu_items
20
+ from litbee.ezbee_page import ezbee_page
21
+ from litbee.dzbee_page import dzbee_page
22
+ from litbee.xbee_page import xbee_page
23
+
24
+ os.environ["TZ"] = "Asia/Shanghai"
25
+ os.environ["LOGLEVEL"] = "10"
26
+ logzero.loglevel(set_loglevel())
27
+
28
+ st.set_page_config(
29
+ page_title=f"litbee v{__version__}",
30
+ page_icon="🧊",
31
+ layout="wide",
32
+ initial_sidebar_state="auto", # "auto" or "expanded" or "collapsed",
33
+ menu_items=menu_items,
34
+ )
35
+
36
+ pd.set_option("precision", 2)
37
+ pd.options.display.float_format = "{:,.2f}".format
38
+
39
+
40
+ if "ns" not in state:
41
+ state.ns = SimpleNamespace()
42
+
43
+
44
+ def main():
45
+ # instructions()
46
+
47
+ sb_front_cover()
48
+
49
+ try:
50
+ _ = state.ns.df
51
+ state.ns.count += 1
52
+ logger.debug(" run: %s", state.ns.count)
53
+ except AttributeError:
54
+ logger.debug("first run")
55
+ # df = files2df("data/en.txt", "data/zh.txt")
56
+ df = files2df("data/test_en.txt", "data/test_zh.txt")
57
+ state.ns.count = 1
58
+ state.ns.df = df
59
+
60
+ # multi-page setup
61
+ menu = {
62
+ "ezbee": ezbee_page,
63
+ "dzbee": dzbee_page,
64
+ "xbee": xbee_page,
65
+ }
66
+ selection = st.sidebar.radio("", menu)
67
+ page = menu[selection]
68
+
69
+ # page.app()
70
+ page()
71
+
72
+ # 'items', 'keys', values, 'to_dict', 'update', 'values'
73
+ # logger.debug("state.ns: %s", state.ns)
74
+
75
+ st.write(f"run: {state.ns.count}")
76
+ # st.dataframe(state.ns.df)
77
+
78
+ # st.markdown(html_string, unsafe_allow_html=True)
79
+ # st.markdown(state.ns.df.to_html(), unsafe_allow_html=True)
80
 
 
81
 
82
+ main()
 
 
data/en.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ [Young Warrior] Kingold(...) 2021-12-30 22:27:37
2
+ It seems that the standalone version can
3
+ omit the GUI and specify the two files to be aligned directly on the command line.
4
+
5
+
6
+ But if it's not the GUI module that's taking up space, then
7
+ removing it won't help compress the size of the whole package.
8
+
data/test_en.txt ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Wuthering Heights
2
+
3
+
4
+ --------------------------------------------------------------------------------
5
+
6
+ Chapter 2
7
+
8
+ Chinese
9
+
10
+
11
+ Yesterday afternoon set in misty and cold. I had half a mind to spend it by my study fire, instead of wading through heath and mud to Wuthering Heights. On coming up from dinner, however (N.B. I dine between twelve and one o'clock; the housekeeper, a matronly lady, taken as a fixture along with the house, could not, or would not, comprehend my request that I might be served at five), on mounting the stairs with this lazy intention, and stepping into the room, I saw a servant girl on her knees surrounded by brushes and coal-scuttles, and raising an infernal dust as she extinguished the flames with heaps of cinders. This spectacle drove me back immediately; I took my hat, and, after a four-miles' walk, arrived at Heathcliff's garden gate just in time to escape the first feathery flakes of a snow shower.
12
+
13
+ On that bleak hill top the earth was hard with a black frost, and the air made me shiver through every limb. Being unable to remove the chain, I jumped over, and, running up the flagged causeway bordered with straggling gooseberry bushes, knocked vainly for admittance, till my knuckles tingled and the dogs howled.
14
+
15
+ `Wretched inmates!' I ejaculated mentally, `you deserve perpetual isolation from your species for your churlish inhospitality. At least, I would not keep my doors barred in the day time. I don't care--I will get in!' So resolved, I grasped the latch and shook it vehemently. Vinegar-faced Joseph projected his head from a round window of the barn.
16
+
17
+ `Whet are ye for?' he shouted. `T' maister's dahn i' t' fowld. Go rahnd by th' end ut' laith, if yah went tuh spake tull him.'
18
+
19
+ `Is there nobody inside to open the door?' I hallooed, responsively.
20
+
21
+ `They's nobbut t' missis; and shoo'll nut oppen't an ye mak yer flaysome dins till neeght.'
22
+
23
+ `Why? Cannot you tell her who I am, eh, Joseph?'
24
+
25
+ `Nor-ne me! Aw'll hae noa hend wi't,' muttered the head, vanishing.
26
+
27
+ The snow began to drive thickly. I seized the handle to essay another trial; when a young man without coat, and shouldering a pitchfork, appeared in the yard behind. He hailed me to follow him, and, after marching through a wash-house, and a paved area containing a coal shed, pump, and pigeon cot, we at length arrived in the huge, warm, cheerful apartment, where I was formerly received. It glowed delightfully in the radiance of an immense fire, compounded of coal, peat, and wood; and near the table, laid for a plentiful evening meal, I was pleased to observe the `missis', an individual whose existence I had never previously suspected. I bowed and waited, thinking she would bid me take a seat. She looked at me, leaning back in her chair, and remained motionless and mute.
28
+
29
+ `Rough weather!' I remarked. `I'm afraid, Mrs Heathcliff, the door must bear the consequence of your servants' leisure attendance: I had hard work to make them hear me.'
30
+
31
+ She never opened her mouth. I stared--she stared also: at any rate, she kept her eyes on me in a cool, regardless manner, exceedingly embarrassing and disagreeable.
32
+
33
+ `Sit down,' said the young man gruffly. `He'll be in soon.'
34
+
35
+ I obeyed; and hemmed, and called the villain Juno, who deigned, at this second interview, to move the extreme tip of her tail, in token of owning my acquaintance.
36
+
37
+ `A beautiful animal!' I commenced again. `Do you intend parting with the little ones, madam?'
38
+
39
+ `They are not mine,' said the amiable hostess, more repellingly than Heathcliff himself could have replied.
40
+
41
+ `Ah, your favourites are among these?' I continued, turning to an obscure cushion full of something like cats.
42
+
43
+ `A strange choice of favourites!' she observed scornfully.
44
+
45
+ Unluckily, it was a heap of dead rabbits. I hemmed once more, and drew closer to the hearth, repeating my comment on the wildness of the evening.
46
+
47
+ `You should not have come out,' she said, rising and reaching from the chimney-piece two of the painted canisters.
48
+
49
+ Her position before was sheltered from the light; now, I had a distinct view of her whole figure and countenance. She was slender, and apparently scarcely past girlhood: an admirable form, and the most exquisite little face that I have ever had the pleasure of beholding; small features, very fair; flaxen ringlets, or rather golden, hanging loose on her delicate neck; and eyes, had they been agreeable in expression, they would have been irresistible: fortunately for my susceptible heart, the only sentiment they evinced hovered between scorn, and a kind of desperation, singularly unnatural to be detected there. The canisters were almost out of her reach; I made a motion to aid her; she turned upon me as a miser might turn if anyone attempted to assist him in counting his gold.
50
+
51
+ `I don't want your help,' she snapped; `I can get them for myself.'
52
+
53
+ `I beg your pardon!' I hastened to reply.
54
+
55
+ `Were you asked to tea?' she demanded, tying an apron over her neat black frock, and standing with a spoonful of the leaf poised over the pot.
56
+
57
+ `I shall be glad to have a cup,' I answered.
58
+
59
+ `Were you asked?' she repeated.
60
+
61
+ `No,' I said, half smiling. `You are the proper person to ask me.'
62
+  
63
+
64
+
65
+ Contents PreviousChapter
66
+ NextChapter
67
+
68
+
69
+ Homepage
data/test_zh.txt ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ 返回首页
data/zh.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ 【少侠】Kingold(...) 2021-12-30 22:27:37
2
+ 单机版貌似可以省略掉图形界面,直接
3
+ 命令行指定两个待对齐文件。
4
+
5
+ 不过如果占地方的
6
+
7
+ 不是图形界面的模块,那去掉了也对压缩整个包的大小没帮助。
install-nodemon.sh ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
2
+ # source .bashrc
3
+ # nvm install node
4
+ # curl -sL https://deb.nodesource.com/setup_12.x | bash -
5
+ wget -c https://deb.nodesource.com/setup_12.x
6
+ bash setup_12.x
7
+
8
+ apt-get install -y nodejs
9
+ npm install -g npm@latest
10
+ npm install -g nodemon
install-poetry.sh ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # pip install pipx
2
+ # pipx install poetry
3
+ # pipx ensurepath
4
+ # source ~/.bashrc
5
+
6
+ # curl -sSL https://install.python-poetry.org | python3 -
7
+ # -C- continue -S show error -o output
8
+ curl -sSL -C- -o install-poetry.py https://install.python-poetry.org
9
+ python install-poetry.py
10
+ ~/.local/bin/poetry install
install-sw.sh ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # pip install pipx
2
+ # pipx install poetry
3
+ # pipx ensurepath
4
+ # source ~/.bashrc
5
+
6
+ # curl -sSL https://install.python-poetry.org | python3 -
7
+ # -C- continue -S show error -o output
8
+ curl -sSL -C- -o install-poetry.py https://install.python-poetry.org
9
+ python install-poetry.py
10
+ rm install-poetry.py
11
+ echo export PATH=~/.local/bin:$PATH > ~/.bashrc
12
+ source ~/.bashrc
13
+ # ~/.local/bin/poetry install
14
+
15
+ wget -c https://deb.nodesource.com/setup_12.x
16
+ bash setup_12.x
17
+ apt-get install -y nodejs
18
+ npm install -g npm@latest
19
+ npm install -g nodemon
20
+ rm setup_12.x
21
+
22
+ # apt upate # alerady done in apt-get install -y nodejs
23
+ apt install byobu -y > /dev/null 2>&1
24
+
litbee/__main__.py CHANGED
@@ -1,45 +1,32 @@
1
  """Prep __main__.py."""
2
  # pylint: disable=invalid-name
 
3
  from pathlib import Path
4
  from typing import Optional
5
 
 
 
 
 
6
  import logzero
7
- import typer
8
  from logzero import logger
9
  from set_loglevel import set_loglevel
10
 
11
  from litbee import __version__, litbee
 
12
 
 
 
13
  logzero.loglevel(set_loglevel())
14
 
15
- app = typer.Typer(
16
- name="litbee",
17
- add_completion=False,
18
- help="litbee help",
19
- )
20
-
21
-
22
- def _version_callback(value: bool) -> None:
23
- if value:
24
- typer.echo(f"{app.info.name} v.{__version__} -- ...")
25
- raise typer.Exit()
26
-
27
-
28
- @app.command()
29
- def main(
30
- version: Optional[bool] = typer.Option( # pylint: disable=(unused-argument
31
- None,
32
- "--version",
33
- "-v",
34
- "-V",
35
- help="Show version info and exit.",
36
- callback=_version_callback,
37
- is_eager=True,
38
- ),
39
- ):
40
- """Define."""
41
- ...
42
-
43
-
44
- if __name__ == "__main__":
45
- app()
 
1
  """Prep __main__.py."""
2
  # pylint: disable=invalid-name
3
+ import os
4
  from pathlib import Path
5
  from typing import Optional
6
 
7
+ import streamlit as st
8
+ from streamlit import session_state as state
9
+ from types import SimpleNamespace
10
+
11
  import logzero
 
12
  from logzero import logger
13
  from set_loglevel import set_loglevel
14
 
15
  from litbee import __version__, litbee
16
+ from litbee.files2df import files2df
17
 
18
+ os.environ["TZ"] = "Asia/Shanghai"
19
+ os.environ["LOGLEVEL"] = "10"
20
  logzero.loglevel(set_loglevel())
21
 
22
+ if "ns" not in state:
23
+ state.ns = SimpleNamespace()
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
+ main()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
litbee/dzbee_page.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Display dzbee page."""
2
+ import streamlit as st
3
+ import pandas as pd
4
+
5
+
6
+ def dzbee_page():
7
+ """Display dzbee page."""
8
+ # st.title('dzbee')
9
+ # st.write('Welcome to app1')
10
+
11
+ try:
12
+ df = st.session_state.ns.df
13
+ except Exception as exc:
14
+ logger.error(exc)
15
+ df = pd.DataFrame([[""]])
16
+
17
+ st.table(df)
litbee/ezbee_page.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Display ezbee page."""
2
+ import streamlit as st
3
+ import pandas as pd
4
+
5
+ from st_aggrid import AgGrid
6
+ from st_aggrid.grid_options_builder import GridOptionsBuilder
7
+
8
+
9
+ def ezbee_page():
10
+ """Display ezbee page."""
11
+ # st.title('ezbee')
12
+ # st.write('### ezbee')
13
+ # st.write('Welcome to app1')
14
+
15
+ try:
16
+ df = st.session_state.ns.df
17
+ except Exception as exc:
18
+ logger.error(exc)
19
+ df = pd.DataFrame([[""]])
20
+
21
+ # st.table(df) # looks alright
22
+
23
+ # stlyed pd dataframe?
24
+ # bigger, no pagination
25
+ # st.markdown(df.to_html(), unsafe_allow_html=True)
26
+
27
+ gb = GridOptionsBuilder.from_dataframe(df)
28
+ gb.configure_pagination()
29
+ options = {
30
+ "resizable": True,
31
+ "autoHeight": True,
32
+ "wrapText": True,
33
+ "editable": True,
34
+ }
35
+ gb.configure_default_column(**options)
36
+ gridOptions = gb.build()
37
+
38
+ # ag_grid smallish, editable, probably slower
39
+
40
+ df_exp = st.expander("to be aligned", expanded=False)
41
+ with df_exp:
42
+ st.write(df) # too small
43
+
44
+ _ = """
45
+ ag_exp = st.expander("done aligned") # , expanded=False
46
+ with ag_exp:
47
+ agdf = AgGrid(
48
+ df,
49
+ # fit_columns_on_grid_load=True,
50
+ editable=True,
51
+ gridOptions=gridOptions,
52
+ key="ag_exp",
53
+ )
54
+ # """
55
+
56
+ st.write("double-click a cell to edit")
57
+ agdf = AgGrid(
58
+ df,
59
+ # fit_columns_on_grid_load=True,
60
+ editable=True,
61
+ gridOptions=gridOptions,
62
+ key="outside"
63
+ )
litbee/files2df.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Convert two iesl to pandas.DataFrame."""
2
+ # pylint: disable=invalid-name
3
+
4
+ from itertools import zip_longest
5
+ import tempfile
6
+ import pandas as pd
7
+ from litbee.process_upload import process_upload
8
+
9
+
10
+ def files2df(file1, file2):
11
+ """Convert two files to pd.DataFrame."""
12
+ text1 = [_.strip() for _ in process_upload(file1).splitlines() if _.strip()]
13
+
14
+ # if file2 is tempfile._TemporaryFileWrapper:
15
+ if isinstance(file2, tempfile._TemporaryFileWrapper):
16
+ try:
17
+ filename = file2.name
18
+ except AttributeError:
19
+ filename = ""
20
+ else:
21
+ filename = file2
22
+ if filename:
23
+ # text2 = [_.strip() for _ in process_upload(file2).splitlines() if _.strip()]
24
+ text2 = [_.strip() for _ in process_upload(filename).splitlines() if _.strip()]
25
+ else:
26
+ text2 = [""]
27
+
28
+ text1, text2 = zip(*zip_longest(text1, text2, fillvalue=""))
29
+
30
+ df = pd.DataFrame({"text1": text1, "text2": text2})
31
+
32
+ return df
33
+
34
+
35
+ _ = """
36
+ # return tabulate(df)
37
+ # return tabulate(df, tablefmt="grid")
38
+ # return tabulate(df, tablefmt='html')
39
+ # """
litbee/process_upload.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Process uploads."""
2
+ # pylint: disable=invalid-name, unused-import
3
+ from typing import Union
4
+
5
+ from pathlib import Path
6
+ import tempfile
7
+ import cchardet
8
+ from logzero import logger
9
+
10
+
11
+ def process_upload(upload: Union[str, tempfile._TemporaryFileWrapper, bytes]) -> str:
12
+ """Process upload (fileobj or bytes(zip file: io.BytesIO further to zipfile.ZipFile)).
13
+
14
+ gr.inputs.File("file"): upload normal file
15
+ gr.inputs.File("bytes"): upload zip file
16
+
17
+ """
18
+ # filename/path
19
+ if isinstance(upload, str):
20
+ fpath = Path(upload)
21
+ elif isinstance(upload, bytes):
22
+ logger.warning("Not implemented, yet, for zip file")
23
+ return "Not implemented, yet, for zip file"
24
+ else:
25
+ try:
26
+ fpath = Path(upload.name)
27
+ except Exception as e:
28
+ logger.error("Path(upload.name) error: %s", e)
29
+ return str(e)
30
+
31
+ suffixes = [
32
+ "",
33
+ ".txt",
34
+ ".text",
35
+ ".md",
36
+ "tsv",
37
+ ]
38
+ # check .txt .md ''(no suffix)
39
+ if fpath.suffix.lower() not in suffixes:
40
+ logger.warning('suffix: [%s] not in %s', fpath.suffix, suffixes)
41
+ # return "File type not supported, yet."
42
+
43
+ try:
44
+ # data = Path(upload.name).read_bytes()
45
+ data = fpath.read_bytes()
46
+ except Exception as e:
47
+ logger.error("Unable to read data from %s, errors: %s", fpath, e)
48
+ data = str(e).encode()
49
+
50
+ # no data, empty file, return ""
51
+ if not data:
52
+ logger.info("empty file: %s", fpath)
53
+ return ""
54
+
55
+ encoding = cchardet.detect(data).get("encoding")
56
+
57
+ if encoding is not None:
58
+ try:
59
+ text = fpath.read_text(encoding=encoding)
60
+ except Exception as e:
61
+ logger.error("Unable to retrieve text, error: %s", e)
62
+ text = str(e)
63
+
64
+ # return f"{upload.name} {type(upload)}\n\n{text}"
65
+ # return f"{upload.name}\n{text}"
66
+ return text
67
+
68
+ # not able to cchardet: encoding is None, docx, pdf, epub, zip etc
69
+ logger.info("Trying docx...to be implemented")
70
+
71
+ # TODO .docx .epub .mobi .pdf etc.
72
+
73
+ # _ = Path(upload.name)
74
+ _ = Path(fpath)
75
+ msg = f"binary file: {_.stem[:-8]}{_.suffix}"
76
+ logger.warning("%s", msg)
77
+
78
+ return msg
79
+
80
+
81
+ _ = ''' # colab gradio-file-inputs-upload.ipynb
82
+ # file_to_text/process_file
83
+ def zip_to_text(file_obj):
84
+ """
85
+ # zf = zipfile.ZipFile('german-recipes-dataset.zip')
86
+ zf = file_obj
87
+ namelist = zipfile.ZipFile.namelist(zf);
88
+ # filename = zf.open(namelist[0]);
89
+ file_contents = []
90
+ for filename in namelist:
91
+ with zf.open(filename) as fhandle:
92
+ file_contents.append(fhandle.read().decode())
93
+ """
94
+ # fileobj is <class 'tempfile._TemporaryFileWrapper'>
95
+
96
+ # gr.inputs.File("bytes")
97
+ if isinstance(file_obj, bytes):
98
+ data = file_obj.decode()
99
+ return f"{type(file_obj)}\n{dir(file_obj)}\n{data}"
100
+
101
+ # "file"/gr.inputs.File("file") file_obj.name: /tmp/READMEzm8hc5ze.md
102
+ data = Path(file_obj.name).read_bytes()
103
+ return f"{file_obj.name} {type(file_obj)}\n{dir(file_obj)} \n{data}"
104
+ # '''
litbee/utils.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Prep front cover for sidebar (based on st-bumblebee-st_app.py)."""
2
+ import streamlit as st
3
+ from textwrap import dedent
4
+ import logzero
5
+ from logzero import logger
6
+ from set_loglevel import set_loglevel
7
+
8
+ from litbee import __version__
9
+
10
+ logzero.loglevel(set_loglevel())
11
+
12
+ msg = dedent("""
13
+ What would you like to do?
14
+ The following alignment engines are available.
15
+
16
+ **UFast-Engine**: ultra-fast, based on a home-brewed algorithm, faster than blazing fast but can only process en-zh para/sent pairs, not as sophisticated as DL-Engine;
17
+
18
+ **SFast-Engine**: super-fast, based on machine translation;
19
+
20
+ **Fast-Engine**: based on yet another home-brewed algorithm, blazing fast but can only process en-zh para/sent pairs;
21
+
22
+ **DL-Engin**: based on machine learning, multilingual, one para/sent takes about 1s.
23
+ """
24
+ ).strip()
25
+ msg = dedent("""
26
+ * ezbee: english-chinese, fast para-align
27
+
28
+ * dzbee: german-chinese, fast para-align
29
+
30
+ * bumblebee: other language pairs, normal para-align
31
+
32
+ The algorithm for fast para-align is home-brewn. Two sent-align algorithms are used: one based on Gale-Church, the other machine learning.
33
+ """
34
+ ).strip()
35
+
36
+
37
+ def sb_front_cover():
38
+ """Prep front cover for sidebar"""
39
+ st.sidebar.markdown(f"### litbee {__version__} ")
40
+
41
+ sb_tit_expander = st.sidebar.expander("More info (click to toggle)", expanded=False)
42
+ with sb_tit_expander:
43
+ # st.write(f"Showcasing v.{__version__}, refined, quasi-prodction-ready🚧...")
44
+ # branch
45
+ # st.markdown(
46
+ st.markdown(msg)
47
+
48
+
49
+ intructins = dedent(f"""
50
+ * Set up options in the left sidebar
51
+
52
+ * Click expanders / +: to reveal more details; -: to hide them
53
+
54
+ * Press '**Click to start aligning**' to get the ball rolling. (The button will appear when everything is ready.)
55
+
56
+ * litbee v.{__version__} from mu@qq41947782's keyboard in cyberspace. Join **qq group 316287378** for feedback and questions or to be kept updated. litbee is a member of the bee family.
57
+ """
58
+ ).strip()
59
+
60
+
61
+ def instructions():
62
+ logger.debug("instructions entry")
63
+ back_cover_expander = st.expander("Instructions")
64
+ with back_cover_expander:
65
+ st.markdown(intructins)
66
+
67
+ logger.debug("instructions exit")
68
+
69
+
70
+ about = dedent(f"""
71
+ # litbee {__version__}
72
+
73
+ https://bumblebee.freeforums.net/thread/5/litbee or head to 桃花元 (qq group 316287378)
74
+ """
75
+ ).strip()
76
+ menu_items = {
77
+ 'Get Help': 'https://bumblebee.freeforums.net/thread/5/litbee',
78
+ 'Report a bug': "https://bumblebee.freeforums.net/thread/5/litbee",
79
+ 'About': about,
80
+ }
litbee/xbee_page.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Display xbee page."""
2
+ import streamlit as st
3
+ import pandas as pd
4
+
5
+
6
+ def xbee_page():
7
+ """Display xbee page."""
8
+ # st.title('dzbee')
9
+ st.write('Coming soon')
10
+
11
+ try:
12
+ df = st.session_state.ns.df
13
+ except Exception as exc:
14
+ logger.error(exc)
15
+ df = pd.DataFrame([[""]])
16
+
17
+ # st.table(df)
okteto.yml ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: gradio-cmat
2
+
3
+ # The build section defines how to build the images of
4
+ # your development environment
5
+ # More info: https://www.okteto.com/docs/reference/manifest/#build
6
+ # build:
7
+ # my-service:
8
+ # context: .
9
+
10
+ # The deploy section defines how to deploy your development environment
11
+ # More info: https://www.okteto.com/docs/reference/manifest/#deploy
12
+ # deploy:
13
+ # commands:
14
+ # - name: Deploy
15
+ # command: echo 'Replace this line with the proper 'helm'
16
+
17
+ # or 'kubectl' commands to deploy your development environment'
18
+
19
+ # The dependencies section defines other git repositories to be
20
+ # deployed as part of your development environment
21
+ # More info: https://www.okteto.com/docs/reference/manifest/#dependencies
22
+ # dependencies:
23
+ # - https://github.com/okteto/sample
24
+ # The dev section defines how to activate a development container
25
+ # More info: https://www.okteto.com/docs/reference/manifest/#dev
26
+ dev:
27
+ gradio-cmat:
28
+ # image: okteto/dev:latest
29
+ # image: python:3.8.13-bullseye
30
+ # image: simbachain/poetry-3.8
31
+ image: python:3.8
32
+ command: bash
33
+ workdir: /usr/src/app
34
+ sync:
35
+ - .:/usr/src/app
36
+ environment:
37
+ - name=$USER
38
+ forward:
39
+ - 7861:7861
40
+ - 7860:7860
41
+ - 8501:8501
42
+ reverse:
43
+ - 9000:9000
44
+ autocreate: true
packages.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ icu-doc
2
+ libicu-dev
3
+ pkg-config
poetry.lock CHANGED
The diff for this file is too large to render. See raw diff
 
pyproject.toml CHANGED
@@ -12,6 +12,11 @@ python = "^3.8.3"
12
  logzero = "^1.7.0"
13
  icecream = "^2.1.1"
14
  install = "^1.3.5"
 
 
 
 
 
15
 
16
  [tool.poe.executor]
17
  type = "poetry"
 
12
  logzero = "^1.7.0"
13
  icecream = "^2.1.1"
14
  install = "^1.3.5"
15
+ set-loglevel = "^0.1.2"
16
+ streamlit-multipage = "^0.0.18"
17
+ cchardet = "^2.1.7"
18
+ streamlit-aggrid = "^0.2.3"
19
+ ezbee = "0.1.0a3"
20
 
21
  [tool.poe.executor]
22
  type = "poetry"
requirements-extra.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ streamlit
run-nodemon.sh ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ # nodemon -V -w app.py -x python -m streamlit run app.py
2
+ nodemon -V -w . -x python -m streamlit run $1
run.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # sh run-nodemon.sh app-multipages1.py
2
+ # nodemon -V -w . -x python -m litbee
3
+ nodemon -V -w . -x python -m streamlit run app.py