AI-ANK commited on
Commit
3711571
1 Parent(s): 81ae3d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
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 BytesIO object
24
- buffered = BytesIO()
25
- image.save(buffered, format="JPEG")
26
- img_base64 = base64.b64encode(buffered.getvalue()).decode()
27
 
28
  # Prepare the input data for the model
29
  input_data = {
30
- "image": img_base64,
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