nlpertools 1.0.4__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 (46) hide show
  1. nlpertools/__init__.py +24 -11
  2. nlpertools/algo/__init__.py +0 -0
  3. nlpertools/algo/ac.py +18 -0
  4. nlpertools/algo/bit_ops.py +28 -0
  5. nlpertools/algo/kmp.py +94 -0
  6. nlpertools/algo/num_ops.py +12 -0
  7. nlpertools/algo/template.py +116 -0
  8. nlpertools/algo/union.py +13 -0
  9. nlpertools/data_client.py +387 -0
  10. nlpertools/data_structure/__init__.py +0 -0
  11. nlpertools/data_structure/base_structure.py +109 -0
  12. nlpertools/dataprocess.py +611 -3
  13. nlpertools/default_db_config.yml +41 -0
  14. nlpertools/io/__init__.py +3 -3
  15. nlpertools/io/dir.py +54 -47
  16. nlpertools/io/file.py +277 -205
  17. nlpertools/ml.py +483 -317
  18. nlpertools/monitor/__init__.py +0 -0
  19. nlpertools/monitor/gpu.py +18 -0
  20. nlpertools/monitor/memory.py +24 -0
  21. nlpertools/movie.py +36 -0
  22. nlpertools/nlpertools_config.yml +1 -0
  23. nlpertools/{openApi.py → open_api.py} +65 -62
  24. nlpertools/other.py +364 -188
  25. nlpertools/pic.py +288 -0
  26. nlpertools/plugin.py +43 -34
  27. nlpertools/reminder.py +98 -15
  28. nlpertools/template/__init__.py +0 -0
  29. nlpertools/utils/__init__.py +3 -0
  30. nlpertools/utils/lazy.py +727 -0
  31. nlpertools/utils/log_util.py +20 -0
  32. nlpertools/utils/package.py +89 -0
  33. nlpertools/utils/package_v1.py +94 -0
  34. nlpertools/utils/package_v2.py +117 -0
  35. nlpertools/utils_for_nlpertools.py +93 -0
  36. nlpertools/vector_index_demo.py +108 -0
  37. nlpertools/wrapper.py +161 -0
  38. {nlpertools-1.0.4.dist-info → nlpertools-1.0.6.dev0.dist-info}/LICENSE +200 -200
  39. nlpertools-1.0.6.dev0.dist-info/METADATA +111 -0
  40. nlpertools-1.0.6.dev0.dist-info/RECORD +43 -0
  41. {nlpertools-1.0.4.dist-info → nlpertools-1.0.6.dev0.dist-info}/WHEEL +1 -1
  42. nlpertools-1.0.6.dev0.dist-info/top_level.txt +2 -0
  43. nlpertools_helper/__init__.py +10 -0
  44. nlpertools-1.0.4.dist-info/METADATA +0 -42
  45. nlpertools-1.0.4.dist-info/RECORD +0 -15
  46. nlpertools-1.0.4.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,62 +1,65 @@
1
- #!/usr/bin/python3.8
2
- # -*- coding: utf-8 -*-
3
- # @Author : youshu.Ji
4
- import hashlib
5
- import json
6
-
7
- import requests
8
-
9
-
10
- def translate_by_youdao(text):
11
- YOUDAO_URL = 'https://openapi.youdao.com/api'
12
- APP_KEY = 'xx'
13
- APP_SECRET = 'xx'
14
-
15
- def _truncate(q):
16
- if q is None:
17
- return None
18
- size = len(q)
19
- return q if size <= 20 else q[0:10] + str(size) + q[size - 10:size]
20
-
21
- def _do_request(data):
22
- headers = {'Content-Type': 'application/x-www-form-urlencoded'}
23
- return requests.post(YOUDAO_URL, data=data, headers=headers)
24
-
25
- def _encrypt(signStr):
26
- hash_algorithm = hashlib.sha256()
27
- hash_algorithm.update(signStr.encode('utf-8'))
28
- return hash_algorithm.hexdigest()
29
-
30
- q = text
31
-
32
- data = {}
33
- data['from'] = '源语言'
34
- data['to'] = '目标语言'
35
- data['signType'] = 'v3'
36
- curtime = str(int(time.time()))
37
- data['curtime'] = curtime
38
- salt = str(uuid.uuid1())
39
- signStr = APP_KEY + _truncate(q) + salt + curtime + APP_SECRET
40
- sign = _encrypt(signStr)
41
- data['appKey'] = APP_KEY
42
- data['q'] = q
43
- data['salt'] = salt
44
- data['sign'] = sign
45
- data['vocabId'] = "您的用户词表ID"
46
- youdao_res = _do_request(data)
47
- res = youdao_res.json()['translation'][0]
48
- return res
49
-
50
-
51
- def get_TexSmart(text):
52
- # text 可以是list, 也可以是str
53
- # 如果是分类结果 total['cat_list']['name']
54
- obj = {"str": text, "options": {"text_cat": {"enable": True}}}
55
- req_str = json.dumps(obj).encode()
56
-
57
- url = "https://texsmart.qq.com/api"
58
- r = requests.post(url, data=req_str)
59
- r.encoding = "utf-8"
60
- print(r.text)
61
- total = json.loads(r.text)
62
- 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