halib 0.1.23__tar.gz → 0.1.25__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. {halib-0.1.23/halib.egg-info → halib-0.1.25}/PKG-INFO +6 -1
  2. {halib-0.1.23 → halib-0.1.25}/README.md +5 -0
  3. {halib-0.1.23 → halib-0.1.25}/halib/__init__.py +2 -2
  4. {halib-0.1.23 → halib-0.1.25}/halib/filetype/videofile.py +4 -6
  5. {halib-0.1.23 → halib-0.1.25}/halib/online/gdrive.py +2 -3
  6. {halib-0.1.23 → halib-0.1.25}/halib/online/gdrive_mkdir.py +2 -2
  7. {halib-0.1.23 → halib-0.1.25}/halib/online/gdrive_test.py +1 -4
  8. {halib-0.1.23 → halib-0.1.25}/halib/online/projectmake.py +2 -4
  9. halib-0.1.25/halib/tele_noti.py +123 -0
  10. {halib-0.1.23 → halib-0.1.25/halib.egg-info}/PKG-INFO +6 -1
  11. {halib-0.1.23 → halib-0.1.25}/halib.egg-info/SOURCES.txt +4 -3
  12. halib-0.1.25/halib.egg-info/requires.txt +13 -0
  13. {halib-0.1.23 → halib-0.1.25}/setup.py +1 -1
  14. halib-0.1.23/halib.egg-info/requires.txt +0 -7
  15. {halib-0.1.23 → halib-0.1.25}/.gitignore +0 -0
  16. {halib-0.1.23 → halib-0.1.25}/GDriveFolder.txt +0 -0
  17. {halib-0.1.23 → halib-0.1.25}/LICENSE.txt +0 -0
  18. {halib-0.1.23 → halib-0.1.25}/guide_publish_pip.pdf +0 -0
  19. {halib-0.1.23 → halib-0.1.25}/halib/cuda.py +0 -0
  20. {halib-0.1.23 → halib-0.1.25}/halib/filetype/__init__.py +0 -0
  21. {halib-0.1.23 → halib-0.1.25}/halib/filetype/csvfile.py +0 -0
  22. {halib-0.1.23 → halib-0.1.25}/halib/filetype/jsonfile.py +0 -0
  23. {halib-0.1.23 → halib-0.1.25}/halib/filetype/textfile.py +0 -0
  24. {halib-0.1.23 → halib-0.1.25}/halib/filetype/yamlfile.py +0 -0
  25. {halib-0.1.23 → halib-0.1.25}/halib/listop.py +0 -0
  26. {halib-0.1.23 → halib-0.1.25}/halib/online/__init__.py +0 -0
  27. {halib-0.1.23 → halib-0.1.25}/halib/plot.py +0 -0
  28. {halib-0.1.23/halib/sys → halib-0.1.25/halib/system}/__init__.py +0 -0
  29. {halib-0.1.23/halib/sys → halib-0.1.25/halib/system}/cmd.py +0 -0
  30. {halib-0.1.23/halib/sys → halib-0.1.25/halib/system}/filesys.py +0 -0
  31. {halib-0.1.23 → halib-0.1.25}/halib.egg-info/dependency_links.txt +0 -0
  32. {halib-0.1.23 → halib-0.1.25}/halib.egg-info/top_level.txt +0 -0
  33. {halib-0.1.23 → halib-0.1.25}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: halib
3
- Version: 0.1.23
3
+ Version: 0.1.25
4
4
  Summary: Small library for common tasks
5
5
  Author: Hoang Van Ha
6
6
  Author-email: hoangvanhauit@gmail.com
@@ -15,6 +15,11 @@ License-File: LICENSE.txt
15
15
 
16
16
  Helper package for coding and automation
17
17
 
18
+ **Version 0.1.24**
19
+
20
+ + rename `sys` to `system` to avoid conflict with built-in `sys` module
21
+ + add `tele_noti` module to send notification to telegram after a specific interval for training progress monitoring
22
+ ---
18
23
  **Version 0.1.22**
19
24
 
20
25
  + add `cuda.py` module to check CUDA availability (for both pytorch and tensorflow)
@@ -1,5 +1,10 @@
1
1
  Helper package for coding and automation
2
2
 
3
+ **Version 0.1.24**
4
+
5
+ + rename `sys` to `system` to avoid conflict with built-in `sys` module
6
+ + add `tele_noti` module to send notification to telegram after a specific interval for training progress monitoring
7
+ ---
3
8
  **Version 0.1.22**
4
9
 
5
10
  + add `cuda.py` module to check CUDA availability (for both pytorch and tensorflow)
@@ -28,8 +28,8 @@ import numpy as np
28
28
  import pandas as pd
29
29
  from .filetype import *
30
30
  from .filetype.yamlfile import load_yaml
31
- from .sys import cmd
32
- from .sys import filesys as fs
31
+ from .system import cmd
32
+ from .system import filesys as fs
33
33
  from .cuda import tcuda
34
34
 
35
35
  # for log
@@ -1,12 +1,10 @@
1
- from enum import Enum
2
-
3
1
  import cv2
2
+ import textfile
4
3
  import enlighten
5
- from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
4
+ from enum import Enum
5
+ from ..system import filesys
6
6
  from tube_dl import Youtube, Playlist
7
-
8
- from halib.sys import filesys
9
- from halib.filetype import textfile
7
+ from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
10
8
 
11
9
 
12
10
  class VideoResolution(Enum):
@@ -15,9 +15,8 @@ from pydrive.auth import GoogleAuth
15
15
  from pydrive.drive import GoogleDrive
16
16
  from pydrive.files import GoogleDriveFileList
17
17
 
18
-
19
- from halib.sys import filesys
20
- from halib.filetype import textfile
18
+ from ..system import filesys
19
+ from ..filetype import textfile
21
20
 
22
21
  # Import general libraries
23
22
 
@@ -1,8 +1,8 @@
1
1
  from argparse import ArgumentParser
2
2
  from datetime import datetime
3
3
 
4
- from halib.online import gdrive
5
- from halib.filetype import textfile
4
+ import gdrive
5
+ from ..filetype import textfile
6
6
 
7
7
 
8
8
  def parse_args():
@@ -1,8 +1,5 @@
1
1
  from argparse import ArgumentParser
2
-
3
- from halib.online import gdrive
4
-
5
-
2
+ import gdrive
6
3
  def parse_args():
7
4
  parser = ArgumentParser(description="Upload local folder to Google Drive")
8
5
  parser.add_argument(
@@ -8,10 +8,8 @@ import subprocess
8
8
 
9
9
  import certifi
10
10
  import pycurl
11
-
12
- from halib.filetype import jsonfile
13
- from halib.sys import filesys
14
-
11
+ from ..filetype import jsonfile
12
+ from ..system import filesys
15
13
 
16
14
  def get_curl(url, user_and_pass, verbose=True):
17
15
  c = pycurl.Curl()
@@ -0,0 +1,123 @@
1
+ # Watch a log file and send a telegram message when train reaches a certain epoch or end
2
+
3
+ import os
4
+ import yaml
5
+ import asyncio
6
+ import telegram
7
+ import pandas as pd
8
+
9
+ from rich.pretty import pprint
10
+ import plotly.graph_objects as go
11
+
12
+ from system import filesys as fs
13
+ from filetype import textfile, csvfile
14
+
15
+ from argparse import ArgumentParser
16
+
17
+ def parse_args():
18
+ parser = ArgumentParser(
19
+ description="desc text")
20
+ parser.add_argument(
21
+ "-cfg",
22
+ "--cfg",
23
+ type=str,
24
+ help="yaml file for tele",
25
+ default=r"E:\Dev\halib\cfg_tele_noti.yaml",
26
+ )
27
+
28
+ return parser.parse_args()
29
+
30
+ def get_watcher_message_df(target_file, num_last_lines):
31
+ file_ext = fs.get_file_name(target_file, split_file_ext=True)[1]
32
+ supported_ext = ['.txt', '.log', '.csv']
33
+ assert file_ext in supported_ext, f"File extension {file_ext} not supported. Supported extensions are {supported_ext}"
34
+ last_lines_df = None
35
+ if file_ext in ['.txt', '.log']:
36
+ lines = textfile.read_line_by_line(target_file)
37
+ if num_last_lines > len(lines):
38
+ num_last_lines = len(lines)
39
+ last_line_arr = lines[-num_last_lines:]
40
+ dfCreator = csvfile.DFCreator()
41
+ dfCreator.create_table('last_lines', ['line'])
42
+ last_line_arr = [[line] for line in last_line_arr]
43
+ dfCreator.insert_rows('last_lines', last_line_arr)
44
+ dfCreator.fill_table_from_row_pool('last_lines')
45
+ last_lines_df = dfCreator['last_lines'].copy()
46
+ else:
47
+ df = pd.read_csv(target_file)
48
+ num_rows = len(df)
49
+ if num_last_lines > num_rows:
50
+ num_last_lines = num_rows
51
+ last_lines_df = df.tail(num_last_lines)
52
+ return last_lines_df
53
+
54
+
55
+ def df2img(df: pd.DataFrame, output_img_dir, decimal_places, out_img_scale):
56
+ df = df.round(decimal_places)
57
+ fig = go.Figure(data=[
58
+ go.Table(
59
+ header=dict(values=list(df.columns),align='center'),
60
+ cells=dict(values=df.values.transpose(),
61
+ fill_color = [["white","lightgrey"]*df.shape[0]],
62
+ align='center'
63
+ )
64
+ )
65
+ ])
66
+ img_path = os.path.normpath(os.path.join(output_img_dir, "last_lines.png"))
67
+ fig.write_image(img_path, scale=out_img_scale)
68
+ return img_path
69
+
70
+
71
+ def compose_message_and_img_path(
72
+ target_file, project, num_last_lines, decimal_places, out_img_scale, output_img_dir
73
+ ):
74
+ context_msg = f">> Project: {project} \n>> File: {target_file} \n>> Last {num_last_lines} lines:"
75
+ msg_df = get_watcher_message_df(target_file, num_last_lines)
76
+ img_path = df2img(msg_df, output_img_dir, decimal_places, out_img_scale)
77
+ return context_msg, img_path
78
+
79
+
80
+ async def send_to_telegram(cfg_dict):
81
+ # pprint(cfg_dict)
82
+ token = cfg_dict["telegram"]["token"]
83
+ chat_id = cfg_dict["telegram"]["chat_id"]
84
+
85
+ noti_settings = cfg_dict["noti_settings"]
86
+ project = noti_settings["project"]
87
+ target_file = noti_settings["target_file"]
88
+ num_last_lines = noti_settings["num_last_lines"]
89
+ output_img_dir = noti_settings["output_img_dir"]
90
+ decimal_places = noti_settings["decimal_places"]
91
+ out_img_scale = noti_settings["out_img_scale"]
92
+
93
+ bot = telegram.Bot(token=token)
94
+ async with bot:
95
+ context_msg, img_path = compose_message_and_img_path(
96
+ target_file,
97
+ project,
98
+ num_last_lines,
99
+ decimal_places,
100
+ out_img_scale,
101
+ output_img_dir,
102
+ )
103
+ pprint('Sending message to telegram...')
104
+ await bot.send_message(text=context_msg, chat_id=chat_id)
105
+ await bot.send_photo(chat_id=chat_id, photo=open(img_path, "rb"))
106
+
107
+
108
+ async def run_forever(cfg_path):
109
+ cfg_dict = yaml.safe_load(open(cfg_path, "r"))
110
+ noti_settings = cfg_dict["noti_settings"]
111
+ interval_in_min = noti_settings["interval_in_min"]
112
+ interval_in_sec = int(interval_in_min * 60)
113
+ pprint(f'Message will be sent every {interval_in_min} minutes or {interval_in_sec} seconds')
114
+ while True:
115
+ await send_to_telegram(cfg_dict)
116
+ await asyncio.sleep(interval_in_sec)
117
+
118
+ async def main():
119
+ args = parse_args()
120
+ await run_forever(args.cfg)
121
+
122
+ if __name__ == "__main__":
123
+ asyncio.run(main())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: halib
3
- Version: 0.1.23
3
+ Version: 0.1.25
4
4
  Summary: Small library for common tasks
5
5
  Author: Hoang Van Ha
6
6
  Author-email: hoangvanhauit@gmail.com
@@ -15,6 +15,11 @@ License-File: LICENSE.txt
15
15
 
16
16
  Helper package for coding and automation
17
17
 
18
+ **Version 0.1.24**
19
+
20
+ + rename `sys` to `system` to avoid conflict with built-in `sys` module
21
+ + add `tele_noti` module to send notification to telegram after a specific interval for training progress monitoring
22
+ ---
18
23
  **Version 0.1.22**
19
24
 
20
25
  + add `cuda.py` module to check CUDA availability (for both pytorch and tensorflow)
@@ -8,6 +8,7 @@ halib/__init__.py
8
8
  halib/cuda.py
9
9
  halib/listop.py
10
10
  halib/plot.py
11
+ halib/tele_noti.py
11
12
  halib.egg-info/PKG-INFO
12
13
  halib.egg-info/SOURCES.txt
13
14
  halib.egg-info/dependency_links.txt
@@ -24,6 +25,6 @@ halib/online/gdrive.py
24
25
  halib/online/gdrive_mkdir.py
25
26
  halib/online/gdrive_test.py
26
27
  halib/online/projectmake.py
27
- halib/sys/__init__.py
28
- halib/sys/cmd.py
29
- halib/sys/filesys.py
28
+ halib/system/__init__.py
29
+ halib/system/cmd.py
30
+ halib/system/filesys.py
@@ -0,0 +1,13 @@
1
+ rich
2
+ tqdm
3
+ tabulate
4
+ loguru
5
+ omegaconf
6
+ networkx
7
+ click
8
+ python-telegram-bot
9
+ plotly
10
+ moviepy
11
+ tube_dl
12
+ enlighten
13
+ pycurl
@@ -8,7 +8,7 @@ with open("requirements.txt") as f:
8
8
 
9
9
  setuptools.setup(
10
10
  name="halib",
11
- version="0.1.23",
11
+ version="0.1.25",
12
12
  author="Hoang Van Ha",
13
13
  author_email="hoangvanhauit@gmail.com",
14
14
  description="Small library for common tasks",
@@ -1,7 +0,0 @@
1
- rich
2
- tqdm
3
- tabulate
4
- loguru
5
- omegaconf
6
- networkx
7
- click
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes