hjxdl 0.1.50__py3-none-any.whl → 0.1.52__py3-none-any.whl
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.
- hdl/_version.py +2 -2
- hdl/utils/database_tools/connect.py +17 -3
- hdl/utils/llm/chat.py +2 -2
- hdl/utils/llm/vis.py +76 -0
- {hjxdl-0.1.50.dist-info → hjxdl-0.1.52.dist-info}/METADATA +4 -1
- {hjxdl-0.1.50.dist-info → hjxdl-0.1.52.dist-info}/RECORD +8 -7
- {hjxdl-0.1.50.dist-info → hjxdl-0.1.52.dist-info}/WHEEL +0 -0
- {hjxdl-0.1.50.dist-info → hjxdl-0.1.52.dist-info}/top_level.txt +0 -0
hdl/_version.py
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
import psycopg
|
2
|
+
import redis
|
2
3
|
|
3
4
|
|
4
5
|
def connect_by_infofile(info_file: str) -> psycopg.Connection:
|
5
6
|
"""Create a postgres connection
|
6
7
|
|
7
8
|
Args:
|
8
|
-
info_file (str):
|
9
|
+
info_file (str):
|
9
10
|
the path of the connection info like
|
10
11
|
host=127.0.0.1 dbname=dbname port=5432 user=postgres password=lala
|
11
12
|
|
12
13
|
Returns:
|
13
|
-
psycopg.Connection:
|
14
|
+
psycopg.Connection:
|
14
15
|
the connection instance should be closed after committing.
|
15
16
|
"""
|
16
17
|
conn = psycopg.connect(
|
@@ -25,4 +26,17 @@ def connect_by_infofile(info_file: str) -> psycopg.Connection:
|
|
25
26
|
# for record in cur:
|
26
27
|
# print(record)
|
27
28
|
# conn.commit()
|
28
|
-
# conn.close()
|
29
|
+
# conn.close()
|
30
|
+
|
31
|
+
def conn_redis(
|
32
|
+
host: str,
|
33
|
+
port: int
|
34
|
+
):
|
35
|
+
client = redis.Redis(
|
36
|
+
host=host,
|
37
|
+
port=port,
|
38
|
+
decode_responses=True
|
39
|
+
)
|
40
|
+
res = client.ping()
|
41
|
+
print(res)
|
42
|
+
return client
|
hdl/utils/llm/chat.py
CHANGED
@@ -166,7 +166,7 @@ class OpenAI_M():
|
|
166
166
|
"""
|
167
167
|
content = [
|
168
168
|
{"type": "text", "text": prompt},
|
169
|
-
]
|
169
|
+
]
|
170
170
|
if image_url is not None:
|
171
171
|
image_content = {
|
172
172
|
"type": "image_url",
|
@@ -209,7 +209,7 @@ class OpenAI_M():
|
|
209
209
|
"""
|
210
210
|
content = [
|
211
211
|
{"type": "text", "text": prompt},
|
212
|
-
]
|
212
|
+
]
|
213
213
|
if image_url is not None:
|
214
214
|
image_content = {
|
215
215
|
"type": "image_url",
|
hdl/utils/llm/vis.py
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
import requests
|
2
|
+
|
3
|
+
import torch
|
4
|
+
import numpy as np
|
5
|
+
from PIL import Image
|
6
|
+
import redis
|
7
|
+
from transformers import ChineseCLIPProcessor, ChineseCLIPModel
|
8
|
+
|
9
|
+
from ..database_tools.connect import conn_redis
|
10
|
+
|
11
|
+
|
12
|
+
# url = "https://clip-cn-beijing.oss-cn-beijing.aliyuncs.com/pokemon.jpeg"
|
13
|
+
# image = Image.open(requests.get(url, stream=True).raw)
|
14
|
+
|
15
|
+
|
16
|
+
class ImgHandler:
|
17
|
+
def __init__(
|
18
|
+
self,
|
19
|
+
model_path,
|
20
|
+
redis_host,
|
21
|
+
redis_port,
|
22
|
+
) -> None:
|
23
|
+
self.model = ChineseCLIPModel.from_pretrained(model_path)
|
24
|
+
self.processor = ChineseCLIPProcessor.from_pretrained(model_path)
|
25
|
+
self.redis_host = redis_host
|
26
|
+
self.redis_port = redis_port
|
27
|
+
|
28
|
+
@property
|
29
|
+
def redis_conn(self):
|
30
|
+
return conn_redis(self.redis_host, self.redis_port)
|
31
|
+
|
32
|
+
def get_img_features(self, images, **kwargs):
|
33
|
+
inputs = self.processor(
|
34
|
+
images=images,
|
35
|
+
return_tensors="pt",
|
36
|
+
**kwargs
|
37
|
+
)
|
38
|
+
image_features = self.model.get_image_features(**inputs)
|
39
|
+
image_features = image_features / \
|
40
|
+
image_features.norm(p=2, dim=-1, keepdim=True)
|
41
|
+
return image_features
|
42
|
+
|
43
|
+
def get_text_features(
|
44
|
+
self,
|
45
|
+
texts,
|
46
|
+
**kwargs
|
47
|
+
):
|
48
|
+
inputs = self.processor(
|
49
|
+
text=texts,
|
50
|
+
padding=True,
|
51
|
+
return_tensors="pt",
|
52
|
+
**kwargs
|
53
|
+
)
|
54
|
+
text_features = self.model.get_text_features(**inputs)
|
55
|
+
text_features = text_features / \
|
56
|
+
text_features.norm(p=2, dim=-1, keepdim=True)
|
57
|
+
return text_features
|
58
|
+
|
59
|
+
def get_text_img_sims(
|
60
|
+
self,
|
61
|
+
texts,
|
62
|
+
images,
|
63
|
+
**kwargs
|
64
|
+
):
|
65
|
+
inputs = self.processor(
|
66
|
+
text=texts,
|
67
|
+
images=images,
|
68
|
+
return_tensors="pt",
|
69
|
+
padding=True,
|
70
|
+
**kwargs
|
71
|
+
)
|
72
|
+
outputs = self.model(**inputs)
|
73
|
+
logits_per_image = outputs.logits_per_image # this is the image-text similarity score
|
74
|
+
probs = logits_per_image.softmax(dim=1)
|
75
|
+
return probs
|
76
|
+
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: hjxdl
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.52
|
4
4
|
Summary: A collection of functions for Jupyter notebooks
|
5
5
|
Home-page: https://github.com/huluxiaohuowa/hdl
|
6
6
|
Author: Jianxing Hu
|
@@ -18,6 +18,9 @@ Requires-Dist: geopy
|
|
18
18
|
Requires-Dist: timezonefinder
|
19
19
|
Requires-Dist: pytz
|
20
20
|
Requires-Dist: duckduckgo-search[lxml]
|
21
|
+
Requires-Dist: opencv-python
|
22
|
+
Requires-Dist: redis[hiredis]
|
23
|
+
Requires-Dist: Pillow
|
21
24
|
|
22
25
|
# DL framework by Jianxing
|
23
26
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
hdl/__init__.py,sha256=GffnD0jLJdhkd-vo989v40N90sQbofkayRBwxc6TVhQ,72
|
2
|
-
hdl/_version.py,sha256=
|
2
|
+
hdl/_version.py,sha256=AH_hPvheFemhgsFVkuYeG1vR7uIqnobUyxSKwbUlAVA,413
|
3
3
|
hdl/args/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
hdl/args/loss_args.py,sha256=s7YzSdd7IjD24rZvvOrxLLFqMZQb9YylxKeyelSdrTk,70
|
5
5
|
hdl/controllers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -118,7 +118,7 @@ hdl/utils/chemical_tools/__init__.py,sha256=_QRNtVx0ieZZgSEsHndPFKm6XU3WXfRb7GYq
|
|
118
118
|
hdl/utils/chemical_tools/query_info.py,sha256=wyQXwKSY_gBGVUNvYggHpYBtOLAtpYKq3PN5wqDb7Co,4204
|
119
119
|
hdl/utils/chemical_tools/sdf.py,sha256=71PEqU0H885L6IeGHEa6n7ZLZThvMsZOVLuFG2wnoyM,542
|
120
120
|
hdl/utils/database_tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
121
|
-
hdl/utils/database_tools/connect.py,sha256=
|
121
|
+
hdl/utils/database_tools/connect.py,sha256=1CKK1VbgbvYMlA6iBSPpQM6bDt0fxwKwC7cxoppIHoU,940
|
122
122
|
hdl/utils/database_tools/datetime.py,sha256=xqE2xNiOpADzX-R8_bM0bioJRF3Ay9Jp1CAG6dy6uVI,1202
|
123
123
|
hdl/utils/database_tools/web.py,sha256=vZJYWA02QbyUUMGLDX710cexn7RlfWeHa8YwK3UsDZ0,1934
|
124
124
|
hdl/utils/desc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -127,15 +127,16 @@ hdl/utils/desc/template.py,sha256=a0UAkkKctt_EHY9UECsIIAwVkGPcM1Hr01HSkRMeIuw,12
|
|
127
127
|
hdl/utils/general/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
128
128
|
hdl/utils/general/glob.py,sha256=8-RCnt6L297wMIfn34ZAMCsGCZUjHG3MGglGZI1cX0g,491
|
129
129
|
hdl/utils/llm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
130
|
-
hdl/utils/llm/chat.py,sha256=
|
130
|
+
hdl/utils/llm/chat.py,sha256=sk7Lw5Oa30k-l2fnJknkMmTc5zkBeEKsR981aeFhH5s,11907
|
131
131
|
hdl/utils/llm/embs.py,sha256=Tf0FOYrOFZp7qQpEPiSCXzlgyHH0X9HVTUtsup74a9E,7174
|
132
132
|
hdl/utils/llm/extract.py,sha256=2sK_WJzmYIc8iuWaM9DA6Nw3_6q1O4lJ5pKpcZo-bBA,6512
|
133
133
|
hdl/utils/llm/llama_chat.py,sha256=watcHGOaz-bv3x-yDucYlGk5f8FiqfFhwWogrl334fk,4387
|
134
|
+
hdl/utils/llm/vis.py,sha256=2M6-AFOl4q2zMshAwzvQceCTEzuWmAsbkRBHpH91K3M,2041
|
134
135
|
hdl/utils/schedulers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
135
136
|
hdl/utils/schedulers/norm_lr.py,sha256=bDwCmdEK-WkgxQMFBiMuchv8Mm7C0-GZJ6usm-PQk14,4461
|
136
137
|
hdl/utils/weather/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
137
138
|
hdl/utils/weather/weather.py,sha256=k11o6wM15kF8b9NMlEfrg68ak-SfSYLN3nOOflFUv-I,4381
|
138
|
-
hjxdl-0.1.
|
139
|
-
hjxdl-0.1.
|
140
|
-
hjxdl-0.1.
|
141
|
-
hjxdl-0.1.
|
139
|
+
hjxdl-0.1.52.dist-info/METADATA,sha256=oxr1xeBgm6Y0mapKPQr3Xgn67K7uAAs3PahbXylSMdI,818
|
140
|
+
hjxdl-0.1.52.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
|
141
|
+
hjxdl-0.1.52.dist-info/top_level.txt,sha256=-kxwTM5JPhylp06z3zAVO3w6_h7wtBfBo2zgM6YZoTk,4
|
142
|
+
hjxdl-0.1.52.dist-info/RECORD,,
|
File without changes
|
File without changes
|