Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ from llama_index import ServiceContext, VectorStoreIndex, Document
|
|
9 |
from llama_index.memory import ChatMemoryBuffer
|
10 |
import os
|
11 |
import base64
|
|
|
12 |
|
13 |
|
14 |
# Function to get image caption via Kosmos2 (as in your original code)
|
@@ -20,14 +21,14 @@ def get_image_caption(image_array):
|
|
20 |
# Convert the numpy array to a PIL Image
|
21 |
image = Image.fromarray(image_array.astype('uint8'), 'RGB')
|
22 |
|
23 |
-
# Save the PIL Image to a
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
|
28 |
# Prepare the input data for the model
|
29 |
input_data = {
|
30 |
-
"image":
|
31 |
"description_type": "Brief"
|
32 |
}
|
33 |
|
|
|
9 |
from llama_index.memory import ChatMemoryBuffer
|
10 |
import os
|
11 |
import base64
|
12 |
+
import tempfile
|
13 |
|
14 |
|
15 |
# Function to get image caption via Kosmos2 (as in your original code)
|
|
|
21 |
# Convert the numpy array to a PIL Image
|
22 |
image = Image.fromarray(image_array.astype('uint8'), 'RGB')
|
23 |
|
24 |
+
# Save the PIL Image to a temporary file
|
25 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpeg") as tmp_file:
|
26 |
+
image.save(tmp_file, format="JPEG")
|
27 |
+
tmp_file_path = tmp_file.name
|
28 |
|
29 |
# Prepare the input data for the model
|
30 |
input_data = {
|
31 |
+
"image": open(tmp_file_path, "rb"),
|
32 |
"description_type": "Brief"
|
33 |
}
|
34 |
|