nlpertools 1.0.5__py3-none-any.whl → 1.0.6.dev0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. nlpertools/__init__.py +24 -20
  2. nlpertools/algo/ac.py +18 -0
  3. nlpertools/algo/bit_ops.py +28 -0
  4. nlpertools/algo/kmp.py +94 -55
  5. nlpertools/algo/num_ops.py +12 -0
  6. nlpertools/algo/template.py +116 -0
  7. nlpertools/algo/union.py +13 -0
  8. nlpertools/data_client.py +387 -257
  9. nlpertools/data_structure/base_structure.py +109 -13
  10. nlpertools/dataprocess.py +611 -3
  11. nlpertools/default_db_config.yml +41 -0
  12. nlpertools/io/__init__.py +3 -3
  13. nlpertools/io/dir.py +54 -36
  14. nlpertools/io/file.py +277 -222
  15. nlpertools/ml.py +483 -460
  16. nlpertools/monitor/__init__.py +0 -0
  17. nlpertools/monitor/gpu.py +18 -0
  18. nlpertools/monitor/memory.py +24 -0
  19. nlpertools/movie.py +36 -0
  20. nlpertools/nlpertools_config.yml +1 -0
  21. nlpertools/{openApi.py → open_api.py} +65 -65
  22. nlpertools/other.py +364 -249
  23. nlpertools/pic.py +288 -0
  24. nlpertools/plugin.py +43 -43
  25. nlpertools/reminder.py +98 -87
  26. nlpertools/utils/__init__.py +3 -3
  27. nlpertools/utils/lazy.py +727 -0
  28. nlpertools/utils/log_util.py +20 -0
  29. nlpertools/utils/package.py +89 -76
  30. nlpertools/utils/package_v1.py +94 -0
  31. nlpertools/utils/package_v2.py +117 -0
  32. nlpertools/utils_for_nlpertools.py +93 -93
  33. nlpertools/vector_index_demo.py +108 -0
  34. nlpertools/wrapper.py +161 -96
  35. {nlpertools-1.0.5.dist-info → nlpertools-1.0.6.dev0.dist-info}/LICENSE +200 -200
  36. nlpertools-1.0.6.dev0.dist-info/METADATA +111 -0
  37. nlpertools-1.0.6.dev0.dist-info/RECORD +43 -0
  38. {nlpertools-1.0.5.dist-info → nlpertools-1.0.6.dev0.dist-info}/WHEEL +1 -1
  39. nlpertools-1.0.6.dev0.dist-info/top_level.txt +2 -0
  40. nlpertools_helper/__init__.py +10 -0
  41. nlpertools-1.0.5.dist-info/METADATA +0 -85
  42. nlpertools-1.0.5.dist-info/RECORD +0 -25
  43. nlpertools-1.0.5.dist-info/top_level.txt +0 -1
File without changes
@@ -0,0 +1,18 @@
1
+ import os
2
+ import time
3
+
4
+
5
+ def gpu_memory():
6
+ while 1:
7
+ current_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
8
+ usage = os.popen("nvidia-smi --query-gpu=memory.used --format=csv").read()
9
+ usage_string = ",".join(usage.split("\n"))
10
+ # 将内存使用情况写入文件
11
+ with open("mem_usage_gpu.txt", "a") as f:
12
+ f.write(f"{current_time} - Usage: {usage_string}\n")
13
+ time.sleep(1)
14
+
15
+
16
+ if __name__ == "__main__":
17
+ print("start gpu memory monitor!")
18
+ gpu_memory()
@@ -0,0 +1,24 @@
1
+ import time
2
+
3
+ import psutil
4
+
5
+
6
+ def memory_monitor():
7
+ while True:
8
+ # 获取当前时间
9
+ current_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
10
+
11
+ # 获取内存使用情况
12
+ mem = psutil.virtual_memory()
13
+ total = round(mem.total / 1024 / 1024 / 1024, 2)
14
+ available = round(mem.available / 1024 / 1024 / 1024, 2)
15
+ # 将内存使用情况写入文件
16
+ with open("mem_usage_cpu.txt", "a") as f:
17
+ f.write(f"{current_time} - Total: {total}, Available: {available}\n")
18
+
19
+ time.sleep(10)
20
+
21
+
22
+ if __name__ == "__main__":
23
+ print("start cpu memory monitor!")
24
+ memory_monitor()
nlpertools/movie.py ADDED
@@ -0,0 +1,36 @@
1
+ from tqdm import trange, tqdm
2
+
3
+
4
+ def cv_time(file_path):
5
+ import cv2 # pip install opencv-python-headless
6
+
7
+ cap = cv2.VideoCapture(file_path)
8
+ frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
9
+ print(frame_count)
10
+ success, image = cap.read()
11
+ for i in trange(frame_count):
12
+ success, image = cap.read()
13
+ print()
14
+ # print(success)
15
+
16
+
17
+ def moviepy_time(file_path):
18
+ from moviepy.editor import VideoFileClip
19
+
20
+ video = VideoFileClip(file_path)
21
+ fps = video.fps
22
+ total = int(video.duration * fps)
23
+ for idx, frame in tqdm(
24
+ # 循环时以帧迭代
25
+ enumerate(video.iter_frames(fps=fps)),
26
+ total=total,
27
+ ):
28
+ pass
29
+
30
+
31
+ if __name__ == "__main__":
32
+
33
+ # file_path = r"../movies/bikes.mp4"
34
+ file_path = r"D:\[甄嬛传][76集全]\甄嬛传.EP34.WEB-DL.4K.H264.AAC-CYW.mp4"
35
+ # cv_time(file_path)
36
+ moviepy_time(file_path)
@@ -0,0 +1 @@
1
+ IPT_MODEL_PATH : './tiny'
@@ -1,65 +1,65 @@
1
- #!/usr/bin/python3.8
2
- # -*- coding: utf-8 -*-
3
- # @Author : youshu.Ji
4
- import hashlib
5
- import json
6
- import time
7
- import uuid
8
-
9
- # import requests
10
- from .utils.package import *
11
-
12
-
13
- def translate_by_youdao(text):
14
- YOUDAO_URL = 'https://openapi.youdao.com/api'
15
- APP_KEY = 'xx'
16
- APP_SECRET = 'xx'
17
-
18
- def _truncate(q):
19
- if q is None:
20
- return None
21
- size = len(q)
22
- return q if size <= 20 else q[0:10] + str(size) + q[size - 10:size]
23
-
24
- def _do_request(data):
25
- headers = {'Content-Type': 'application/x-www-form-urlencoded'}
26
- return requests.post(YOUDAO_URL, data=data, headers=headers)
27
-
28
- def _encrypt(signStr):
29
- hash_algorithm = hashlib.sha256()
30
- hash_algorithm.update(signStr.encode('utf-8'))
31
- return hash_algorithm.hexdigest()
32
-
33
- q = text
34
-
35
- data = {}
36
- data['from'] = '源语言'
37
- data['to'] = '目标语言'
38
- data['signType'] = 'v3'
39
- curtime = str(int(time.time()))
40
- data['curtime'] = curtime
41
- salt = str(uuid.uuid1())
42
- signStr = APP_KEY + _truncate(q) + salt + curtime + APP_SECRET
43
- sign = _encrypt(signStr)
44
- data['appKey'] = APP_KEY
45
- data['q'] = q
46
- data['salt'] = salt
47
- data['sign'] = sign
48
- data['vocabId'] = "您的用户词表ID"
49
- youdao_res = _do_request(data)
50
- res = youdao_res.json()['translation'][0]
51
- return res
52
-
53
-
54
- def get_TexSmart(text):
55
- # text 可以是list, 也可以是str
56
- # 如果是分类结果 total['cat_list']['name']
57
- obj = {"str": text, "options": {"text_cat": {"enable": True}}}
58
- req_str = json.dumps(obj).encode()
59
-
60
- url = "https://texsmart.qq.com/api"
61
- r = requests.post(url, data=req_str)
62
- r.encoding = "utf-8"
63
- print(r.text)
64
- total = json.loads(r.text)
65
- return total
1
+ #!/usr/bin/python3.8
2
+ # -*- coding: utf-8 -*-
3
+ # @Author : youshu.Ji
4
+ import hashlib
5
+ import json
6
+ import time
7
+ import uuid
8
+
9
+ # import requests
10
+ from .utils.package import *
11
+
12
+
13
+ def translate_by_youdao(text):
14
+ YOUDAO_URL = 'https://openapi.youdao.com/api'
15
+ APP_KEY = 'xx'
16
+ APP_SECRET = 'xx'
17
+
18
+ def _truncate(q):
19
+ if q is None:
20
+ return None
21
+ size = len(q)
22
+ return q if size <= 20 else q[0:10] + str(size) + q[size - 10:size]
23
+
24
+ def _do_request(data):
25
+ headers = {'Content-Type': 'application/x-www-form-urlencoded'}
26
+ return requests.post(YOUDAO_URL, data=data, headers=headers)
27
+
28
+ def _encrypt(signStr):
29
+ hash_algorithm = hashlib.sha256()
30
+ hash_algorithm.update(signStr.encode('utf-8'))
31
+ return hash_algorithm.hexdigest()
32
+
33
+ q = text
34
+
35
+ data = {}
36
+ data['from'] = '源语言'
37
+ data['to'] = '目标语言'
38
+ data['signType'] = 'v3'
39
+ curtime = str(int(time.time()))
40
+ data['curtime'] = curtime
41
+ salt = str(uuid.uuid1())
42
+ signStr = APP_KEY + _truncate(q) + salt + curtime + APP_SECRET
43
+ sign = _encrypt(signStr)
44
+ data['appKey'] = APP_KEY
45
+ data['q'] = q
46
+ data['salt'] = salt
47
+ data['sign'] = sign
48
+ data['vocabId'] = "您的用户词表ID"
49
+ youdao_res = _do_request(data)
50
+ res = youdao_res.json()['translation'][0]
51
+ return res
52
+
53
+
54
+ def get_TexSmart(text):
55
+ # text 可以是list, 也可以是str
56
+ # 如果是分类结果 total['cat_list']['name']
57
+ obj = {"str": text, "options": {"text_cat": {"enable": True}}}
58
+ req_str = json.dumps(obj).encode()
59
+
60
+ url = "https://texsmart.qq.com/api"
61
+ r = requests.post(url, data=req_str)
62
+ r.encoding = "utf-8"
63
+ print(r.text)
64
+ total = json.loads(r.text)
65
+ return total