shivanis14 commited on
Commit
b386189
·
verified ·
1 Parent(s): 375b323

Update api/data_extractor.py

Browse files
Files changed (1) hide show
  1. api/data_extractor.py +7 -2
api/data_extractor.py CHANGED
@@ -21,6 +21,9 @@ collection = db.products
21
  print(f"collection is {collection}")
22
 
23
 
 
 
 
24
  def extract_information(images_list: List[Any]) -> Dict[str, Any]:
25
  global openai_client
26
  print(f"DEBUG - openai_client : {openai_client}")
@@ -59,8 +62,10 @@ Your goal will be to extract information from these images to populate the schem
59
  # Convert valid images to byte streams for API processing
60
  image_message = [
61
  {
62
- "type": "image",
63
- "image": {"bytes": base64.b64encode(uploaded_file.read()).decode('utf-8')}
 
 
64
  }
65
  for uploaded_file in valid_image_files
66
  ]
 
21
  print(f"collection is {collection}")
22
 
23
 
24
+ def encode_image(uploaded_file):
25
+ return base64.b64encode(uploaded_file.read()).decode('utf-8')
26
+
27
  def extract_information(images_list: List[Any]) -> Dict[str, Any]:
28
  global openai_client
29
  print(f"DEBUG - openai_client : {openai_client}")
 
62
  # Convert valid images to byte streams for API processing
63
  image_message = [
64
  {
65
+ "type": "image_url",
66
+ "image_url": {
67
+ "url": f"data:image/jpeg;base64,{encode_image(uploaded_file)}"
68
+ }
69
  }
70
  for uploaded_file in valid_image_files
71
  ]