hjxdl 0.2.13__py3-none-any.whl → 0.2.15__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/llm/vis.py +20 -0
- hdl/utils/llm/visrag.py +27 -6
- {hjxdl-0.2.13.dist-info → hjxdl-0.2.15.dist-info}/METADATA +1 -1
- {hjxdl-0.2.13.dist-info → hjxdl-0.2.15.dist-info}/RECORD +7 -7
- {hjxdl-0.2.13.dist-info → hjxdl-0.2.15.dist-info}/WHEEL +0 -0
- {hjxdl-0.2.13.dist-info → hjxdl-0.2.15.dist-info}/top_level.txt +0 -0
hdl/_version.py
CHANGED
hdl/utils/llm/vis.py
CHANGED
@@ -15,6 +15,7 @@ from redis.commands.search.indexDefinition import IndexDefinition, IndexType
|
|
15
15
|
from hdl.jupyfuncs.show.pbar import tqdm
|
16
16
|
from redis.commands.search.query import Query
|
17
17
|
|
18
|
+
|
18
19
|
from ..database_tools.connect import conn_redis
|
19
20
|
|
20
21
|
|
@@ -89,6 +90,7 @@ def imgfile_to_base64(img_dir: str):
|
|
89
90
|
|
90
91
|
return img_base64
|
91
92
|
|
93
|
+
|
92
94
|
def imgbase64_to_pilimg(img_base64: str):
|
93
95
|
"""Converts a base64 encoded image to a PIL image.
|
94
96
|
|
@@ -107,6 +109,24 @@ def imgbase64_to_pilimg(img_base64: str):
|
|
107
109
|
return img_pil
|
108
110
|
|
109
111
|
|
112
|
+
def pilimg_to_base64(pilimg):
|
113
|
+
"""Converts a PIL image to base64 format.
|
114
|
+
|
115
|
+
Args:
|
116
|
+
pilimg (PIL.Image): The PIL image to be converted.
|
117
|
+
|
118
|
+
Returns:
|
119
|
+
str: Base64 encoded image string.
|
120
|
+
"""
|
121
|
+
buffered = BytesIO()
|
122
|
+
pilimg.save(buffered, format="PNG")
|
123
|
+
image_base64 = base64.b64encode(buffered.getvalue()).decode("utf-8")
|
124
|
+
img_format = 'png'
|
125
|
+
mime_type = f"image/{img_format}"
|
126
|
+
img_base64 = f"data:{mime_type};base64,{image_base64}"
|
127
|
+
return img_base64
|
128
|
+
|
129
|
+
|
110
130
|
class ImgHandler:
|
111
131
|
def __init__(
|
112
132
|
self,
|
hdl/utils/llm/visrag.py
CHANGED
@@ -12,7 +12,7 @@ import json
|
|
12
12
|
from transformers import AutoModel, AutoTokenizer
|
13
13
|
|
14
14
|
from .chat import OpenAI_M
|
15
|
-
from .vis import
|
15
|
+
from .vis import pilimg_to_base64
|
16
16
|
|
17
17
|
def get_image_md5(img: Image.Image):
|
18
18
|
img_byte_array = img.tobytes()
|
@@ -116,14 +116,35 @@ def retrieve_gradio(knowledge_base, query, topk, cache_dir=None, model=None, tok
|
|
116
116
|
# return image_base64
|
117
117
|
|
118
118
|
def answer_question(images, question, gen_model):
|
119
|
-
#
|
120
|
-
|
121
|
-
images_base64 = [imgfile_to_base64(image) for image in images]
|
119
|
+
# Load images from the image paths in images[0]
|
120
|
+
pil_images = [Image.open(image[0]).convert('RGB') for image in images]
|
122
121
|
|
123
|
-
#
|
122
|
+
# Calculate the total size of the new image (for vertical concatenation)
|
123
|
+
widths, heights = zip(*(img.size for img in pil_images))
|
124
|
+
|
125
|
+
# Assuming vertical concatenation, so width is the max width, height is the sum of heights
|
126
|
+
total_width = max(widths)
|
127
|
+
total_height = sum(heights)
|
128
|
+
|
129
|
+
# Create a new blank image with the total width and height
|
130
|
+
new_image = Image.new('RGB', (total_width, total_height))
|
131
|
+
|
132
|
+
# Paste each image into the new image
|
133
|
+
y_offset = 0
|
134
|
+
for img in pil_images:
|
135
|
+
new_image.paste(img, (0, y_offset))
|
136
|
+
y_offset += img.height # Move the offset down by the height of the image
|
137
|
+
|
138
|
+
# Optionally save or display the final concatenated image (for debugging)
|
139
|
+
# new_image.save('concatenated_image.png')
|
140
|
+
|
141
|
+
# Convert the concatenated image to base64
|
142
|
+
new_image_base64 = pilimg_to_base64(new_image)
|
143
|
+
|
144
|
+
# Call the model with the base64-encoded concatenated image
|
124
145
|
answer = gen_model.chat(
|
125
146
|
prompt=question,
|
126
|
-
images=
|
147
|
+
images=[new_image_base64], # Use the concatenated image
|
127
148
|
stream=False
|
128
149
|
)
|
129
150
|
return answer
|
@@ -1,5 +1,5 @@
|
|
1
1
|
hdl/__init__.py,sha256=GffnD0jLJdhkd-vo989v40N90sQbofkayRBwxc6TVhQ,72
|
2
|
-
hdl/_version.py,sha256=
|
2
|
+
hdl/_version.py,sha256=jLEv5wW_x8zLfp1bwdtLZaGYh6V6kSSSoRN6ETWwP6c,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
|
@@ -132,13 +132,13 @@ hdl/utils/llm/chatgr.py,sha256=GO2G7g6YybduA5VCUuGjvEsJfC_6L7rycSnPeHMcxyM,2820
|
|
132
132
|
hdl/utils/llm/embs.py,sha256=Tf0FOYrOFZp7qQpEPiSCXzlgyHH0X9HVTUtsup74a9E,7174
|
133
133
|
hdl/utils/llm/extract.py,sha256=2sK_WJzmYIc8iuWaM9DA6Nw3_6q1O4lJ5pKpcZo-bBA,6512
|
134
134
|
hdl/utils/llm/llama_chat.py,sha256=watcHGOaz-bv3x-yDucYlGk5f8FiqfFhwWogrl334fk,4387
|
135
|
-
hdl/utils/llm/vis.py,sha256
|
136
|
-
hdl/utils/llm/visrag.py,sha256=
|
135
|
+
hdl/utils/llm/vis.py,sha256=-6QvxSVzKqxLh_l0aYg2wN2G5HOiQvCpfp-jn9twXw0,16210
|
136
|
+
hdl/utils/llm/visrag.py,sha256=vNj4cHsvfC_Vc0eDPKZc-yflLUMGApZGpggjAqAlwS8,9215
|
137
137
|
hdl/utils/schedulers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
138
138
|
hdl/utils/schedulers/norm_lr.py,sha256=bDwCmdEK-WkgxQMFBiMuchv8Mm7C0-GZJ6usm-PQk14,4461
|
139
139
|
hdl/utils/weather/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
140
140
|
hdl/utils/weather/weather.py,sha256=k11o6wM15kF8b9NMlEfrg68ak-SfSYLN3nOOflFUv-I,4381
|
141
|
-
hjxdl-0.2.
|
142
|
-
hjxdl-0.2.
|
143
|
-
hjxdl-0.2.
|
144
|
-
hjxdl-0.2.
|
141
|
+
hjxdl-0.2.15.dist-info/METADATA,sha256=8TpagjCOPvQJbvgS4FPGB6gqHRyvScegPcxhL7ZIwlM,836
|
142
|
+
hjxdl-0.2.15.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
143
|
+
hjxdl-0.2.15.dist-info/top_level.txt,sha256=-kxwTM5JPhylp06z3zAVO3w6_h7wtBfBo2zgM6YZoTk,4
|
144
|
+
hjxdl-0.2.15.dist-info/RECORD,,
|
File without changes
|
File without changes
|