|
1 | 1 | # Copyright (C) 2024 Intel Corporation
|
2 | 2 | # SPDX-License-Identifier: Apache-2.0
|
3 | 3 |
|
| 4 | +import base64 |
4 | 5 | import errno
|
5 | 6 | import functools
|
6 | 7 | import io
|
@@ -198,6 +199,16 @@ def load_csv(input_path):
|
198 | 199 |
|
199 | 200 | def load_image(image_path):
|
200 | 201 | """Load the image file."""
|
| 202 | + if os.getenv("SUMMARIZE_IMAGE_VIA_LVM", None) == "1": |
| 203 | + query = "Please summarize this image." |
| 204 | + image_b64_str = base64.b64encode(open(image_path, "rb").read()).decode() |
| 205 | + response = requests.post( |
| 206 | + "http://localhost:9399/v1/lvm", |
| 207 | + data=json.dumps({"image": image_b64_str, "prompt": query}), |
| 208 | + headers={"Content-Type": "application/json"}, |
| 209 | + proxies={"http": None}, |
| 210 | + ) |
| 211 | + return response.json()["text"].strip() |
201 | 212 | loader = UnstructuredImageLoader(image_path)
|
202 | 213 | text = loader.load()[0].page_content
|
203 | 214 | return text
|
@@ -239,7 +250,12 @@ def document_loader(doc_path):
|
239 | 250 | return load_xlsx(doc_path)
|
240 | 251 | elif doc_path.endswith(".csv"):
|
241 | 252 | return load_csv(doc_path)
|
242 |
| - elif doc_path.endswith(".tiff"): |
| 253 | + elif ( |
| 254 | + doc_path.endswith(".tiff") |
| 255 | + or doc_path.endswith(".jpg") |
| 256 | + or doc_path.endswith(".jpeg") |
| 257 | + or doc_path.endswith(".png") |
| 258 | + ): |
243 | 259 | return load_image(doc_path)
|
244 | 260 | elif doc_path.endswith(".svg"):
|
245 | 261 | return load_image(doc_path)
|
|
0 commit comments